[Zope3-checkins] CVS: Zope3/lib/python/Interface/Registry - AdapterRegistry.py:1.2.8.1 IAdapterRegistry.py:1.2.8.1

K.Narasimha Murthy nmurthy@zeomega.com
Tue, 15 Oct 2002 10:41:30 -0400


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

Modified Files:
      Tag: Zope3-Bangalore-TTW-Branch
	AdapterRegistry.py IAdapterRegistry.py 
Log Message:
changed  the AdapterRegistry constructer to take in an optional parameter viz: data 
 Added a new getRegistered() method to the IAdapterRegistry and AdapterRegistry`


=== Zope3/lib/python/Interface/Registry/AdapterRegistry.py 1.2 => 1.2.8.1 ===
--- Zope3/lib/python/Interface/Registry/AdapterRegistry.py:1.2	Thu Aug  1 12:06:41 2002
+++ Zope3/lib/python/Interface/Registry/AdapterRegistry.py	Tue Oct 15 10:41:30 2002
@@ -1,95 +1,105 @@
-##############################################################################
-#
-# 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):
-        self._reg = {}
-        
-    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):
-        """
-        Finds a registered component that provides the given interface.
-        Returns None if not found.
-        """
-        for interface in _flatten(ob_interface):
-            c = self._reg.get((interface, provide))
-            if c:
-                return c[1]
-
-        c = self._reg.get((None, provide), default)
-        if c:
-            return c[1]
-
-        return c
-
-    def getForObject(self, object, interface):
-        return self.get((getattr(object, '__implements__', None), interface))
+##############################################################################
+#
+# 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):
+        """
+        Finds a registered component that provides the given interface.
+        Returns None if not found.
+        """
+        for interface in _flatten(ob_interface):
+            c = self._reg.get((interface, provide))
+            if c:
+                return c[1]
+
+        c = self._reg.get((None, provide), default)
+        if c:
+            return c[1]
+
+        return c
+
+    def getForObject(self, object, interface):
+        return self.get((getattr(object, '__implements__', None), interface))
+
+    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


=== Zope3/lib/python/Interface/Registry/IAdapterRegistry.py 1.2 => 1.2.8.1 ===
--- Zope3/lib/python/Interface/Registry/IAdapterRegistry.py:1.2	Thu Aug  1 11:37:08 2002
+++ Zope3/lib/python/Interface/Registry/IAdapterRegistry.py	Tue Oct 15 10:41:30 2002
@@ -1,73 +1,77 @@
-##############################################################################
-#
-# 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):
-        """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.
-        """
-    
-    def getForObject(object, interface):
-        """Get an adapter for object that implements the specified interface
-        """
-    
+##############################################################################
+#
+# 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):
+        """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.
+        """
+    
+    def getForObject(object, interface):
+        """Get an adapter for object that implements the specified interface
+        """
+
+    def getRegistered(require, provide):
+        """return data registred specificly for the given interfaces
+        """
+