[pytango] 123/483: changes for python 2.4

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:32 UTC 2017


This is an automated email from the git hooks/post-receive script.

sbodomerle-guest pushed a commit to annotated tag bliss_8.10
in repository pytango.

commit 19d09813cc7d53c1bff891d21863c07ca46bdb95
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Mon Jun 18 13:16:56 2012 +0000

    changes for python 2.4
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@20709 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 PyTango/log4tango.py |  6 +++---
 PyTango/utils.py     | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 58 insertions(+), 4 deletions(-)

diff --git a/PyTango/log4tango.py b/PyTango/log4tango.py
index e99e3df..26725ad 100644
--- a/PyTango/log4tango.py
+++ b/PyTango/log4tango.py
@@ -43,8 +43,8 @@ __all__ = [ "TangoStream", "LogIt", "DebugIt", "InfoIt", "WarnIt",
 
 __docformat__ = "restructuredtext"
 
-import functools
-
+from utils import wraps
+    
 class TangoStream:
     
     def __init__(self, fn):
@@ -122,7 +122,7 @@ class LogIt(object):
         return d.debug_stream
 
     def __call__(self, f):
-        @functools.wraps(f)
+        @wraps(f)
         def log_stream(*args, **kwargs):
             d = args[0]
             if not self.is_enabled(d):
diff --git a/PyTango/utils.py b/PyTango/utils.py
index 9736d0f..96be935 100644
--- a/PyTango/utils.py
+++ b/PyTango/utils.py
@@ -29,7 +29,8 @@ __all__ = [ "is_scalar_type", "is_array_type", "is_numerical_type",
             "is_int_type", "is_float_type", "obj_2_str", "seqStr_2_obj",
             "document_method", "document_static_method", "document_enum",
             "CaselessList", "CaselessDict", "EventCallBack", "get_home",
-            "from_version_str_to_hex_str", "from_version_str_to_int", ]
+            "from_version_str_to_hex_str", "from_version_str_to_int", 
+            "wraps", "update_wrapper"]
 
 __docformat__ = "restructuredtext"
 
@@ -39,6 +40,59 @@ import socket
 import types
 import operator
 
+try:
+    from functools import wraps, update_wrapper
+except ImportError:
+    # -------------------
+    # Python 2.4 fallback
+    # -------------------
+    def curry(_curried_func, *args, **kwargs):
+        def _curried(*moreargs, **morekwargs):
+            return _curried_func(*(args+moreargs), **dict(kwargs, **morekwargs))
+        return _curried
+    
+    WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
+    WRAPPER_UPDATES = ('__dict__',)
+    def update_wrapper(wrapper,
+                       wrapped,
+                       assigned = WRAPPER_ASSIGNMENTS,
+                       updated = WRAPPER_UPDATES):
+        """Update a wrapper function to look like the wrapped function
+
+           wrapper is the function to be updated
+           wrapped is the original function
+           assigned is a tuple naming the attributes assigned directly
+           from the wrapped function to the wrapper function (defaults to
+           functools.WRAPPER_ASSIGNMENTS)
+           updated is a tuple naming the attributes off the wrapper that
+           are updated with the corresponding attribute from the wrapped
+           function (defaults to functools.WRAPPER_UPDATES)
+        """
+        for attr in assigned:
+            try:
+                setattr(wrapper, attr, getattr(wrapped, attr))
+            except TypeError: # Python 2.3 doesn't allow assigning to __name__.
+                pass
+        for attr in updated:
+            getattr(wrapper, attr).update(getattr(wrapped, attr))
+        # Return the wrapper so this can be used as a decorator via curry()
+        return wrapper
+
+    def wraps(wrapped,
+          assigned = WRAPPER_ASSIGNMENTS,
+          updated = WRAPPER_UPDATES):
+        """Decorator factory to apply update_wrapper() to a wrapper function
+
+           Returns a decorator that invokes update_wrapper() with the decorated
+           function as the wrapper argument and the arguments to wraps() as the
+           remaining arguments. Default arguments are as for update_wrapper().
+           This is a convenience function to simplify applying curry() to
+           update_wrapper().
+        """
+        return curry(update_wrapper, wrapped=wrapped,
+                     assigned=assigned, updated=updated)
+
+
 from _PyTango import StdStringVector, StdDoubleVector
 from _PyTango import DbData, DbDevInfos, DbDevExportInfos, CmdArgType, AttrDataFormat
 from _PyTango import EventData, AttrConfEventData, DataReadyEventData

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-science/packages/pytango.git



More information about the debian-science-commits mailing list