[Checkins] SVN: z3c.componentdebug/trunk/src/z3c/componentdebug/ Add byRegistration

Ross Patterson me at rpatterson.net
Thu May 31 00:18:27 EDT 2007


Log message for revision 76036:
  Add byRegistration
  

Changed:
  U   z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt
  U   z3c.componentdebug/trunk/src/z3c/componentdebug/component.py
  U   z3c.componentdebug/trunk/src/z3c/componentdebug/interfaces.py
  U   z3c.componentdebug/trunk/src/z3c/componentdebug/tests/component.txt

-=-
Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt	2007-05-31 04:00:37 UTC (rev 76035)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/README.txt	2007-05-31 04:18:27 UTC (rev 76036)
@@ -58,6 +58,8 @@
     >>> registrations = inspect((foo, bar), IBaz)
     >>> pprint([i for i in registrations.byObject()])
     [(<Foo object at ...>, []), (<Bar object at ...>, [])]
+    >>> pprint([i for i in registrations.byRegistration()])
+    []
 
 Register a factory for this lookup::
 
@@ -83,6 +85,10 @@
       [(<InterfaceClass __builtin__.IBar>,
         [AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
         IBar], IBaz, '', getBaz, u'')])])]
+    >>> pprint([i for i in registrations.byRegistration()])
+    [(AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
+    IBaz, '', getBaz, u''),
+      [<Foo object at ...>, <Bar object at ...>])]
 
 When we remove one of the required interfaces, we can see what
 regisration might have otherwise fulfilled the lookup and which object
@@ -103,6 +109,10 @@
         [AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
         IBar], IBaz, '', getBaz, u'')])]),
      (<Bar object at ...>, [])]
+    >>> pprint([i for i in registrations.byRegistration()])
+    [(AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
+    IBaz, '', getBaz, u''),
+      [<Foo object at ...>, False])]
 
 --------------------
 ComponentLookupError

Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/component.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/component.py	2007-05-31 04:00:37 UTC (rev 76035)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/component.py	2007-05-31 04:18:27 UTC (rev 76036)
@@ -90,3 +90,9 @@
             yield object, [(req, by_required[req]) for req in ordered]
 
     def byRegistration(self):
+        assert hasattr(self, 'objects')
+        for reg in self:
+            yield (
+                reg,
+                [reg.required[idx].providedBy(self.objects[idx])
+                 and self.objects[idx] for idx in xrange(self.order)])

Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/interfaces.py
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/interfaces.py	2007-05-31 04:00:37 UTC (rev 76035)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/interfaces.py	2007-05-31 04:18:27 UTC (rev 76036)
@@ -5,3 +5,6 @@
 
     def byObject():
         """Registrations grouped by the objects."""
+
+    def byRegistration():
+        """Registrations annotated with the objects."""

Modified: z3c.componentdebug/trunk/src/z3c/componentdebug/tests/component.txt
===================================================================
--- z3c.componentdebug/trunk/src/z3c/componentdebug/tests/component.txt	2007-05-31 04:00:37 UTC (rev 76035)
+++ z3c.componentdebug/trunk/src/z3c/componentdebug/tests/component.txt	2007-05-31 04:18:27 UTC (rev 76036)
@@ -40,6 +40,10 @@
       [(<InterfaceClass __builtin__.IBar>,
         [AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
         IBar], IBaz, '', getBaz, u'')])])]
+    >>> pprint([i for i in registrations.byRegistration()])
+    [(AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
+    IBaz, '', getBaz, u''),
+      [<Foo object at ...>, <Bar object at ...>])]
 
 Multiple Registrations
 ----------------------
@@ -73,6 +77,13 @@
         IBar], IBaz, '', getBaz2, u''),
          AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
          IBar], IBaz, '', getBaz, u'')])])]
+    >>> pprint([i for i in registrations.byRegistration()])
+    [(AdapterRegistration(<BaseGlobalComponents base>, [IFoo2, IBar],
+    IBaz, '', getBaz2, u''),
+      [<Foo object at ...>, <Bar object at ...>]),
+     (AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
+     IBaz, '', getBaz, u''),
+      [<Foo object at ...>, <Bar object at ...>])]
 
     >>> def getBaz3(foo, bar): return 'baz3'
     >>> provideAdapter(getBaz3, (IFoo, Interface), IBaz)
@@ -104,6 +115,16 @@
        (<InterfaceClass zope.interface.Interface>,
         [AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
         Interface], IBaz, '', getBaz3, u'')])])]
+    >>> pprint([i for i in registrations.byRegistration()])
+    [(AdapterRegistration(<BaseGlobalComponents base>, [IFoo2, IBar],
+    IBaz, '', getBaz2, u''),
+      [<Foo object at ...>, <Bar object at ...>]),
+     (AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
+     IBaz, '', getBaz, u''),
+      [<Foo object at ...>, <Bar object at ...>]),
+     (AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
+     Interface], IBaz, '', getBaz3, u''),
+      [<Foo object at ...>, <Bar object at ...>])]
 
 If there are registrations that don't match, the sort later::
 
@@ -133,6 +154,16 @@
        (<InterfaceClass zope.interface.Interface>,
         [AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
         Interface], IBaz, '', getBaz3, u'')])])]
+    >>> pprint([i for i in registrations.byRegistration()])
+    [(AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
+    IBaz, '', getBaz, u''),
+      [<Foo object at ...>, <Bar object at ...>]),
+     (AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
+     Interface], IBaz, '', getBaz3, u''),
+      [<Foo object at ...>, <Bar object at ...>]),
+     (AdapterRegistration(<BaseGlobalComponents base>, [IFoo2, IBar],
+     IBaz, '', getBaz2, u''),
+      [False, <Bar object at ...>])]
 
     >>> noLongerProvides(bar, IBar)
     >>> registrations = inspect((foo, bar), IBaz)
@@ -154,3 +185,13 @@
       [(<InterfaceClass zope.interface.Interface>,
         [AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
         Interface], IBaz, '', getBaz3, u'')])])]
+    >>> pprint([i for i in registrations.byRegistration()])
+    [(AdapterRegistration(<BaseGlobalComponents base>, [IFoo,
+    Interface], IBaz, '', getBaz3, u''),
+      [<Foo object at ...>, <Bar object at ...>]),
+     (AdapterRegistration(<BaseGlobalComponents base>, [IFoo, IBar],
+     IBaz, '', getBaz, u''),
+      [<Foo object at ...>, False]),
+     (AdapterRegistration(<BaseGlobalComponents base>, [IFoo2, IBar],
+     IBaz, '', getBaz2, u''),
+      [False, False])]



More information about the Checkins mailing list