[Zodb-checkins] CVS: Zope3/src/zope/interface - adapter.py:1.15

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Apr 15 09:26:56 EDT 2004


Update of /cvs-repository/Zope3/src/zope/interface
In directory cvs.zope.org:/tmp/cvs-serv10370/src/zope/interface

Modified Files:
	adapter.py 
Log Message:


Removed 'getRegisteredMatching()'.


=== Zope3/src/zope/interface/adapter.py 1.14 => 1.15 ===
--- Zope3/src/zope/interface/adapter.py:1.14	Mon Apr 12 13:58:34 2004
+++ Zope3/src/zope/interface/adapter.py	Thu Apr 15 09:26:25 2004
@@ -508,191 +508,6 @@
 
         return result
 
-    def getRegisteredMatching(self,
-                              required=None,
-                              provided=None,
-                              name=None,
-                              with=None,
-                              ):
-        """Search for registered adapters
-
-           Return a 5-tuple with:
-
-           - (first) required interface
-
-           - provided interface
-
-           - a tuple of additional required interfaces (for multi-adapters)
-
-           - name, and
-
-           - a sequence of factories. (Note that this could be arbitrary data).
-           
-
-           Note, this is usually slow!
-
-           >>> from zope.interface import Interface
-
-           >>> class R1(Interface):
-           ...     pass
-           >>> class R12(Interface):
-           ...     pass
-           >>> class R2(R1):
-           ...     pass
-           >>> class R3(R2):
-           ...     pass
-           >>> class R4(R3):
-           ...     pass
-
-           >>> class P1(Interface):
-           ...     pass
-           >>> class P2(P1):
-           ...     pass
-           >>> class P3(P2):
-           ...     pass
-           >>> class P4(P3):
-           ...     pass
-
-
-           >>> registry = AdapterRegistry()
-           >>> registry.register([None], P3, '', 'default P3')
-           >>> registry.register([Interface], P3, '', 'any P3')
-           >>> registry.register([R2], P3, '', 'R2 P3')
-           >>> registry.register([R2], P3, 'bob', "bobs R2 P3")
-
-           >>> from pprint import PrettyPrinter
-           >>> pprint = PrettyPrinter(width=60).pprint
-           >>> def sorted(x):
-           ...    x = [(getattr(r, '__name__', None), p.__name__, w, n, f)
-           ...         for (r, p, w, n, f) in x]
-           ...    x.sort()
-           ...    pprint(x)
-
-           >>> sorted(registry.getRegisteredMatching())
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3'),
-            ('R2', 'P3', (), u'', 'R2 P3'),
-            ('R2', 'P3', (), u'bob', 'bobs R2 P3')]
-
-           >>> sorted(registry.getRegisteredMatching(name=''))
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3'),
-            ('R2', 'P3', (), u'', 'R2 P3')]
-
-           >>> sorted(registry.getRegisteredMatching(required=[R1]))
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3')]
-
-           >>> sorted(registry.getRegisteredMatching(required=R1))
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3')]
-
-           >>> sorted(registry.getRegisteredMatching(provided=[P1]))
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3'),
-            ('R2', 'P3', (), u'', 'R2 P3'),
-            ('R2', 'P3', (), u'bob', 'bobs R2 P3')]
-
-           >>> sorted(registry.getRegisteredMatching(provided=P1))
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3'),
-            ('R2', 'P3', (), u'', 'R2 P3'),
-            ('R2', 'P3', (), u'bob', 'bobs R2 P3')]
-
-           >>> sorted(registry.getRegisteredMatching(provided=P3))
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3'),
-            ('R2', 'P3', (), u'', 'R2 P3'),
-            ('R2', 'P3', (), u'bob', 'bobs R2 P3')]
-
-           >>> sorted(registry.getRegisteredMatching(
-           ...     required = (R4, R12),
-           ...     provided = (P1, )))
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3'),
-            ('R2', 'P3', (), u'', 'R2 P3'),
-            ('R2', 'P3', (), u'bob', 'bobs R2 P3')]
-
-           >>> sorted(registry.getRegisteredMatching(
-           ...     required = (R4, R12),
-           ...     provided = (P3, )))
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3'),
-            ('R2', 'P3', (), u'', 'R2 P3'),
-            ('R2', 'P3', (), u'bob', 'bobs R2 P3')]
-
-           >>> sorted(registry.getRegisteredMatching(
-           ...     required = (R2, ),
-           ...     provided = (P3, )))
-           [(None, 'P3', (), u'', 'default P3'),
-            ('Interface', 'P3', (), u'', 'any P3'),
-            ('R2', 'P3', (), u'', 'R2 P3'),
-            ('R2', 'P3', (), u'bob', 'bobs R2 P3')]
-
-           >>> sorted(registry.getRegisteredMatching(
-           ...     required = (R2, ),
-           ...     provided = (P3, ),
-           ...     name='bob'))
-           [('R2', 'P3', (), u'bob', 'bobs R2 P3')]
-
-           >>> sorted(registry.getRegisteredMatching(
-           ...     required = (R3, ),
-           ...     provided = (P1, ),
-           ...     name='bob'))
-           [('R2', 'P3', (), u'bob', 'bobs R2 P3')]
-
-           """
-
-        if name is not None:
-            name = unicode(name)
-        
-        if isinstance(required, InterfaceClass):
-            required = (required, )
-        elif required is None:
-            required = [ref() for ref in self._surrogates.keys()
-                                   if ref() is not None]
-
-        required = tuple(required)+(None,)
-
-        if isinstance(provided, InterfaceClass):
-            provided = (provided, )
-
-
-        seen = {}
-
-        for required in required:
-            s = self.get(required)
-            for ancestor in ro(s):
-                if ancestor in seen:
-                    continue
-                seen[ancestor] = 1
-                adapters = ancestor.adapters
-                if adapters:
-                    items = adapters.iteritems()
-                    ancestor = ancestor.spec()
-                    if ancestor is Default:
-                        ancestor = None
-                    for key, factories in items:
-                        subscription, rwith, aname, target = key
-                        if subscription:
-                            continue
-                            # XXX: We have subscriptions now, so not being
-                            # implemented is not an option. (SR) 
-                            #raise NotImplementedError
-                        if with is not None and not mextends(with, rwith):
-                            continue
-                        if name is not None and aname != name:
-                            continue
-
-                        if provided:
-                            for p in provided:
-                                if target.extends(p, False):
-                                    break
-                            else:
-                                # None matching
-                                continue
-
-                        yield (ancestor, target, rwith, aname, factories)
         
 
 def mextends(with, rwith):




More information about the Zodb-checkins mailing list