[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/ - Backport of fix for a bug in TypeRegistry for

Christian Theune ct at gocept.com
Thu Jun 10 10:27:17 EDT 2004


Log message for revision 25332:
 - Backport of fix for a bug in TypeRegistry for
   zope.app.publisher.browser.globalbrowsermenuservice which allows passing
   classes instead of interfaces as well but has a missing import.




-=-
Modified: Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt
===================================================================
--- Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt	2004-06-10 14:17:57 UTC (rev 25331)
+++ Zope3/branches/ZopeX3-3.0/doc/CHANGES.txt	2004-06-10 14:27:17 UTC (rev 25332)
@@ -15,6 +15,11 @@
       - Fixed the default 'text/*' content type for file objects.
         Backport of the fix for bug 201.
 
+      - Fixed bug in TypeRegistry for
+        zope.app.publisher.browser.globalbrowsermenuservice which allows
+        passing classes instead of interfaces as well but has a missing
+        import.
+
       - A monkey patch to cope with weakref problems in Python 2.3.3
         was removed, so Python 2.3.4 is required now.
 

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/browser/globalbrowsermenuservice.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/browser/globalbrowsermenuservice.py	2004-06-10 14:17:57 UTC (rev 25331)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/browser/globalbrowsermenuservice.py	2004-06-10 14:27:17 UTC (rev 25332)
@@ -19,7 +19,7 @@
 
 import sys
 from zope.exceptions import DuplicationError, Unauthorized, Forbidden
-from zope.interface import implements
+from zope.interface import implements, implementedBy
 from zope.security.checker import CheckerPublic
 from zope.security import checkPermission
 from zope.app.component.metaconfigure import handler
@@ -48,12 +48,12 @@
         self._reg = {}
 
     def register(self, interface, object):
-        if not (interface is None or IInterface.providedBy(interface)):
+        if interface is not None and not IInterface.providedBy(interface):
             if isinstance(interface, (type, types.ClassType)):
-                interface = zope.interface.implementedBy(interface)
+                interface = implementedBy(interface)
             else:
                 raise TypeError(
-                    "The interface argument must be an interface (or None)")
+                    "The interface argument must be an interface (or None) or a class.")
         
         self._reg[interface] = object
 

Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py	2004-06-10 14:17:57 UTC (rev 25331)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/publisher/browser/tests/test_globalbrowsermenuservice.py	2004-06-10 14:27:17 UTC (rev 25332)
@@ -36,6 +36,9 @@
 class I12(I1): pass
 class I111(I11): pass
 
+class C1(object):
+    implements(I1)
+            
 class TestObject:
     implements(IBrowserPublisher, I111)
 
@@ -227,7 +230,17 @@
                 ]
         self.assertEqual(menu, [d(5), d(6), d(7), d(8), d(3), d(2), d(1)])
 
+    def test_addWrong(self):
+        r = self.__reg()
+        
+        x = []
+        r.menu('test_id', 'test menu')
+        self.assertRaises(TypeError, r.menuItem, 'test_id', x, 'a1', 'a2',' a3')
 
+    def test_addClass(self):
+        r = self.__reg()
+        r.menu('test_id', 'test menu')
+        r.menuItem('test_id', C1, 'a1', 'a2', 'a3')
 
 def test_suite():
     return unittest.TestSuite((




More information about the Zope3-Checkins mailing list