[Zope3-checkins] CVS: Zope3/src/zope/app/pluggableauth - __init__.py:1.4 configure.zcml:1.3

Maru Newby maru at thesprawl.net
Mon Mar 22 19:23:09 EST 2004


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

Modified Files:
	__init__.py configure.zcml 
Log Message:


Replaced implementation of IRemoveNotifiable with an object subscriber for
object remove events on PluggableAuthenticationService objects.




=== Zope3/src/zope/app/pluggableauth/__init__.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/pluggableauth/__init__.py:1.3	Sat Mar 13 18:55:11 2004
+++ Zope3/src/zope/app/pluggableauth/__init__.py	Mon Mar 22 19:23:08 2004
@@ -34,7 +34,7 @@
 from zope.app.location import locate
 from zope.app.traversing import getPath
 
-from zope.app.container.interfaces import IOrderedContainer, IAddNotifiable
+from zope.app.container.interfaces import IOrderedContainer
 from zope.app.container.interfaces import IContainerNamesContainer, INameChooser
 from zope.app.container.interfaces import IContained
 from zope.app.container.constraints import ItemTypePrecondition
@@ -59,7 +59,7 @@
 class PluggableAuthenticationService(OrderedContainer):
 
     implements(IPluggableAuthenticationService, ISimpleService,
-               IOrderedContainer, IAddNotifiable)
+               IOrderedContainer)
 
     def __init__(self, earmark=None):
         self.earmark = earmark
@@ -74,16 +74,6 @@
         # references which embed the old earmark.
         OrderedContainer.__init__(self)
 
-    def addNotify(self, event):
-        """ See IAddNotifiable. """
-        if self.earmark is None:
-            # we manufacture what is intended to be a globally unique
-            # earmark if one is not provided in __init__
-            myname = zapi.name(self)
-            rand_id = gen_key()
-            t = int(time.time())
-            self.earmark = '%s-%s-%s' % (myname, rand_id, t)
-
     def authenticate(self, request):
         """ See IAuthenticationService. """
         for ps_key, ps in self.items():
@@ -194,6 +184,63 @@
         """
 
         del self[id]
+
+
+class PluggableAuthenticationServiceAddSubscriber:
+
+    zope.interface.implements(zope.app.event.interfaces.ISubscriber)
+
+    def __init__(self, pluggable_auth_service, event):
+        self.pluggable_auth_service = pluggable_auth_service
+        self.event = event
+
+    def notify(self, event):
+        r"""Generates an earmark if one is not provided.
+
+        Define a stub for PluggableAuthenticationService
+
+        >>> from zope.app.traversing.interfaces \
+        ...     import IPhysicallyLocatable
+        >>> class PluggableAuthStub:
+        ...     implements(IPhysicallyLocatable)
+        ...     def __init__(self, earmark=None):
+        ...         self.earmark = earmark
+        ...     def getName(self):
+        ...         return 'PluggableAuthName'
+
+        The subscriber generates an earmark for the auth service if one is not
+        set in the init.
+
+        >>> stub = PluggableAuthStub()
+        >>> event = ''
+        >>> subscriber = \
+        ...     PluggableAuthenticationServiceAddSubscriber(stub,
+        ...                                                 event)
+        >>> subscriber.notify(event)
+        >>> stub.earmark is not None
+        True
+        
+        The subscriber does not modify an earmark for the auth service if one
+        exists already.
+
+        >>> earmark = 'my sample earmark'
+        >>> stub = PluggableAuthStub(earmark=earmark)
+        >>> event = ''
+        >>> subscriber = \
+        ...     PluggableAuthenticationServiceAddSubscriber(stub, event)
+        >>> subscriber.notify(event)
+        >>> stub.earmark == earmark
+        True
+        """
+        self = self.pluggable_auth_service
+        if self.earmark is None:
+            # we manufacture what is intended to be a globally unique
+            # earmark if one is not provided in __init__
+            myname = zapi.name(self)
+            rand_id = gen_key()
+            t = int(time.time())
+            self.earmark = '%s-%s-%s' % (myname, rand_id, t)
+                
 
 class IBTreePrincipalSource(
     ILoginPasswordPrincipalSource,


=== Zope3/src/zope/app/pluggableauth/configure.zcml 1.2 => 1.3 ===
--- Zope3/src/zope/app/pluggableauth/configure.zcml:1.2	Sat Mar 13 10:21:25 2004
+++ Zope3/src/zope/app/pluggableauth/configure.zcml	Mon Mar 22 19:23:08 2004
@@ -36,13 +36,16 @@
 -->
     <require
         permission="zope.ManageServices"
-        interface="zope.app.container.interfaces.IAddNotifiable"
-        />
-    <require
-        permission="zope.ManageServices"
         interface="zope.app.site.interfaces.ISimpleService"
         />
   </content>
+
+  <subscriber
+        factory=".PluggableAuthenticationServiceAddSubscriber"
+        for=".interfaces.IPluggableAuthenticationService
+             zope.app.container.interfaces.IObjectAddedEvent"
+        provides="zope.app.event.interfaces.ISubscriber"
+        />
 
   <content class=".BTreePrincipalSource">
     <factory




More information about the Zope3-Checkins mailing list