[Zope-Checkins] SVN: Products.Five/branches/philikon-local-components/ Make the marking of "five methods" nicer by using a descriptor.

Philipp von Weitershausen philikon at philikon.de
Sun Mar 5 11:30:15 EST 2006


Log message for revision 65824:
  Make the marking of "five methods" nicer by using a descriptor.
  Also, make some relative imports absolute ones. Death to absolute imports! (at
  least the way they currently exist in Python)
  

Changed:
  U   Products.Five/branches/philikon-local-components/__init__.py
  U   Products.Five/branches/philikon-local-components/fiveconfigure.py
  U   Products.Five/branches/philikon-local-components/sizeconfigure.py
  U   Products.Five/branches/philikon-local-components/traversable.py
  U   Products.Five/branches/philikon-local-components/viewable.py

-=-
Modified: Products.Five/branches/philikon-local-components/__init__.py
===================================================================
--- Products.Five/branches/philikon-local-components/__init__.py	2006-03-05 14:41:35 UTC (rev 65823)
+++ Products.Five/branches/philikon-local-components/__init__.py	2006-03-05 16:30:15 UTC (rev 65824)
@@ -18,12 +18,23 @@
 import Acquisition
 from Globals import INSTANCE_HOME
 
-import zcml
+from Products.Five import zcml
 
 # public API provided by Five
 # usage: from Products.Five import <something>
-from browser import BrowserView
-from skin.standardmacros import StandardMacros
+from Products.Five.browser import BrowserView
+from Products.Five.skin.standardmacros import StandardMacros
 
+# load the site's ZCML tree (usually site.zcml) upon product
+# initialization
 def initialize(context):
     zcml.load_site()
+
+# some convenience methods/decorators
+
+def fivemethod(func):
+    func.__five_method__ = True
+    return func
+
+def isFiveMethod(m):
+    return hasattr(m, '__five_method__')

Modified: Products.Five/branches/philikon-local-components/fiveconfigure.py
===================================================================
--- Products.Five/branches/philikon-local-components/fiveconfigure.py	2006-03-05 14:41:35 UTC (rev 65823)
+++ Products.Five/branches/philikon-local-components/fiveconfigure.py	2006-03-05 16:30:15 UTC (rev 65824)
@@ -37,10 +37,11 @@
 from zope.app.component.metaconfigure import adapter
 from zope.app.security.interfaces import IPermission
 
-from viewable import Viewable
-from traversable import Traversable
-from bridge import fromZ2Interface
-from browser.metaconfigure import page
+from Products.Five import isFiveMethod
+from Products.Five.viewable import Viewable
+from Products.Five.traversable import Traversable
+from Products.Five.bridge import fromZ2Interface
+from Products.Five.browser.metaconfigure import page
 
 debug_mode = App.config.getConfiguration().debug_mode
 
@@ -107,9 +108,6 @@
                     interface)
             )
 
-def isFiveMethod(m):
-    return hasattr(m, '__five_method__')
-
 _traversable_monkies = []
 def classTraversable(class_):
     # If a class already has this attribute, it means it is either a

Modified: Products.Five/branches/philikon-local-components/sizeconfigure.py
===================================================================
--- Products.Five/branches/philikon-local-components/sizeconfigure.py	2006-03-05 14:41:35 UTC (rev 65823)
+++ Products.Five/branches/philikon-local-components/sizeconfigure.py	2006-03-05 16:30:15 UTC (rev 65824)
@@ -17,11 +17,12 @@
 $Id$
 """
 from zope.app.size.interfaces import ISized
-from Products.Five.fiveconfigure import isFiveMethod
+from Products.Five import fivemethod, isFiveMethod
 
 # holds classes that were monkeyed with; for clean up
 _monkied = []
 
+ at fivemethod
 def get_size(self):
     size = ISized(self, None)
     if size is not None:
@@ -32,8 +33,6 @@
     if method is not None:
         return self.__five_original_get_size()
 
-get_size.__five_method__ = True
-
 def classSizable(class_):
     """Monkey the class to be sizable through Five"""
     # tuck away the original method if necessary

Modified: Products.Five/branches/philikon-local-components/traversable.py
===================================================================
--- Products.Five/branches/philikon-local-components/traversable.py	2006-03-05 14:41:35 UTC (rev 65823)
+++ Products.Five/branches/philikon-local-components/traversable.py	2006-03-05 16:30:15 UTC (rev 65824)
@@ -29,6 +29,7 @@
 from zope.app.interface import queryType
 
 from AccessControl import getSecurityManager
+from Products.Five import fivemethod
 from Products.Five.security import newInteraction
 
 _marker = object
@@ -47,6 +48,7 @@
     """
     __five_traversable__ = True
 
+    @fivemethod
     def __fallback_traverse__(self, REQUEST, name):
         """Method hook for fallback traversal
 
@@ -57,8 +59,8 @@
         and let Zope do it's job.
         """
         raise NotImplementedError
-    __fallback_traverse__.__five_method__ = True
 
+    @fivemethod
     def __bobo_traverse__(self, REQUEST, name):
         """Hook for Zope 2 traversal
 
@@ -103,9 +105,6 @@
             pass
         raise AttributeError, name
 
-    __bobo_traverse__.__five_method__ = True
-
-
 class FiveTraversable(DefaultTraversable):
 
     def traverse(self, name, furtherPath):

Modified: Products.Five/branches/philikon-local-components/viewable.py
===================================================================
--- Products.Five/branches/philikon-local-components/viewable.py	2006-03-05 14:41:35 UTC (rev 65823)
+++ Products.Five/branches/philikon-local-components/viewable.py	2006-03-05 16:30:15 UTC (rev 65824)
@@ -22,6 +22,7 @@
 from zope.publisher.interfaces.browser import IBrowserRequest
 from zope.app.zapi import getDefaultViewName
 
+from Products.Five import fivemethod
 from Products.Five.traversable import FakeRequest
 from Products.Five.interfaces import IBrowserDefault
 
@@ -45,6 +46,7 @@
     #    return self
 
     # we have a default view, tell zpublisher to go there
+    @fivemethod
     def __browser_default__(self, request):
         obj = self
         path = None
@@ -59,11 +61,11 @@
                 return obj, ('fallback_call__',)
             return obj, path
         return self.__fallback_default__(request)
-    __browser_default__.__five_method__ = True
 
     # this is technically not needed because ZPublisher finds our
     # attribute through __browser_default__; but we also want to be
     # able to call pages from python modules, PythonScripts or ZPT
+    # @fivemethod
     # def __call__(self, *args, **kw):
     #    """ """
     #    request = kw.get('REQUEST')
@@ -77,7 +79,6 @@
     #        if meth is not None:
     #            return meth(*args, **kw)
     #    return self.fallback_call__(*args, **kw)
-    # __call__.__five_method__ = True
 
 # def simpleRecursion():
 #     # This tests for simple recursion, which can easily happen



More information about the Zope-Checkins mailing list