[Zope3-checkins] SVN: Zope3/trunk/src/zope/interface/t Removed unused type registries.

Jim Fulton jim at zope.com
Sat May 29 08:21:20 EDT 2004


Log message for revision 25123:
Removed unused type registries.



-=-
Deleted: Zope3/trunk/src/zope/interface/tests/test_type.py
===================================================================
--- Zope3/trunk/src/zope/interface/tests/test_type.py	2004-05-29 12:20:42 UTC (rev 25122)
+++ Zope3/trunk/src/zope/interface/tests/test_type.py	2004-05-29 12:21:19 UTC (rev 25123)
@@ -1,162 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2001, 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.
-#
-##############################################################################
-"""
-
-Revision information:
-$Id$
-"""
-
-import unittest
-from zope.interface.type import TypeRegistry
-from zope.interface import Interface, implements
-
-def getAllForObject(reg, ob):
-    all = list(reg.getAllForObject(ob))
-    all.sort()
-    return all
-
-def getTypesMatching(reg, interface):
-    all = list(reg.getTypesMatching(interface))
-    all.sort()
-    return all
-
-class TestTypeRegistry(unittest.TestCase):
-
-    def new_instance(self):
-        return TypeRegistry()
-
-    def test(self):
-        class I1(Interface): pass
-        class I2(I1): pass
-        class I3(I2): pass
-
-        reg = self.new_instance()
-        self.assertEqual(len(reg), 0)
-
-        reg.register(I2, 2)
-        self.assertEqual(len(reg), 1)
-        self.assertEqual(getTypesMatching(reg, None), [I2])
-        self.assertEqual(getTypesMatching(reg, Interface), [I2])
-        self.assertEqual(getTypesMatching(reg, I1), [I2])
-        self.assertEqual(getTypesMatching(reg, I2), [I2])
-        self.assertEqual(getTypesMatching(reg, I3), [])
-
-        class C1: implements(I1)
-        class C2: implements(I2)
-        class C3: implements(I3)
-        class C: pass
-
-        self.assertEqual(getAllForObject(reg, C1()), [])
-        self.assertEqual(getAllForObject(reg, C2()), [2])
-        self.assertEqual(getAllForObject(reg, C3()), [2])
-        self.assertEqual(getAllForObject(reg,  C()), [])
-
-        self.assertEqual(reg.get(I1), None)
-        self.assertEqual(reg.get(I2), 2)
-        self.assertEqual(reg.get(I3), None)
-
-        reg.register(I1, 1)
-        self.assertEqual(len(reg), 2)
-        self.assertEqual(getTypesMatching(reg, None), [I1, I2])
-        self.assertEqual(getTypesMatching(reg, Interface), [I1, I2])
-        self.assertEqual(getTypesMatching(reg, I1), [I1, I2])
-        self.assertEqual(getTypesMatching(reg, I2), [I2])
-        self.assertEqual(getTypesMatching(reg, I3), [])
-
-        self.assertEqual(getAllForObject(reg, C1()), [1])
-        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
-        self.assertEqual(getAllForObject(reg, C3()), [1, 2])
-        self.assertEqual(getAllForObject(reg,  C()), [])
-
-        self.assertEqual(reg.get(I1), 1)
-        self.assertEqual(reg.get(I2), 2)
-        self.assertEqual(reg.get(I3), None)
-
-        reg.register(I3, 3)
-        self.assertEqual(len(reg), 3)
-        self.assertEqual(getTypesMatching(reg, None), [I1, I2, I3])
-        self.assertEqual(getTypesMatching(reg, Interface), [I1, I2, I3])
-        self.assertEqual(getTypesMatching(reg, I1), [I1, I2, I3])
-        self.assertEqual(getTypesMatching(reg, I2), [I2, I3])
-        self.assertEqual(getTypesMatching(reg, I3), [I3])
-
-        self.assertEqual(getAllForObject(reg, C1()), [1])
-        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
-        self.assertEqual(getAllForObject(reg, C3()), [1, 2, 3])
-        self.assertEqual(getAllForObject(reg,  C()), [])
-
-        self.assertEqual(reg.get(I1), 1)
-        self.assertEqual(reg.get(I2), 2)
-        self.assertEqual(reg.get(I3), 3)
-
-        reg.unregister(I3)
-        self.assertEqual(len(reg), 2)
-        self.assertEqual(getTypesMatching(reg, None), [I1, I2])
-        self.assertEqual(getTypesMatching(reg, Interface), [I1, I2])
-        self.assertEqual(getTypesMatching(reg, I1), [I1, I2])
-        self.assertEqual(getTypesMatching(reg, I2), [I2])
-        self.assertEqual(getTypesMatching(reg, I3), [])
-
-        self.assertEqual(getAllForObject(reg, C1()), [1])
-        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
-        self.assertEqual(getAllForObject(reg, C3()), [1, 2])
-        self.assertEqual(getAllForObject(reg,  C()), [])
-
-        self.assertEqual(reg.get(I1), 1)
-        self.assertEqual(reg.get(I2), 2)
-        self.assertEqual(reg.get(I3), None)
-
-    def testSetdefault(self):
-        class I(Interface):
-            pass
-        reg = TypeRegistry()
-        x = reg.setdefault(I, 1)
-        y = reg.setdefault(I, 2)
-        self.assertEqual(x, y)
-        self.assertEqual(x, 1)
-
-    def testDup(self):
-        class I1(Interface): pass
-        class I2(I1): pass
-        class I3(I1): pass
-        class I4(I2, I3): pass
-        class C1: implements(I1)
-        class C2: implements(I2)
-        class C3: implements(I3)
-        class C4: implements(I4)
-        class C5: implements(I1, I2, I3, I4)
-        class C: pass
-
-        reg = TypeRegistry()
-        reg.register(I1, 1)
-        reg.register(I2, 2)
-        reg.register(I3, 3)
-
-        self.assertEqual(getAllForObject(reg, C1()), [1])
-        self.assertEqual(getAllForObject(reg, C2()), [1, 2])
-        self.assertEqual(getAllForObject(reg, C3()), [1, 3])
-        self.assertEqual(getAllForObject(reg, C4()), [1, 2, 3])
-        self.assertEqual(getAllForObject(reg, C5()), [1, 2, 3])
-        self.assertEqual(getAllForObject(reg,  C()), [])
-
-    def testBadRequire(self):
-        registry = TypeRegistry()
-        self.assertRaises(TypeError, registry.register, 42, '')
-
-def test_suite():
-    loader = unittest.TestLoader()
-    return loader.loadTestsFromTestCase(TestTypeRegistry)
-
-if __name__=='__main__':
-    unittest.TextTestRunner().run(test_suite())

Deleted: Zope3/trunk/src/zope/interface/type.py
===================================================================
--- Zope3/trunk/src/zope/interface/type.py	2004-05-29 12:20:42 UTC (rev 25122)
+++ Zope3/trunk/src/zope/interface/type.py	2004-05-29 12:21:19 UTC (rev 25123)
@@ -1,157 +0,0 @@
-##############################################################################
-#
-# 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.
-#
-##############################################################################
-"""This module is DEPRECATED. Don't use it!
-
-$Id$
-"""
-__metaclass__ = type # All classes are new style when run with Python 2.2+
-
-import zope.interface
-import types
-from zope.interface import providedBy, implements, Interface
-from zope.interface.interfaces import IInterface
-
-class ITypeRegistry(Interface):
-    """Type-specific registry
-
-    This registry stores objects registered for objects that implement
-    a required interface.
-    """
-
-    def register(interface, object):
-        """Register an object for an interface.
-
-        The interface argument may be None.  This effectively defines a
-        default object.
-        """
-
-    def unregister(interface):
-        """Remove the registration for the given interface
-
-        If nothing is registered for the interface, the call is ignored.
-        """
-
-    def get(interface, default=None):
-        """Return the object registered for the given interface.
-        """
-
-    def getAll(implements):
-        """Get registered objects
-
-        Return a sequence of all objects registered with interfaces
-        that are extended by or equal to one or more interfaces in the
-        given interface specification.
-
-        Objects that match more specific interfaces of the specification
-        come before those that match less specific interfaces, as per
-        the interface resolution order described in the flattened() operation
-        of IInterfaceSpecification.
-        """
-
-    def getAllForObject(object):
-        """Get all registered objects for types that object implements.
-        """
-
-    def getTypesMatching(interface):
-        """Get all registered interfaces matching the given interface
-
-        Returns a sequence of all interfaces registered that extend
-        or are equal to the given interface.
-        """
-
-    def __len__():
-        """Returns the number of distinct interfaces registered.
-        """
-
-class TypeRegistry:
-
-    implements(ITypeRegistry)
-
-    # XXX This comment doesn't seem to be correct, because the mapping is
-    # from interface -> object.  There are no tuples that I see.  Also,
-    # I'm not sure what the last sentence is trying to say :-).
-
-    # The implementation uses a mapping:
-    #
-    #  { (required, provided) -> (registered_provided, 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 register(self, interface, object):
-        if not (interface is None or IInterface.providedBy(interface)):
-            if isinstance(interface, (type, types.ClassType)):
-                interface = zope.interface.implementedBy(interface)
-            else:
-                raise TypeError(
-                    "The interface argument must be an interface (or None)")
-        
-        self._reg[interface] = object
-        
-    def unregister(self, interface):
-        if interface is None or IInterface.providedBy(interface):
-            if interface in self._reg:
-                del self._reg[interface]
-        else:
-            raise TypeError(
-                "The interface argument must be an interface (or None)")
-
-    def get(self, interface, default=None):
-        """
-        Finds a registered component that provides the given interface.
-        Returns None if not found.
-        """
-        return self._reg.get(interface, default)
-
-    def setdefault(self, interface, default=None):
-        return self._reg.setdefault(interface, default)
-
-    def getAll(self, interface_spec):
-        result = []
-        for interface in interface_spec.flattened():
-            object = self._reg.get(interface)
-            if object is not None:
-                result.append(object)
-
-        if interface_spec is not None:
-            object = self._reg.get(None)
-            if object is not None:
-                result.append(object)
-
-        return result
-
-    def getAllForObject(self, object):
-        # XXX This isn't quite right, since it doesn't take into
-        # account implementation registries for objects that can't
-        # have '__implemented__' attributes.
-        return self.getAll(providedBy(object))
-
-    def getTypesMatching(self, interface):
-        if interface is None:
-            return self._reg.keys()
-
-        result = []
-        for k in self._reg:
-            if k is None or k.extends(interface, False):
-                result.append(k)
-        return result
-
-    def __len__(self):
-        return len(self._reg)




More information about the Zope3-Checkins mailing list