Commit 34b1bfc7 authored by Julien Muchembled's avatar Julien Muchembled

Simplify code of some decorators

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@40071 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ea31cff4
...@@ -88,14 +88,11 @@ from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate ...@@ -88,14 +88,11 @@ from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
PICKLE_CLEANERS = {} PICKLE_CLEANERS = {}
class cleaner_for(object): def cleaner_for(classdef):
def wrapper(func):
def __init__(self, classdef): PICKLE_CLEANERS[classdef] = func
self.classdef = classdef return func
return wrapper
def __call__(self, callable):
PICKLE_CLEANERS[self.classdef] = callable
return callable
# BBB: Remove this cleaner when we drop support for Zope 2.8 # BBB: Remove this cleaner when we drop support for Zope 2.8
@cleaner_for(ZopePageTemplate) @cleaner_for(ZopePageTemplate)
......
...@@ -41,6 +41,7 @@ from Products.MailHost.MailHost import MailHost ...@@ -41,6 +41,7 @@ from Products.MailHost.MailHost import MailHost
from email import message_from_string from email import message_from_string
import backportUnittest import backportUnittest
from Products.ERP5Type.Globals import PersistentMapping from Products.ERP5Type.Globals import PersistentMapping
from Products.ERP5Type.Utils import simple_decorator
from Products.ZSQLCatalog.SQLCatalog import Catalog from Products.ZSQLCatalog.SQLCatalog import Catalog
class FileUpload(file): class FileUpload(file):
...@@ -316,23 +317,18 @@ def createZServer(log=os.devnull): ...@@ -316,23 +317,18 @@ def createZServer(log=os.devnull):
hs.close() hs.close()
# decorators # decorators
class reindex(object): @simple_decorator
def reindex(func):
"""Decorator to commit transaction and flush activities after the method is """Decorator to commit transaction and flush activities after the method is
called. called.
""" """
def __init__(self, func): def wrapper(self, *args, **kw):
self._func = func ret = func(self, *args, **kw)
def __get__(self, instance, cls=None):
self._instance = instance
return self
def __call__(self, *args, **kw):
ret = self._func(self._instance, *args, **kw)
if kw.get('reindex', 1): if kw.get('reindex', 1):
transaction.commit() transaction.commit()
self._instance.tic() self.tic()
return ret return ret
return wrapper
# Use this as a method or class decorator to tag it as TODO. # Use this as a method or class decorator to tag it as TODO.
# The test will be skipped: # The test will be skipped:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment