[Erp5-report] r37064 jm - /erp5/trunk/products/ERP5Type/

nobody at svn.erp5.org nobody at svn.erp5.org
Mon Jul 12 18:07:14 CEST 2010


Author: jm
Date: Mon Jul 12 18:07:13 2010
New Revision: 37064

URL: http://svn.erp5.org?rev=37064&view=rev
Log:
Fix __name__ and __doc__ of some decorated functions

Modified:
    erp5/trunk/products/ERP5Type/Cache.py
    erp5/trunk/products/ERP5Type/UnrestrictedMethod.py
    erp5/trunk/products/ERP5Type/Utils.py

Modified: erp5/trunk/products/ERP5Type/Cache.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Cache.py?rev=37064&r1=37063&r2=37064&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Cache.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Cache.py [utf8] Mon Jul 12 18:07:13 2010
@@ -33,6 +33,7 @@ from AccessControl.SecurityInfo import a
 from CachePlugins.BaseCache import CachedMethodError
 from zLOG import LOG, WARNING
 from Products.ERP5Type.TransactionalVariable import getTransactionalVariable
+from Products.ERP5Type.Utils import simple_decorator
 from warnings import warn
 
 DEFAULT_CACHE_SCOPE = 'GLOBAL'
@@ -281,6 +282,7 @@ def generateCacheIdWithoutFirstArg(metho
 
 def caching_instance_method(*args, **kw):
   kw.setdefault('cache_id_generator', generateCacheIdWithoutFirstArg)
+  @simple_decorator
   def wrapped(method):
     # The speed of returned function must be fast
     # so we instanciate CachingMethod now.
@@ -293,6 +295,7 @@ def caching_instance_method(*args, **kw)
   return wrapped
 
 def transactional_cached(key_method=lambda *args: args):
+  @simple_decorator
   def decorator(function):
     key = repr(function)
     def wrapper(*args, **kw):
@@ -303,7 +306,5 @@ def transactional_cached(key_method=lamb
       except KeyError:
         cache[subkey] = result = function(*args, **kw)
         return result
-    wrapper.__doc__ = function.__doc__
-    wrapper.__name__ = function.__name__
     return wrapper
   return decorator

Modified: erp5/trunk/products/ERP5Type/UnrestrictedMethod.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/UnrestrictedMethod.py?rev=37064&r1=37063&r2=37064&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/UnrestrictedMethod.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/UnrestrictedMethod.py [utf8] Mon Jul 12 18:07:13 2010
@@ -34,6 +34,7 @@ try:
   from Zope2 import app
 except ImportError:
   from Zope import app
+from Products.ERP5Type.Utils import simple_decorator
 
 class PrivilegedUser(UnrestrictedUser):
   """User that bypasses all security checks, but retains an original
@@ -48,6 +49,7 @@ class PrivilegedUser(UnrestrictedUser):
     """Get the ID of the user. This is disabled in UnrestrictedUser."""
     return self.getUserName()
 
+ at simple_decorator
 def UnrestrictedMethod(function):
   """Decorator to bypass all security checks.
 
@@ -66,10 +68,7 @@ def UnrestrictedMethod(function):
 
   This method is dangerous. Enough said. Be careful.
   """
-  wrapper = lambda *args, **kw: unrestricted_apply(function, args, kw)
-  wrapper.__doc__ = function.__doc__
-  wrapper.__name__ = function.__name__
-  return wrapper
+  return lambda *args, **kw: unrestricted_apply(function, args, kw)
 
 def unrestricted_apply(function, args=(), kw={}):
     """Function to bypass all security checks

Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=37064&r1=37063&r2=37064&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Mon Jul 12 18:07:13 2010
@@ -65,6 +65,27 @@ from Products.PageTemplates.Expressions 
 from Products.PageTemplates.Expressions import SecureModuleImporter
 from Products.ZCatalog.Lazy import LazyMap
 
+def simple_decorator(decorator):
+  """Decorator to turn simple function into well-behaved decorator
+
+  See also http://wiki.python.org/moin/PythonDecoratorLibrary
+
+  XXX We should use http://pypi.python.org/pypi/decorator/ instead,
+      to make decorators ZPublisher-friendly.
+  """
+  def new_decorator(f):
+    g = decorator(f)
+    g.__name__ = f.__name__
+    g.__doc__ = f.__doc__
+    g.__dict__.update(f.__dict__)
+    return g
+  # Now a few lines needed to make simple_decorator itself
+  # be a well-behaved decorator.
+  new_decorator.__name__ = decorator.__name__
+  new_decorator.__doc__ = decorator.__doc__
+  new_decorator.__dict__.update(decorator.__dict__)
+  return new_decorator
+
 from Products.ERP5Type import Permissions
 
 from Products.ERP5Type.Accessor.Constant import PropertyGetter as \
@@ -194,6 +215,7 @@ def _showwarning(message, category, file
     file.write(warnings.formatwarning(message, category, filename, lineno))
 warnings.showwarning = _showwarning
 
+ at simple_decorator
 def deprecated(wrapped):
   message = "Use of '%s' function (%s, line %s) is deprecated." % (
     wrapped.__name__, wrapped.__module__, wrapped.func_code.co_firstlineno)




More information about the Erp5-report mailing list