[Zope3-checkins] CVS: Zope3/src/zope/app/event - interfaces.py:1.1 __init__.py:1.11 configure.zcml:1.7 function.py:1.3 globalservice.py:1.13 metaconfigure.py:1.5 objectevent.py:1.10 subs.py:1.24

Philipp von Weitershausen philikon at philikon.de
Tue Mar 2 13:51:35 EST 2004


Update of /cvs-repository/Zope3/src/zope/app/event
In directory cvs.zope.org:/tmp/cvs-serv7455/event

Modified Files:
	__init__.py configure.zcml function.py globalservice.py 
	metaconfigure.py objectevent.py subs.py 
Added Files:
	interfaces.py 
Log Message:
Moved event interfaces from zope.app.interfaces.event to
zope.app.event.interfaces.


=== Added File Zope3/src/zope/app/event/interfaces.py ===
##############################################################################
#
# Copyright (c) 2002, 2003 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""

Revision information:
$Id: interfaces.py,v 1.1 2004/03/02 18:50:59 philikon Exp $
"""

from zope.interface import Interface, Attribute

class IEvent(Interface):
    """The base interface for Events."""


class IFilter(Interface):
    """Interface for predicates used to filter events."""

    def __call__(event):
        """Return True if event passes, otherwise False."""


class IPublisher(Interface):

    def publish(event):
        """Publish this event to subscribers.

        Events will often be propagated to higher level IPublishers.
        This is a policy decision for the IPublisher.
        """


# these are method calls and not events because they are traditional messages
# between two objects, not events of general interest.
class ISubscribingAware(Interface):

    def subscribedTo(subscribable, event_type, filter):
        """Alerts the object that it has subscribed, via a call from
        itself or from another object, to the subscribable.  The
        event_type and filter match the arguments provided to the
        ISubscribable.subscribe.

        The subscribable must be appropriately placefully wrapped (note
        that the global event service will have no wrapping)."""

    def unsubscribedFrom(subscribable, event_type, filter):
        """Alerts the object that it has unsubscribed, via a call from
        itself or from another object, to the subscribable.  The
        event_type and filter match the exact event_type and filter of
        the deleted subscription, rather than, necessarily, the
        arguments provided to the ISubscribable.unsubscribe.

        The subscribable must be appropriately placefully wrapped (note
        that the global event service will have no wrapping)."""


class ISubscriber(Interface):
    """Interface for objects which receiving event notifications."""

    def notify(event):
        """ISubscribables call this method to indicate an event.

        This method must not block.

        This method may raise an exception to veto the event.
        """


class IGlobalSubscribable(Interface):
    """Objects that broadcast events to subscribers.

    Subscriptions to a global subscribable are not persistent."""

    def globalSubscribe(subscriber, event_type=IEvent, filter=None):
        """Add subscriber to the list of subscribers for the channel.

        subscriber must be adaptable to ISubscriber.

        event_type, if supplied, is the event interface
        about which subscriber should be notified, and must implement
        IEvent.  The subscriber will be notified of all events of this
        event_type and of subclasses of this event_type.
        The default value, IEvent, as the parent type, is effectively a single
        catch-all event type that will pass all event types to the subscriber.

        filter, if supplied, must implement IFilter; subscriber
        will be notified of events only if they pass.

        A subscriber may subscribe more than once, even if it has
        already been subscribed with the same event type and
        filter.  In this case the subscriber will receive multiple
        calls to its notify method.

        If the subscriber has an ISubscribingAware adapter, this function
        will call the subscriber's subscribedTo method.
        """

    def unsubscribe(subscriber, event_type=IEvent, filter=None):
        """Unsubscribe subscriber from receiving event types from this
        subscribable.

        If event_type is IEvent, the default value, the subscriber is
        unsubscribed completely for all event types from this
        subscribable (and its parents, if the subscribable is a placeful
        service).  The filter argument is ignored in this case.  If no
        subscriptions for this subscriber are present, no error is
        raised.

        If event_type is supplied, this method will unsubscribe the
        subscriber from one subscription exactly matching the
        event_type/filter pair given (the default filter being None).
        If other subscriptions are present they will remain.  If the
        subscription cannot be found and the subscribable is a placeful
        service, the unsubscription request is passed to parent
        services.  Raises Zope.Exceptions.NotFound if subscriber wasn't 
        subscribed as expected.

        If the subscriber has an ISubscribingAware adapter, this function
        will call the subscriber's unsubscribedFrom method for each
        individual unsubscribe.
        """

    def listSubscriptions(subscriber, event_type=IEvent):
        """Returns an iterator of the subscriptions to this channel for
        the subscriber. If event_type is supplied, the list is limited
        to that exact event_type.  If the subscribable is a placeful
        service, the list will include subscriptions to parent services.
        No subscriptions returns an empty iterator.  Each subscription is
        represented as a tuple (event_type, filter)."""


class ISubscribable(Interface):
    """A subscribable that only works with physically locatable objects,
    or their paths or hubids."""

    def subscribe(reference, event_type=IEvent, filter=None):
        """Add subscriber to the list of subscribers for the component.

        Subscriber must have an ISubscriber adapter, and must be accessible
        via path.  The reference passed to the method may be a hard 
        reference, contextually wrapped if appropriate; or a path or
        hubid that reference the subscriber.

        If the subscriber is a wrapped object then it will be
        subscribed on the basis of hubid, if available for the object,
        and path otherwise; passing the path or the hubid uses that
        explicitly.  In all cases, the method passes back the hubid or
        path used to subscribe on success.

        event_type, if supplied, is the event interface
        about which subscriber should be notified, and must implement
        IEvent.  The subscriber will be notified of all events of this
        event_type and of subclasses of this event_type.
        The default value, IEvent, as the parent type, is effectively a
        single catch-all event type that will pass all event types to
        the subscriber.

        filter, if supplied, must implement IFilter; subscriber
        will be notified of events only if they pass. filter must be
        picklable.

        A subscriber may subscribe more than once, even if it has
        already been subscribed with the same event type and
        filter.  In this case the subscriber will receive multiple
        calls to its notify method.

        If the subscriber has an ISubscribingAware adapter, this method
        will call the subscriber's subscribedTo method.
        """

    def unsubscribe(reference, event_type, filter=None):
        """Removes just one subscription.

        This is in parity with subscribe providing just one subscription.

        A filter of None means 'the subscription with no filter' rather
        than 'a subscription with any filter'.

        A subscriber is determined based on the reference supplied.

        If 'reference' is an object, it must be physically locatable so
        we can get its path. We try to remove a subscription based on the
        hubId (if available). If there is no hubId or no such subscription,
        we try to remove a subscription based on the path.

        If 'reference' is an int, it is interpreted as a hubId. We try to
        remove a subscription by hubId, and then by path.

        If 'reference' is a string or unicode, it is interpreted as an
        absolute path. We try to remove a subscription by path, and then
        by hubId.

        If a subscription is removed, and the subscriber has an
        ISubscribingAware adapter, the adapter's unsubscribedFrom method
        is called.
        If no subscription can be removed, we raise a NotFoundError.

        If a path or hubId is given that no longer resolves to an object,
        and such a subscription exists, then that subscription will be
        removed and a warning logged.
        """

    def unsubscribeAll(reference, event_type=IEvent):
        """Removes all subscriptions for subscriber that match event_type.

        The subscriber is determined from the reference as described in
        the docstring of the 'unsubscribe' method.

        If a path and hubId can be determined for the subscriber,
        all subscriptions by both path and hubId that match event_type
        are removed.

        Subscriptions are removed only if the event in the subscription
        is event_type, or extends event_type.

        Returns the number of subscriptions removed.
        """

    def resubscribeByHubId(reference):
        """Change all subscriptions for reference by path into subscriptions
        by hubId.

        The reference may be a hubId, a path or a physically locatable object.

        Returns the number of subscriptions converted.
        """

    def resubscribeByPath(reference):
        """Change all subscriptions for reference by hubId into subscriptions
        by path.

        The reference may be a hubId, a path or a physically locatable object.

        Returns the number of subscriptions converted.
        """

    def iterSubscriptions(reference=None, event_type=IEvent):
        """Returns an iterator of the subscriptions to this channel for
        the referenced subscriber.

        The reference may be a hubId, a path or a physically locatable object.
        Subscriptions by hubId and by path are returned.
        The reference may also be None, meaning that subscriptions for all
        subscribers are to be returned.

        If event_type is supplied, only those subscriptions where the
        event_type of the subscription extends or is equal to the given
        event_type will be returned.

        Each element of the iteration is a three-tuple:

          (reference, event_type, filter)

        The first element of the tuple will the int or unicode that is
        subscribed. The second element is the event_type subscribed.
        The third is the filter subscribed.
        """

class IObjectEvent(IEvent):
    """Something has happened to an object.

    The object that generated this event is not necessarily the object
    refered to by location.
    """

    object = Attribute("The subject of the event.")

class IObjectCreatedEvent(IObjectEvent):
    """An object has been created.

    The location will usually be None for this event."""

class IObjectCopiedEvent(IObjectCreatedEvent):
    """An object has been copied"""

class IObjectModifiedEvent(IObjectEvent):
    """An object has been modified"""

class IObjectAnnotationsModifiedEvent(IObjectModifiedEvent):
    """An object's annotations have been modified"""

class IObjectContentModifiedEvent(IObjectModifiedEvent):
    """An object's content has been modified"""

class IDatabaseOpenedEvent(IEvent):
    """The main database has been opened."""

    database = Attribute("The main database.")

class IProcessStartingEvent(IEvent):
    """The application server process is starting."""


=== Zope3/src/zope/app/event/__init__.py 1.10 => 1.11 ===
--- Zope3/src/zope/app/event/__init__.py:1.10	Thu May  1 15:35:15 2003
+++ Zope3/src/zope/app/event/__init__.py	Tue Mar  2 13:50:59 2004
@@ -12,14 +12,12 @@
 # 
 ##############################################################################
 """
-Revision information:
-
 $Id$
 """
 
 from zope.component import getService
 from zope.app.services.servicenames import EventPublication
-from zope.app.interfaces.event import IEvent
+from zope.app.event.interfaces import IEvent
 from zope.app.event.globalservice import eventPublisher
 
 def getEventService(context): # the "publish" service


=== Zope3/src/zope/app/event/configure.zcml 1.6 => 1.7 ===
--- Zope3/src/zope/app/event/configure.zcml:1.6	Mon Feb  9 04:07:43 2004
+++ Zope3/src/zope/app/event/configure.zcml	Tue Mar  2 13:50:59 2004
@@ -5,7 +5,7 @@
 
 <serviceType
     id='EventPublication' 
-    interface='zope.app.interfaces.event.IPublisher' />
+    interface='zope.app.event.interfaces.IPublisher' />
 
 <service
     serviceType='EventPublication'
@@ -13,6 +13,6 @@
 
 <event:subscribe
     subscriber=".objectevent.objectEventNotifierInstance"
-    event_types="zope.app.interfaces.event.IObjectEvent" />
+    event_types="zope.app.event.interfaces.IObjectEvent" />
 
 </configure>


=== Zope3/src/zope/app/event/function.py 1.2 => 1.3 ===
--- Zope3/src/zope/app/event/function.py:1.2	Wed Jun 25 11:19:07 2003
+++ Zope3/src/zope/app/event/function.py	Tue Mar  2 13:50:59 2004
@@ -17,7 +17,7 @@
 """
 
 from zope.interface import implements
-from zope.app.interfaces.event import ISubscriber
+from zope.app.event.interfaces import ISubscriber
 
 
 class Subscriber:
@@ -38,7 +38,7 @@
 
         <event:subscribe
             subscriber='.module.startupEventHandler'
-            event_types='zope.app.interfaces.event.IProcessStartingEvent'
+            event_types='zope.app.event.interfaces.IProcessStartingEvent'
             />
     """
     implements(ISubscriber)


=== Zope3/src/zope/app/event/globalservice.py 1.12 => 1.13 ===
--- Zope3/src/zope/app/event/globalservice.py:1.12	Sun Aug  3 17:56:10 2003
+++ Zope3/src/zope/app/event/globalservice.py	Tue Mar  2 13:50:59 2004
@@ -23,8 +23,8 @@
 from zope.exceptions import NotFoundError
 from zope.proxy import removeAllProxies
 
-from zope.app.interfaces.event import IEvent, ISubscriber, ISubscribingAware
-from zope.app.interfaces.event import IGlobalSubscribable, IPublisher
+from zope.app.event.interfaces import IEvent, ISubscriber, ISubscribingAware
+from zope.app.event.interfaces import IGlobalSubscribable, IPublisher
 
 import logging
 import pprint


=== Zope3/src/zope/app/event/metaconfigure.py 1.4 => 1.5 ===
--- Zope3/src/zope/app/event/metaconfigure.py:1.4	Sun Aug  3 17:56:10 2003
+++ Zope3/src/zope/app/event/metaconfigure.py	Tue Mar  2 13:50:59 2004
@@ -15,7 +15,7 @@
 $Id$
 """
 
-from zope.app.interfaces.event import IEvent
+from zope.app.event.interfaces import IEvent
 from globalservice import globalSubscribeMany
 
 directive_counter = 0


=== Zope3/src/zope/app/event/objectevent.py 1.9 => 1.10 ===
--- Zope3/src/zope/app/event/objectevent.py:1.9	Wed Feb 25 18:02:25 2004
+++ Zope3/src/zope/app/event/objectevent.py	Tue Mar  2 13:50:59 2004
@@ -18,12 +18,12 @@
 
 __metaclass__ = type
 
-from zope.app.interfaces.event import IObjectEvent, IObjectCreatedEvent
-from zope.app.interfaces.event import IObjectModifiedEvent
-from zope.app.interfaces.event import IObjectCopiedEvent
-from zope.app.interfaces.event import IObjectAnnotationsModifiedEvent
-from zope.app.interfaces.event import IObjectContentModifiedEvent
-from zope.app.interfaces.event import ISubscriber
+from zope.app.event.interfaces import IObjectEvent, IObjectCreatedEvent
+from zope.app.event.interfaces import IObjectModifiedEvent
+from zope.app.event.interfaces import IObjectCopiedEvent
+from zope.app.event.interfaces import IObjectAnnotationsModifiedEvent
+from zope.app.event.interfaces import IObjectContentModifiedEvent
+from zope.app.event.interfaces import ISubscriber
 from zope.interface import implements
 from zope.app.event import publish
 from zope.component import querySubscriptionMultiAdapter


=== Zope3/src/zope/app/event/subs.py 1.23 => 1.24 ===
--- Zope3/src/zope/app/event/subs.py:1.23	Fri Feb 20 17:02:29 2004
+++ Zope3/src/zope/app/event/subs.py	Tue Mar  2 13:50:59 2004
@@ -25,8 +25,8 @@
 
 from zope.app.traversing import getPath
 from zope.app.traversing import canonicalPath, traverse
-from zope.app.interfaces.event import IEvent, ISubscriber, ISubscribable
-from zope.app.interfaces.event import ISubscribingAware
+from zope.app.event.interfaces import IEvent, ISubscriber, ISubscribable
+from zope.app.event.interfaces import ISubscribingAware
 
 from zope.component import getService, queryService, getAdapter, queryAdapter
 from zope.app.services.servicenames import HubIds




More information about the Zope3-Checkins mailing list