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