[Zope-CVS] CVS: Packages/pypes/pypes - event.py:1.4 identity.py:1.4
interfaces.py:1.8
Casey Duncan
casey at zope.com
Sun Feb 8 22:56:52 EST 2004
Update of /cvs-repository/Packages/pypes/pypes
In directory cvs.zope.org:/tmp/cvs-serv4474
Modified Files:
event.py identity.py interfaces.py
Log Message:
Add extent map interface
Move identity message from event module to identity
Add listenForIdEvents helper function and test
=== Packages/pypes/pypes/event.py 1.3 => 1.4 ===
--- Packages/pypes/pypes/event.py:1.3 Fri Jan 30 00:35:38 2004
+++ Packages/pypes/pypes/event.py Sun Feb 8 22:56:21 2004
@@ -21,29 +21,12 @@
from BTrees.OOBTree import OOBTree, OOTreeSet
from persistent import Persistent
from zope.interface import implements
-from pypes.interfaces import IEventService, IIdentityMessage
+from pypes.interfaces import IEventService
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):
=== Packages/pypes/pypes/identity.py 1.3 => 1.4 ===
--- Packages/pypes/pypes/identity.py:1.3 Fri Jan 30 00:35:38 2004
+++ Packages/pypes/pypes/identity.py Sun Feb 8 22:56:21 2004
@@ -27,11 +27,12 @@
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.event import PypesMessage
+from pypes.interfaces import IIdentityService, IIdentitySet, IIdentityMessage
from pypes.exceptions import PypesError, PypesLookupError
from pypes.exceptions import IdentityError, IdentityKeyError, SetLookupError
+
class IdentityService(Persistent):
"""Identity service providing integer identifiers. Before this service
can be used, it must be committed to the database
@@ -130,6 +131,7 @@
def idSet(self):
return IITreeSet(self._objs.keys())
+
class IdentitySet(Persistent):
"""Efficient persistent sets of id-registered objects"""
@@ -260,11 +262,64 @@
def __ne__(self, other):
return not self.issubset(other) or not self.issuperset(other)
-
+
+
+## Id Event Messsage Types ##
+
+
+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
+
+
## Helper Functions ##
+
def pypesid(obj):
"""Return the identifier for obj if registered with an identity service
otherwise return None"""
return getattr(obj, '_pypes_id_', None)
+
+
+def listenForIdEvents(listener, conn=None,
+ id_registered_method='_notifyIdRegistered',
+ id_unregistered_method='_notifyIdUnRegistered'):
+ """Register obj with the event service as a listener for identity
+ service registrations/unregistrations.
+
+ listener -- Object to be registered as a listener
+
+ conn -- Open ZODB connection object. If None it will be derived from
+ listener if possible.
+
+ id_registered_method -- Name of the method of listener which will
+ receive idRegisteredMessages.
+
+ id_registered_method -- Name of the method of listener which will
+ receive idUnRegisteredMessages.
+ """
+ if conn is None:
+ conn = listener
+ event = services.event(conn)
+ if id_registered_method:
+ event.registerListener(
+ listener, id_registered_method, IdRegisteredMessage)
+ if id_unregistered_method:
+ event.registerListener(
+ listener, id_unregistered_method, IdUnregisteredMessage)
=== Packages/pypes/pypes/interfaces.py 1.7 => 1.8 ===
--- Packages/pypes/pypes/interfaces.py:1.7 Thu Feb 5 00:35:51 2004
+++ Packages/pypes/pypes/interfaces.py Sun Feb 8 22:56:21 2004
@@ -276,6 +276,22 @@
"""Return an iterator of all extents in the service"""
+class IExtentMap(Interface):
+ """Simple mapping-like container for canonical extents of a single type"""
+
+ key_type = Attribute('key_type',
+ """Type of key objects used to identify extents in the map""")
+
+ def __getitem__(key):
+ """Return extent for key or raise KeyError"""
+
+ def __iter__():
+ """Return an iterator of all extents in the mapping"""
+
+ def update():
+ """Update the extent map from all identified objects"""
+
+
class IExtent(Interface):
"""Automated set of identified objects.
@@ -345,7 +361,7 @@
"""
class IDerivedExtent(IExtent):
- """An extent derived by combining one or more extents"""
+ """An extent derived by combining extents"""
class IGraphNodes(Interface):
More information about the Zope-CVS
mailing list