src/pyams_utils/intids.py
changeset 72 9049384a2bd4
parent 49 01eaa997a5f4
child 292 b338586588ad
--- a/src/pyams_utils/intids.py	Tue Nov 15 10:43:55 2016 +0100
+++ b/src/pyams_utils/intids.py	Fri Nov 18 15:28:54 2016 +0100
@@ -24,7 +24,7 @@
 from zope.keyreference.interfaces import IKeyReference, NotYet
 
 # import packages
-from pyams_utils.adapter import adapter_config
+from pyams_utils.adapter import adapter_config, ContextAdapter
 from pyams_utils.registry import get_all_utilities_registered_for, query_utility
 from pyramid.events import subscriber
 from pyramid.threadlocal import get_current_registry
@@ -33,17 +33,16 @@
 
 
 @adapter_config(context=IPersistent, provides=IUniqueID)
-class UniqueIdAdapter(object):
+class UniqueIdAdapter(ContextAdapter):
     """Object unique ID adapter
 
-    This adapter is based on a registered IIntIds utility
+    This adapter is based on a registered IIntIds utility to get a unique ID
+    for any persistent object.
     """
 
-    def __init__(self, context):
-        self.context = context
-
     @property
     def oid(self):
+        """Get context ID in hexadecimal form"""
         intids = query_utility(IIntIds)
         if intids is not None:
             return hex(intids.queryId(self.context))[2:]
@@ -51,7 +50,11 @@
 
 @subscriber(IObjectAddedEvent, context_selector=IPersistent)
 def handle_added_object(event):
-    """Notify IntId utility for added objects"""
+    """Notify IntId utility for added objects
+
+    This subscriber is used for all persistent objects to be registered
+    in all locally registered IIntIds utilities.
+    """
     utilities = tuple(get_all_utilities_registered_for(IIntIds))
     if utilities:
         # assert that there are any utilities
@@ -71,7 +74,11 @@
 
 @subscriber(IObjectRemovedEvent, context_selector=IPersistent)
 def handle_removed_object(event):
-    """Notify IntId utility for removed objects"""
+    """Notify IntId utility for removed objects
+
+    This subscriber is used for all persistent objects to be unregistered
+    from all locally registered IIntIds utilities.
+    """
     registry = get_current_registry()
     locations = ISublocations(event.object, None)
     if locations is not None:
@@ -93,4 +100,7 @@
 
 @subscriber(IIntIdEvent)
 def handle_intid_event(event):
+    """Event subscriber used to dispatch all IIntIdEvent events using Pyramid events subscribers to matching
+    subscribers using Zope events
+    """
     intIdEventNotify(event)