[Checkins] SVN: zope.interface/branches/regebro-python3/ Added the implementer_only decorator that will replace implementOnly. I'm not happy with the name, but

Lennart Regebro regebro at gmail.com
Tue Apr 7 12:45:43 EDT 2009


Log message for revision 98980:
  Added the implementer_only decorator that will replace implementOnly. I'm not happy with the name, but 
  we can still change it.
  

Changed:
  U   zope.interface/branches/regebro-python3/build_ext_3.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/__init__.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/declarations.py
  U   zope.interface/branches/regebro-python3/src/zope/interface/interfaces.py

-=-
Modified: zope.interface/branches/regebro-python3/build_ext_3.py
===================================================================
--- zope.interface/branches/regebro-python3/build_ext_3.py	2009-04-07 16:31:03 UTC (rev 98979)
+++ zope.interface/branches/regebro-python3/build_ext_3.py	2009-04-07 16:45:43 UTC (rev 98980)
@@ -138,8 +138,7 @@
     
             # 2to3
             self.fixer_names = get_fixers_from_package('lib2to3.fixes') + \
-                ['zope.fixers.fix_implements',]
-            #self.fixer_names = ['fix_implements',]
+                get_fixers_from_package('zope.fixers')
             self.run_2to3(self.updated_files)
             self.run_2to3(self.possible_doctests, doctests_only=True)
     

Modified: zope.interface/branches/regebro-python3/src/zope/interface/__init__.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/__init__.py	2009-04-07 16:31:03 UTC (rev 98979)
+++ zope.interface/branches/regebro-python3/src/zope/interface/__init__.py	2009-04-07 16:45:43 UTC (rev 98980)
@@ -63,7 +63,8 @@
 from zope.interface.declarations import providedBy, implementedBy
 from zope.interface.declarations import classImplements, classImplementsOnly
 from zope.interface.declarations import directlyProvidedBy, directlyProvides
-from zope.interface.declarations import alsoProvides, implementer
+from zope.interface.declarations import alsoProvides
+from zope.interface.declarations import implementer, implementer_only
 from zope.interface.declarations import implements, implementsOnly
 from zope.interface.declarations import classProvides, moduleProvides
 from zope.interface.declarations import noLongerProvides, Declaration

Modified: zope.interface/branches/regebro-python3/src/zope/interface/declarations.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/declarations.py	2009-04-07 16:31:03 UTC (rev 98979)
+++ zope.interface/branches/regebro-python3/src/zope/interface/declarations.py	2009-04-07 16:45:43 UTC (rev 98980)
@@ -503,6 +503,23 @@
             classImplements(ob, *self.interfaces)
             return ob            
 
+class implementer_only:
+
+    def __init__(self, *interfaces):
+        self.interfaces = interfaces
+
+    def __call__(self, ob):
+        if isinstance(ob, (FunctionType, MethodType)):
+            # XXX Does this decorator make sense for anything but classes?
+            # I don't think so. There can be no inheritance of interfaces
+            # on a method pr function....
+            raise ValueError('The implementor_only decorator is not '
+                             'supported for methods or functions.')
+        else:
+            # Assume it's a class:
+            classImplementsOnly(ob, *self.interfaces)
+            return ob            
+        
 def _implements(name, interfaces, classImplements):
     frame = sys._getframe(2)
     locals = frame.f_locals

Modified: zope.interface/branches/regebro-python3/src/zope/interface/interfaces.py
===================================================================
--- zope.interface/branches/regebro-python3/src/zope/interface/interfaces.py	2009-04-07 16:31:03 UTC (rev 98979)
+++ zope.interface/branches/regebro-python3/src/zope/interface/interfaces.py	2009-04-07 16:45:43 UTC (rev 98980)
@@ -446,6 +446,13 @@
         Instances of ``C`` provide only ``I1``, ``I2``, and regardless of
         whatever interfaces instances of ``A`` and ``B`` implement.
         """
+        
+    def implementer_only(*interfaces):
+        """Create a decorator for declaring the only interfaces implemented 
+        
+        A callable is returned that makes an implements declaration on
+        objects passed to it.
+        """
 
     def directlyProvidedBy(object):
         """Return the interfaces directly provided by the given object



More information about the Checkins mailing list