Commit e6c0a217 authored by Julien Muchembled's avatar Julien Muchembled

Define well-behaved decorators using 'functools.wraps'

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2682 71dcc9de-d417-0410-9af5-da40c76e7ee4
parent 9f20fc76
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from functools import wraps
from ZODB import BaseStorage, ConflictResolution, POSException from ZODB import BaseStorage, ConflictResolution, POSException
from zope.interface import implements from zope.interface import implements
import ZODB.interfaces import ZODB.interfaces
...@@ -32,7 +33,7 @@ def check_read_only(func): ...@@ -32,7 +33,7 @@ def check_read_only(func):
if self._is_read_only: if self._is_read_only:
raise POSException.ReadOnlyError() raise POSException.ReadOnlyError()
return func(self, *args, **kw) return func(self, *args, **kw)
return wrapped return wraps(func)(wrapped)
class DummyCache(object): class DummyCache(object):
def __init__(self, app): def __init__(self, app):
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from functools import wraps
from time import time from time import time
import neo.lib import neo.lib
...@@ -44,7 +45,7 @@ def not_closed(func): ...@@ -44,7 +45,7 @@ def not_closed(func):
if self.connector is None: if self.connector is None:
raise ConnectorConnectionClosedException raise ConnectorConnectionClosedException
return func(self, *args, **kw) return func(self, *args, **kw)
return decorator return wraps(func)(decorator)
def lockCheckWrapper(func): def lockCheckWrapper(func):
...@@ -67,7 +68,7 @@ def lockCheckWrapper(func): ...@@ -67,7 +68,7 @@ def lockCheckWrapper(func):
self.__class__.__name__, ''.join(traceback.format_stack())) self.__class__.__name__, ''.join(traceback.format_stack()))
# Call anyway # Call anyway
return func(self, *args, **kw) return func(self, *args, **kw)
return wrapper return wraps(func)(wrapper)
class OnTimeout(object): class OnTimeout(object):
""" """
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from functools import wraps
from neo.lib.locking import Lock, Empty from neo.lib.locking import Lock, Empty
from neo.lib.profiling import profiler_decorator from neo.lib.profiling import profiler_decorator
EMPTY = {} EMPTY = {}
...@@ -39,7 +40,7 @@ def giant_lock(func): ...@@ -39,7 +40,7 @@ def giant_lock(func):
return func(self, *args, **kw) return func(self, *args, **kw)
finally: finally:
self.lock_release() self.lock_release()
return wrapped return wraps(func)(wrapped)
class Dispatcher: class Dispatcher:
"""Register a packet, connection pair as expecting a response packet.""" """Register a packet, connection pair as expecting a response packet."""
......
...@@ -20,6 +20,7 @@ import signal ...@@ -20,6 +20,7 @@ import signal
import ctypes import ctypes
import imp import imp
import os import os
from functools import wraps
import neo import neo
# WARNING: This module should only be used for live application debugging. # WARNING: This module should only be used for live application debugging.
...@@ -53,7 +54,7 @@ def decorate(func): ...@@ -53,7 +54,7 @@ def decorate(func):
# "debug" module don't kill process. # "debug" module don't kill process.
traceback.print_exc() traceback.print_exc()
errno.value = old_errno errno.value = old_errno
return decorator return wraps(func)(decorator)
@decorate @decorate
def debugHandler(sig, frame): def debugHandler(sig, frame):
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from functools import wraps
import neo import neo
from neo.lib import protocol from neo.lib import protocol
...@@ -340,7 +341,7 @@ def thread_safe(method): ...@@ -340,7 +341,7 @@ def thread_safe(method):
return method(self, *args, **kwargs) return method(self, *args, **kwargs)
finally: finally:
self.unlock() self.unlock()
return wrapper return wraps(method)(wrapper)
class MTPartitionTable(PartitionTable): class MTPartitionTable(PartitionTable):
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
from functools import wraps
import neo.lib import neo.lib
from neo.lib.handler import EventHandler from neo.lib.handler import EventHandler
...@@ -71,12 +72,9 @@ Both part follow the same mechanism: ...@@ -71,12 +72,9 @@ Both part follow the same mechanism:
def checkConnectionIsReplicatorConnection(func): def checkConnectionIsReplicatorConnection(func):
def decorator(self, conn, *args, **kw): def decorator(self, conn, *args, **kw):
if self.app.replicator.isCurrentConnection(conn): if self.app.replicator.isCurrentConnection(conn):
result = func(self, conn, *args, **kw) return func(self, conn, *args, **kw)
else:
# Should probably raise & close connection... # Should probably raise & close connection...
result = None return wraps(func)(decorator)
return result
return decorator
class ReplicationHandler(EventHandler): class ReplicationHandler(EventHandler):
"""This class handles events for replications.""" """This class handles events for replications."""
......
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