[Zope-Checkins] CVS: Zope3/lib/python/Interface/Registry - AdapterRegistry.py:1.2.8.5 IAdapterRegistry.py:1.2.8.4

Jim Fulton jim@zope.com
Wed, 13 Nov 2002 15:23:48 -0500


Update of /cvs-repository/Zope3/lib/python/Interface/Registry
In directory cvs.zope.org:/tmp/cvs-serv568/lib/python/Interface/Registry

Modified Files:
      Tag: Zope3-Bangalore-TTW-Branch
	AdapterRegistry.py IAdapterRegistry.py 
Log Message:
fixed DOS line endings

=== Zope3/lib/python/Interface/Registry/AdapterRegistry.py 1.2.8.4 => 1.2.8.5 ===
--- Zope3/lib/python/Interface/Registry/AdapterRegistry.py:1.2.8.4	Thu Oct 24 07:08:37 2002
+++ Zope3/lib/python/Interface/Registry/AdapterRegistry.py	Wed Nov 13 15:23:17 2002
@@ -1,158 +1,158 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-# 
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-# 
-##############################################################################
-"""Adapter-style interface registry
-
-See Adapter class.
-
-$Id$
-"""
-__metaclass__ = type # All classes are new style when run with Python 2.2+
-
-from Interface import Interface
-from Interface.IInterface import IInterface
-from _flatten import _flatten
-from IAdapterRegistry import IAdapterRegistry
-
-class AdapterRegistry:
-    """Adapter-style interface registry
-    """
-
-    __implements__ = IAdapterRegistry
-
-    # The implementation uses a mapping:
-    #
-    #  { (required_interface, provided_interface) ->
-    #                             (registered_provides, component) }
-    #
-    # Where the registered provides is what was registered and
-    # provided may be some base interface
-    
-    def __init__(self, data=None):
-        if data is None:
-            data = {}
-        self._reg = data
-        
-    def _registerAllProvided(self, require, primary_provide, object, provide):
-        # Registers a component using (require, provide) as a key.
-        # Also registers superinterfaces of the provided interface,
-        # stopping when the registry already has a component
-        # that provides a more general interface or when the Base is Interface.
-        
-        reg = self._reg
-        reg[(require, provide)] = (primary_provide, object)
-        bases = getattr(provide, '__bases__', ())
-        for base in bases:
-            if base is Interface:
-                # Never register the say-nothing Interface.
-                continue
-            existing = reg.get((require, base), None)
-            if existing is not None:
-                existing_provide = existing[0]
-                if existing_provide is not primary_provide:
-                    if not existing_provide.extends(primary_provide):
-                        continue
-                    # else we are registering a general component
-                    # after a more specific component.
-            self._registerAllProvided(require, primary_provide, object, base)
-
-
-    def register(self, require, provide, object):
-        if require is not None and not IInterface.isImplementedBy(require):
-            raise TypeError(
-                "The require argument must be an interface (or None)")
-        if not IInterface.isImplementedBy(provide):
-            raise TypeError(
-                "The provide argument must be an interface (or None)")
-        
-        self._registerAllProvided(require, provide, object, provide)
-
-    def get(self, (ob_interface, provide), default=None, filter=None):
-        """
-        Finds a registered component that provides the given interface.
-        Returns None if not found.
-        """
-        for interface in _flatten(ob_interface, 1):
-            c = self._reg.get((interface, provide))
-            if c:
-                c = c[1]
-                if filter is None:
-                    return c
-                if filter(c):
-                    return c
-
-        return default
-
-    def getForObject(self, object, interface, filter=None):
-        return self.get((getattr(object, '__implements__', None), interface),
-                        filter=filter)
-
-    def getRegistered(self, require, provide):
-        data = self._reg.get((require, provide))
-        if data:
-            registered_provide, object = data
-            if registered_provide == provide:
-                return object
-        return None
-
-    def getRegisteredMatching(self,
-                              required_interfaces=None,
-                              provided_interfaces=None):
-
-
-        if provided_interfaces:
-            r = {}
-
-            if required_interfaces:
-                # Both specified
-                for required in _flatten(required_interfaces, 1):
-                    for provided in provided_interfaces:
-                        v = self._reg.get((required, provided))
-                        if v:
-                            rprovided, o = v                        
-                            r[required, rprovided] = o
-
-
-            else:
-                # Only provided specified
-                for (required, provided), (rprovided, o) in self._reg.items():
-                    for p in provided_interfaces:
-                        if provided.extends(p, 0):
-                            r[required, rprovided] = o
-                            break
-
-            return [(required, provided, o)
-                    for ((required, provided), o) in r.items()]
-
-
-        elif required_interfaces:
-            # Just required specified
-            required_interfaces = _flatten(required_interfaces, 1)
-            return [(required, provided, o)
-                    for (required, provided), (rprovided, o)
-                    in self._reg.items()
-                    if ((required in required_interfaces)
-                        and
-                        provided == rprovided
-                        )
-                   ]
-            
-        else:
-            # Nothing specified
-            return [(required, provided, o)
-                    for (required, provided), (rprovided, o)
-                    in self._reg.items()
-                    if provided == rprovided
-                   ]
-                        
-                        
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+# 
+##############################################################################
+"""Adapter-style interface registry
+
+See Adapter class.
+
+$Id$
+"""
+__metaclass__ = type # All classes are new style when run with Python 2.2+
+
+from Interface import Interface
+from Interface.IInterface import IInterface
+from _flatten import _flatten
+from IAdapterRegistry import IAdapterRegistry
+
+class AdapterRegistry:
+    """Adapter-style interface registry
+    """
+
+    __implements__ = IAdapterRegistry
+
+    # The implementation uses a mapping:
+    #
+    #  { (required_interface, provided_interface) ->
+    #                             (registered_provides, component) }
+    #
+    # Where the registered provides is what was registered and
+    # provided may be some base interface
+    
+    def __init__(self, data=None):
+        if data is None:
+            data = {}
+        self._reg = data
+        
+    def _registerAllProvided(self, require, primary_provide, object, provide):
+        # Registers a component using (require, provide) as a key.
+        # Also registers superinterfaces of the provided interface,
+        # stopping when the registry already has a component
+        # that provides a more general interface or when the Base is Interface.
+        
+        reg = self._reg
+        reg[(require, provide)] = (primary_provide, object)
+        bases = getattr(provide, '__bases__', ())
+        for base in bases:
+            if base is Interface:
+                # Never register the say-nothing Interface.
+                continue
+            existing = reg.get((require, base), None)
+            if existing is not None:
+                existing_provide = existing[0]
+                if existing_provide is not primary_provide:
+                    if not existing_provide.extends(primary_provide):
+                        continue
+                    # else we are registering a general component
+                    # after a more specific component.
+            self._registerAllProvided(require, primary_provide, object, base)
+
+
+    def register(self, require, provide, object):
+        if require is not None and not IInterface.isImplementedBy(require):
+            raise TypeError(
+                "The require argument must be an interface (or None)")
+        if not IInterface.isImplementedBy(provide):
+            raise TypeError(
+                "The provide argument must be an interface (or None)")
+        
+        self._registerAllProvided(require, provide, object, provide)
+
+    def get(self, (ob_interface, provide), default=None, filter=None):
+        """
+        Finds a registered component that provides the given interface.
+        Returns None if not found.
+        """
+        for interface in _flatten(ob_interface, 1):
+            c = self._reg.get((interface, provide))
+            if c:
+                c = c[1]
+                if filter is None:
+                    return c
+                if filter(c):
+                    return c
+
+        return default
+
+    def getForObject(self, object, interface, filter=None):
+        return self.get((getattr(object, '__implements__', None), interface),
+                        filter=filter)
+
+    def getRegistered(self, require, provide):
+        data = self._reg.get((require, provide))
+        if data:
+            registered_provide, object = data
+            if registered_provide == provide:
+                return object
+        return None
+
+    def getRegisteredMatching(self,
+                              required_interfaces=None,
+                              provided_interfaces=None):
+
+
+        if provided_interfaces:
+            r = {}
+
+            if required_interfaces:
+                # Both specified
+                for required in _flatten(required_interfaces, 1):
+                    for provided in provided_interfaces:
+                        v = self._reg.get((required, provided))
+                        if v:
+                            rprovided, o = v                        
+                            r[required, rprovided] = o
+
+
+            else:
+                # Only provided specified
+                for (required, provided), (rprovided, o) in self._reg.items():
+                    for p in provided_interfaces:
+                        if provided.extends(p, 0):
+                            r[required, rprovided] = o
+                            break
+
+            return [(required, provided, o)
+                    for ((required, provided), o) in r.items()]
+
+
+        elif required_interfaces:
+            # Just required specified
+            required_interfaces = _flatten(required_interfaces, 1)
+            return [(required, provided, o)
+                    for (required, provided), (rprovided, o)
+                    in self._reg.items()
+                    if ((required in required_interfaces)
+                        and
+                        provided == rprovided
+                        )
+                   ]
+            
+        else:
+            # Nothing specified
+            return [(required, provided, o)
+                    for (required, provided), (rprovided, o)
+                    in self._reg.items()
+                    if provided == rprovided
+                   ]
+                        
+                        


=== Zope3/lib/python/Interface/Registry/IAdapterRegistry.py 1.2.8.3 => 1.2.8.4 ===
--- Zope3/lib/python/Interface/Registry/IAdapterRegistry.py:1.2.8.3	Thu Oct 24 01:52:05 2002
+++ Zope3/lib/python/Interface/Registry/IAdapterRegistry.py	Wed Nov 13 15:23:17 2002
@@ -1,113 +1,113 @@
-##############################################################################
-#
-# Copyright (c) 2002 Zope Corporation and Contributors.
-# All Rights Reserved.
-# 
-# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
-# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
-# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE.
-# 
-##############################################################################
-"""
-
-$Id$
-"""
-
-from Interface import Interface
-
-class IAdapterRegistry(Interface):
-    """Adapter-style registry
-
-    This registry stores objects registered to convert (or participate
-    in the conversion from) one interface to another. The interface
-    converted is the "required" interface. We say that the interface
-    converted to is the "provided" interface.
-
-    The objects registered here don't need to be adapters. What's
-    important is that they are registered according to a required and
-    a provided interface.
-
-    The provided interface may not be None.
-
-    The required interface may be None. Adapters with a required
-    interface of None adapt non-components. An adapter that adapts all
-    components should specify a required interface of
-    Interface.Interface.
-    
-    """
-
-    def register(require, provide, object):
-        """Register an object for a required and provided interface.
-
-        There are no restrictions on what the object might be.
-        Any restrictions (e.g. callability, or interface
-        implementation) must be enforced by higher-level code.
-
-        The require argument may be None.
-
-        """
-
-    def get((implements, provides), default=None, filter=None):
-        """Return a registered object
-
-        The registered object is one that was registered to require an
-        interface that one of the interfaces in the 'implements'
-        specification argument extends or equals and that provides an
-        interface that extends or equals the 'provides' argument.  An
-        attempt will be made to find the component that most closely
-        matches the input arguments.
-
-        The object returned could have been registred to require None.
-
-        Note that the implements may be None, it which case a
-        component will be returned only if it was registered with a
-        require of None.
-
-        An optional filter may be provided. If provided, the returned
-        object must pass the filter. Search will continue until a
-        suitable match can be found. The filter should take a single
-        argument and return a true value if the object passes the
-        filter, or false otherwise.
-        
-        """
-    
-    def getForObject(object, interface, filter=None):
-        """Get an adapter for object that implements the specified interface
-
-        The filter option has the same meaning as in the get method.
-        """
-
-    def getRegistered(require, provide):
-        """return data registred specificly for the given interfaces
-        """
-    
-    def getRegisteredMatching(required_interfaces=None,
-                              provided_interfaces=None):
-        """Return information about registered data
-
-        Zero or more required and provided interfaces may be
-        specified. Registration information matching any of the
-        specified interfaces is returned. The returned value is a
-        sequence of three-element tuples:
-
-        - required interface
-
-        - provided interface
-
-        - the object registered specifically for the required and
-          provided interfaces.
-
-        To understand hopw the matching works, imagine that we have
-        interfaces R1, R2, P1, and P2. R2 extends R1. P2 extends P1.
-        We've registered C to require R1 and provide P2.  Given this,
-        if we call getRegisteredMatching:
-
-          registery.getRegisteredMatching([R2], [P1])
-
-        the returned value will include:
-
-          (R1, P2, C)
-        """
+##############################################################################
+#
+# Copyright (c) 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+# 
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+# 
+##############################################################################
+"""
+
+$Id$
+"""
+
+from Interface import Interface
+
+class IAdapterRegistry(Interface):
+    """Adapter-style registry
+
+    This registry stores objects registered to convert (or participate
+    in the conversion from) one interface to another. The interface
+    converted is the "required" interface. We say that the interface
+    converted to is the "provided" interface.
+
+    The objects registered here don't need to be adapters. What's
+    important is that they are registered according to a required and
+    a provided interface.
+
+    The provided interface may not be None.
+
+    The required interface may be None. Adapters with a required
+    interface of None adapt non-components. An adapter that adapts all
+    components should specify a required interface of
+    Interface.Interface.
+    
+    """
+
+    def register(require, provide, object):
+        """Register an object for a required and provided interface.
+
+        There are no restrictions on what the object might be.
+        Any restrictions (e.g. callability, or interface
+        implementation) must be enforced by higher-level code.
+
+        The require argument may be None.
+
+        """
+
+    def get((implements, provides), default=None, filter=None):
+        """Return a registered object
+
+        The registered object is one that was registered to require an
+        interface that one of the interfaces in the 'implements'
+        specification argument extends or equals and that provides an
+        interface that extends or equals the 'provides' argument.  An
+        attempt will be made to find the component that most closely
+        matches the input arguments.
+
+        The object returned could have been registred to require None.
+
+        Note that the implements may be None, it which case a
+        component will be returned only if it was registered with a
+        require of None.
+
+        An optional filter may be provided. If provided, the returned
+        object must pass the filter. Search will continue until a
+        suitable match can be found. The filter should take a single
+        argument and return a true value if the object passes the
+        filter, or false otherwise.
+        
+        """
+    
+    def getForObject(object, interface, filter=None):
+        """Get an adapter for object that implements the specified interface
+
+        The filter option has the same meaning as in the get method.
+        """
+
+    def getRegistered(require, provide):
+        """return data registred specificly for the given interfaces
+        """
+    
+    def getRegisteredMatching(required_interfaces=None,
+                              provided_interfaces=None):
+        """Return information about registered data
+
+        Zero or more required and provided interfaces may be
+        specified. Registration information matching any of the
+        specified interfaces is returned. The returned value is a
+        sequence of three-element tuples:
+
+        - required interface
+
+        - provided interface
+
+        - the object registered specifically for the required and
+          provided interfaces.
+
+        To understand hopw the matching works, imagine that we have
+        interfaces R1, R2, P1, and P2. R2 extends R1. P2 extends P1.
+        We've registered C to require R1 and provide P2.  Given this,
+        if we call getRegisteredMatching:
+
+          registery.getRegisteredMatching([R2], [P1])
+
+        the returned value will include:
+
+          (R1, P2, C)
+        """