From e6c0a21746dddec4450ba8adaff19c1db21ab240 Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Tue, 22 Mar 2011 10:27:26 +0000
Subject: [PATCH] Define well-behaved decorators using 'functools.wraps'

git-svn-id: https://svn.erp5.org/repos/neo/trunk@2682 71dcc9de-d417-0410-9af5-da40c76e7ee4
---
 neo/client/Storage.py               |  3 ++-
 neo/lib/connection.py               |  5 +++--
 neo/lib/dispatcher.py               |  3 ++-
 neo/lib/live_debug.py               |  3 ++-
 neo/lib/pt.py                       |  3 ++-
 neo/storage/handlers/replication.py | 10 ++++------
 6 files changed, 15 insertions(+), 12 deletions(-)

diff --git a/neo/client/Storage.py b/neo/client/Storage.py
index 7d5d4190..93999e93 100644
--- a/neo/client/Storage.py
+++ b/neo/client/Storage.py
@@ -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):
diff --git a/neo/lib/connection.py b/neo/lib/connection.py
index 945dd1b1..6b8208b9 100644
--- a/neo/lib/connection.py
+++ b/neo/lib/connection.py
@@ -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):
     """
diff --git a/neo/lib/dispatcher.py b/neo/lib/dispatcher.py
index 9a175490..af8cbf32 100644
--- a/neo/lib/dispatcher.py
+++ b/neo/lib/dispatcher.py
@@ -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."""
diff --git a/neo/lib/live_debug.py b/neo/lib/live_debug.py
index c4c8c836..526657c5 100644
--- a/neo/lib/live_debug.py
+++ b/neo/lib/live_debug.py
@@ -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):
diff --git a/neo/lib/pt.py b/neo/lib/pt.py
index f349be94..591bffd3 100644
--- a/neo/lib/pt.py
+++ b/neo/lib/pt.py
@@ -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):
diff --git a/neo/storage/handlers/replication.py b/neo/storage/handlers/replication.py
index 82574476..5a578323 100644
--- a/neo/storage/handlers/replication.py
+++ b/neo/storage/handlers/replication.py
@@ -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:
-            # Should probably raise & close connection...
-            result = None
-        return result
-    return decorator
+            return func(self, conn, *args, **kw)
+        # Should probably raise & close connection...
+    return wraps(func)(decorator)
 
 class ReplicationHandler(EventHandler):
     """This class handles events for replications."""
-- 
2.30.9