CVS: Products/PluggableAuthService - utils.py:1.6

Zachery Bir <[email protected]>
Newsgroups gmane.comp.web.zope.public-cvs
Message-ID <[email protected]>
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() )

_______________________________________________
Zope-CVS maillist  -  [email protected]
http://mail.zope.org/mailman/listinfo/zope-cvs

Zope CVS instructions: http://dev.zope.org/CVS
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.