[Zope-CVS] CVS: Products/PluggableAuthService - utils.py:1.6

Zachery Bir zbir at urbanape.com
Wed Jul 6 14:47:09 EDT 2005


Update of /cvs-repository/Products/PluggableAuthService
In directory cvs.zope.org:/tmp/cvs-serv28478

Modified Files:
	utils.py 
Log Message:
Several 2.7/2.8 compatibility utilities


=== Products/PluggableAuthService/utils.py 1.5 => 1.6 ===
--- Products/PluggableAuthService/utils.py:1.5	Mon Jan 31 14:01:39 2005
+++ Products/PluggableAuthService/utils.py	Wed Jul  6 14:47:07 2005
@@ -18,12 +18,50 @@
 from Globals import package_home
 
 try:
-    from zope.interface import directlyProvides
+    from zope.interface import providedBy
 except ImportError:
+    def providedBy(obj):
+        return obj.__implements__
+
+try:
+    from zope.interface import implementedBy
+except ImportError:
+    def implementedBy(klass):
+        return klass.__implements__
+
+try:
+    from zope import interface
+except ImportError:
+    def directlyProvides(obj, *interfaces):
+        obj.__implements__ = tuple( interfaces )
+
+    def classImplements(class_, *interfaces):
+        class_.__implements__ = tuple( interfaces )
+
+else:
     def directlyProvides(obj, *interfaces):
-        obj.__implements__ = ( getattr( obj.__class__, '__implements__', () ) +
-                               tuple( interfaces )
-                             )
+        from Products.Five.bridge import fromZ2Interface
+        # convert any Zope 2 interfaces to Zope 3 using fromZ2Interface
+        normalized_interfaces = []
+        for i in interfaces:
+            try:
+                i = fromZ2Interface(i)
+            except ValueError: # already a Zope 3 interface
+                pass
+            normalized_interfaces.append(i)
+        return interface.directlyProvides(obj, *normalized_interfaces)
+
+    def classImplements(class_, *interfaces):
+        from Products.Five.bridge import fromZ2Interface
+        # convert any Zope 2 interfaces to Zope 3 using fromZ2Interface
+        normalized_interfaces = []
+        for i in interfaces:
+            try:
+                i = fromZ2Interface(i)
+            except ValueError: # already a Zope 3 interface
+                pass
+            normalized_interfaces.append(i)
+        return interface.classImplements(class_, *normalized_interfaces)
 
 
 product_dir = package_home( globals() )



More information about the Zope-CVS mailing list