[Zope-Checkins] SVN: Zope/trunk/src/Products/Five/browser/metaconfigure.py - now we can simplify that code a bit

Yvo Schubbe cvs-admin at zope.org
Tue Jul 10 13:13:03 UTC 2012


Log message for revision 127299:
  - now we can simplify that code a bit

Changed:
  U   Zope/trunk/src/Products/Five/browser/metaconfigure.py

-=-
Modified: Zope/trunk/src/Products/Five/browser/metaconfigure.py
===================================================================
--- Zope/trunk/src/Products/Five/browser/metaconfigure.py	2012-07-10 13:05:08 UTC (rev 127298)
+++ Zope/trunk/src/Products/Five/browser/metaconfigure.py	2012-07-10 13:12:59 UTC (rev 127299)
@@ -120,38 +120,29 @@
                 raise ConfigurationError(
                     "The provided class doesn't have the specified attribute "
                     )
-        cdict = getSecurityInfo(class_)
-        cdict['__name__'] = name
         if template:
             # class and template
             new_class = SimpleViewClass(template, bases=(class_, ), name=name)
-        elif attribute != "__call__":
-            # we're supposed to make a page for an attribute (read:
-            # method) and it's not __call__.  We thus need to create a
-            # new class using our mixin for attributes.
-            cdict['__page_attribute__'] = attribute
-            new_class = makeClass(class_.__name__, (class_, simple), cdict)
-
-            # in case the attribute does not provide a docstring,
-            # ZPublisher refuses to publish it.  So, as a workaround,
-            # we provide a stub docstring
-            func = getattr(new_class, attribute)
-            if not func.__doc__:
-                # cannot test for MethodType/UnboundMethod here
-                # because of ExtensionClass
-                if hasattr(func, 'im_func'):
-                    # you can only set a docstring on functions, not
-                    # on method objects
-                    func = func.im_func
-                func.__doc__ = "Stub docstring to make ZPublisher work"
         else:
-            # we could use the class verbatim here, but we'll execute
-            # some security declarations on it so we really shouldn't
-            # modify the original.  So, instead we make a new class
-            # with just one base class -- the original
+            cdict = getSecurityInfo(class_)
+            cdict['__name__'] = name
             cdict['__page_attribute__'] = attribute
             new_class = makeClass(class_.__name__, (class_, simple), cdict)
 
+            if attribute != "__call__":
+                # in case the attribute does not provide a docstring,
+                # ZPublisher refuses to publish it.  So, as a workaround,
+                # we provide a stub docstring
+                func = getattr(new_class, attribute)
+                if not func.__doc__:
+                    # cannot test for MethodType/UnboundMethod here
+                    # because of ExtensionClass
+                    if hasattr(func, 'im_func'):
+                        # you can only set a docstring on functions, not
+                        # on method objects
+                        func = func.im_func
+                    func.__doc__ = "Stub docstring to make ZPublisher work"
+
     else:
         # template
         new_class = SimpleViewClass(template, name=name)



More information about the Zope-Checkins mailing list