[Zope-CVS] CVS: Packages/pypes/pypes - event.py:1.2 identity.py:1.2
interfaces.py:1.4
Casey Duncan
casey at zope.com
Mon Aug 11 23:35:41 EDT 2003
Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv18466
Modified Files:
event.py identity.py interfaces.py
Log Message:
Fire events when objects are registered or removed from the identity service
=== Packages/pypes/pypes/event.py 1.1.1.1 => 1.2 ===
--- Packages/pypes/pypes/event.py:1.1.1.1 Mon Aug 4 00:46:03 2003
+++ Packages/pypes/pypes/event.py Mon Aug 11 22:35:05 2003
@@ -21,8 +21,30 @@
from BTrees.OOBTree import OOBTree, OOTreeSet
from Persistence import Persistent
from zope.interface import implements
-from pypes.interfaces import IEventService
+from pypes.interfaces import IEventService, IIdentityMessage
from pypes.exceptions import EventRegistrationError
+
+class PypesMessage(object):
+ """Abstract base class for all messages originating from pypes itself"""
+
+class IdRegisteredMessage(PypesMessage):
+ """object was registered with the identity service"""
+
+ implements(IIdentityMessage)
+
+ def __init__(self, object, id):
+ self.object = object
+ self.id = id
+
+class IdUnregisteredMessage(PypesMessage):
+ """object was removed from the identity service"""
+
+ implements(IIdentityMessage)
+
+ def __init__(self, object, id):
+ self.object = object
+ self.id = id
+
class EventService(Persistent):
"""Persistent event service
=== Packages/pypes/pypes/identity.py 1.1.1.1 => 1.2 ===
--- Packages/pypes/pypes/identity.py:1.1.1.1 Mon Aug 4 00:46:02 2003
+++ Packages/pypes/pypes/identity.py Mon Aug 11 22:35:05 2003
@@ -27,9 +27,10 @@
from BTrees.IOBTree import IOBTree
from BTrees.Length import Length
from pypes import services
+from pypes.event import IdRegisteredMessage, IdUnregisteredMessage
from pypes.interfaces import IIdentityService, IIdentitySet
-from pypes.exceptions \
- import PypesError, IdentityError, IdentityKeyError, SetLookupError
+from pypes.exceptions import PypesError, PypesLookupError
+from pypes.exceptions import IdentityError, IdentityKeyError, SetLookupError
class IdentityService(Persistent):
"""Identity service providing integer identifiers. Before this service
@@ -67,6 +68,13 @@
self._objs[identifier] = obj
self._length.change(1)
self._v_nextid += 1
+ if self._p_jar is not None:
+ try:
+ event_svc = services.event(self)
+ except PypesLookupError:
+ pass # No event service
+ else:
+ event_svc.send(IdRegisteredMessage(obj, identifier))
return identifier
def hasId(self, identifier):
@@ -99,6 +107,13 @@
del self._objs[identifier]
self._length.change(-1)
obj._pypes_id_ = None
+ if self._p_jar is not None:
+ try:
+ event_svc = services.event(self)
+ except PypesLookupError:
+ pass # No event service
+ else:
+ event_svc.send(IdUnregisteredMessage(obj, identifier))
def getObject(self, identifier):
try:
=== Packages/pypes/pypes/interfaces.py 1.3 => 1.4 ===
--- Packages/pypes/pypes/interfaces.py:1.3 Sun Aug 10 22:32:15 2003
+++ Packages/pypes/pypes/interfaces.py Mon Aug 11 22:35:05 2003
@@ -241,6 +241,18 @@
registered
"""
+class IObjectMessage(Interface):
+ """A message concerning a single object"""
+
+ object = Attribute('object', 'Object that is the subject of the message')
+
+
+class IIdentityMessage(IObjectMessage):
+ """A message concerning the identity of an object"""
+
+ id = Attribute('id', 'The identity of the object in question')
+
+
class IGraphNodes(Interface):
"""Collection of nodes in a graph"""
More information about the Zope-CVS
mailing list