[Zope3-checkins] CVS: Zope3/src/zope/app/adapter - adapter.py:1.6 tests.py:1.7

Jim Fulton jim at zope.com
Thu Apr 8 17:31:40 EDT 2004


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

Modified Files:
	adapter.py tests.py 
Log Message:
Moved some of the responsibilities for registration() from local
adapter registries to local adapter services. Now, registries only
return their registrations. It's up to the services to delegate to
higher services.  This will make implementing registrations() a little
simpler for the presentation service.


=== Zope3/src/zope/app/adapter/adapter.py 1.5 => 1.6 ===
--- Zope3/src/zope/app/adapter/adapter.py:1.5	Wed Apr  7 15:18:57 2004
+++ Zope3/src/zope/app/adapter/adapter.py	Thu Apr  8 17:31:39 2004
@@ -181,13 +181,6 @@
                 for info in stack.info():
                     yield info['registration']
 
-        next = self.next
-        if next is None:
-            next = self.base
-
-        for registration in next.registrations():
-            yield registration
-
 class LocalAdapterBasedService(
     zope.app.container.contained.Contained,
     Persistent,
@@ -244,12 +237,24 @@
     zope.interface.implements(
         zope.component.interfaces.IAdapterService,
         zope.app.site.interfaces.ISimpleService,
+        zope.component.interfaces.IComponentRegistry,
         )
 
-    def __init__(self):
-        LocalAdapterRegistry.__init__(
-            self, zapi.getService(None, zapi.servicenames.Adapters)
-            )
+    def __init__(self, base=None):
+        if base is None:
+            base = zapi.getService(None, zapi.servicenames.Adapters)
+        LocalAdapterRegistry.__init__(self, base)
+
+    def registrations(self):
+        for registration in LocalAdapterRegistry.registrations(self):
+            yield registration
+
+        next = self.next
+        if next is None:
+            next = self.base
+
+        for registration in next.registrations():
+            yield registration
 
 class IAdapterRegistration(
     zope.app.registration.interfaces.IRegistration):


=== Zope3/src/zope/app/adapter/tests.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/adapter/tests.py:1.6	Thu Apr  8 10:41:17 2004
+++ Zope3/src/zope/app/adapter/tests.py	Thu Apr  8 17:31:39 2004
@@ -16,13 +16,9 @@
    Local surrogates and adapter registries share declarations with
    those "above" them.
 
-   Local adapter registries have "base" registries that mist be
-   IComponentRegistry objects.
+   Suppose we have a global AdapterRegistry:
 
-   Suppose we have a global adapter service, which is a type of
-   adapter registry that is an IComponentRegistry:
-
-   >>> G = GlobalAdapterService()
+   >>> G = AdapterRegistry()
 
    we also have a local adapter registry, with G as it's base:
 
@@ -128,36 +124,22 @@
    >>> L2.lookup([IF2], IB0)
    'A10G'
 
-   We can ask for all of the registrations locally:
-
-   >>> registrations = map(repr, L1.registrations())
-   >>> registrations.sort()
-   >>> for registration in registrations:
-   ...     print registration
-   AdapterRegistration(('IF1',), 'IB1', '', 'A10G', '')
-   Registration('IF0', (), 'IB1', u'', 'A011')
+   We can ask for all of the registrations :
 
-   This shows the local registrations in L1 and the global registrations.
+   >>> registrations = list(L1.registrations())
+   >>> registrations
+   [Registration('IF0', (), 'IB1', u'', 'A011')]
 
-   If we ask L2, we'll see the registrations from G, L1, and L2:
-   
-   >>> registrations = map(repr, L2.registrations())
-   >>> registrations.sort()
-   >>> for registration in registrations:
-   ...     print registration
-   AdapterRegistration(('IF1',), 'IB1', '', 'A10G', '')
-   Registration('IF0', (), 'IB1', u'', 'A011')
-   Registration('IF1', (), 'IB0', u'', 'A102')
-   Registration('IF1', (), 'IB1', u'', 'A112')
+   This shows only the local registrations in L1.
 
    $Id$
    """
 
 def test_named_adapters():
     """
-    Suppose we have a GlobalAdapterService:
+    Suppose we have a global AdapterRegistry:
 
-    >>> G = GlobalAdapterService()
+    >>> G = AdapterRegistry()
 
     we also have a local adapter registry, with G as it's base:
 
@@ -284,9 +266,9 @@
 
 def test_multi_adapters():
     """
-    Suppose we have a globalGlobalAdapterService:
+    Suppose we have a global AdapterRegistry:
 
-    >>> G = GlobalAdapterService()
+    >>> G = AdapterRegistry()
 
     we also have a local adapter registry, with G as it's base:
 
@@ -570,7 +552,7 @@
 
 def test_local_default():
     """
-    >>> G = GlobalAdapterService()
+    >>> G = AdapterRegistry()
     >>> L1 = LocalAdapterRegistry(G)
     >>> r = Registration(required = None, provided=IB1, factory='Adapter')
     >>> L1.createRegistrationsFor(r).activate(r)
@@ -581,7 +563,7 @@
 
 def test_changing_next():
     """
-    >>> G = GlobalAdapterService()
+    >>> G = AdapterRegistry()
     >>> L1 = LocalAdapterRegistry(G)
     >>> L2 = LocalAdapterRegistry(G, L1)
     >>> f2 = F2()
@@ -659,6 +641,7 @@
     Create a local service class, which must define setNext:
 
     >>> import zope.app.site.interfaces
+    >>> from zope.app.adapter.adapter import LocalAdapterBasedService
     >>> class LocalF(LocalAdapterBasedService):
     ...     zope.interface.implements(
     ...         IF2,
@@ -717,9 +700,9 @@
 
 import unittest
 from zope.testing.doctestunit import DocTestSuite
+from zope.interface.adapter import AdapterRegistry
 from zope.component.adapter import GlobalAdapterService
-from zope.app.adapter.adapter import LocalAdapterRegistry
-from zope.app.adapter.adapter import LocalAdapterBasedService
+from zope.app.adapter.adapter import LocalAdapterRegistry, LocalAdapterService
 import zope.interface
 from ZODB.tests.util import DB
 from transaction import get_transaction
@@ -779,7 +762,7 @@
 
 # Create a picklable global registry. The pickleability of other
 # global adapter registries is beyond the scope of these tests:
-class GlobalAdapterRegistry(GlobalAdapterService):
+class GlobalAdapterRegistry(AdapterRegistry):
     def __reduce__(self):
         return 'globalAdapterRegistry'
 
@@ -813,6 +796,67 @@
     """For testing, use custom stack type
     """
     _stackType = TestStack
+
+
+def test_service_registrations():
+    """Local Adapter Service Registration Tests
+
+
+       Local adapter services share declarations and registrations with
+       those "above" them.
+
+       Suppose we have a global adapter service, which is a type of
+       adapter registry that is an IComponentRegistry:
+
+       >>> G = GlobalAdapterService()
+
+       we also have a local adapter registry, with G as it's base:
+
+       >>> L1 = LocalAdapterService(G)
+
+       and another local, with G as it's base:
+
+       >>> L2 = LocalAdapterService(G)
+
+       and L1 as it's next service:
+       
+       >>> L2.setNext(L1)
+
+       Now will register some adapters:
+
+       >>> G.register([IF1], IB1, '', 'A11G')
+       >>> ra011 = Registration(required = IF0, provided=IB1, factory='A011')
+       >>> L1.createRegistrationsFor(ra011).register(ra011)
+       >>> ra112 = Registration(required = IF1, provided=IB1, factory='A112')
+       >>> L2.createRegistrationsFor(ra112).register(ra112)
+       >>> ra102 = Registration(required = IF1, provided=IB0, factory='A102')
+       >>> L2.createRegistrationsFor(ra102).register(ra102)
+
+       We can ask for all of the registrations locally:
+
+       >>> registrations = map(repr, L1.registrations())
+       >>> registrations.sort()
+       >>> for registration in registrations:
+       ...     print registration
+       AdapterRegistration(('IF1',), 'IB1', '', 'A11G', '')
+       Registration('IF0', (), 'IB1', u'', 'A011')
+
+       This shows the local registrations in L1 and the global registrations.
+
+       If we ask L2, we'll see the registrations from G, L1, and L2:
+
+       >>> registrations = map(repr, L2.registrations())
+       >>> registrations.sort()
+       >>> for registration in registrations:
+       ...     print registration
+       AdapterRegistration(('IF1',), 'IB1', '', 'A11G', '')
+       Registration('IF0', (), 'IB1', u'', 'A011')
+       Registration('IF1', (), 'IB0', u'', 'A102')
+       Registration('IF1', (), 'IB1', u'', 'A112')
+
+       $Id$
+       """
+    
     
 
 def test_suite():




More information about the Zope3-Checkins mailing list