diff options
author | tiagocoutinho <tiagocoutinho@users.sourceforge.net> | 2012-12-11 13:43:37 +0000 |
---|---|---|
committer | tiagocoutinho <tiagocoutinho@users.sourceforge.net> | 2012-12-11 13:43:37 +0000 |
commit | f3e68213433cbca30371ca6950458dc52e1f5863 (patch) | |
tree | 7a9a6fee1231c63b337c9f5b6de385810b1bb8ce /src | |
parent | 934be9d64314f202a1b15ec5074738d5aae95cca (diff) |
made compatible with taurus 3.0.0
git-svn-id: file:///home/cpascual/src/sdnongit/svnbck/sardana/trunk@21029 c480fdf4-a248-4bb0-8e4a-34cd1ef68f4f
Diffstat (limited to 'src')
-rw-r--r-- | src/sardana/macroserver/macro.py | 3 | ||||
-rw-r--r-- | src/sardana/tango/core/util.py | 2 | ||||
-rw-r--r-- | src/sardana/tango/macroserver/MacroServer.py | 2 | ||||
-rw-r--r-- | src/sardana/util/wrap.py | 64 |
4 files changed, 67 insertions, 4 deletions
diff --git a/src/sardana/macroserver/macro.py b/src/sardana/macroserver/macro.py index 48dae154..1db2b99f 100644 --- a/src/sardana/macroserver/macro.py +++ b/src/sardana/macroserver/macro.py @@ -46,14 +46,13 @@ import StringIO import ctypes from taurus.core.util import Logger, propertx -from taurus.core.util.wrap import wraps from taurus.console.table import Table from taurus.console.list import List from taurus.core.tango.sardana.pool import PoolElement from sardana.sardanadefs import State - +from sardana.util.wrap import wraps from msparameter import Type, ParamType, ParamRepeat from msexception import StopException, AbortException, \ MacroWrongParameterType, UnknownEnv, UnknownMacro diff --git a/src/sardana/tango/core/util.py b/src/sardana/tango/core/util.py index 939c3711..6bda8b82 100644 --- a/src/sardana/tango/core/util.py +++ b/src/sardana/tango/core/util.py @@ -57,13 +57,13 @@ from PyTango import Util, Database, WAttribute, DbDevInfo, DevFailed, \ import taurus from taurus.core.util.log import Logger -from taurus.core.util.wrap import wraps import sardana from sardana import State, SardanaServer, DataType, DataFormat, InvalidId, \ DataAccess, to_dtype_dformat, to_daccess, Release, ServerRunMode from sardana.sardanaexception import SardanaException from sardana.sardanavalue import SardanaValue +from sardana.util.wrap import wraps from sardana.pool.poolmetacontroller import DataInfo diff --git a/src/sardana/tango/macroserver/MacroServer.py b/src/sardana/tango/macroserver/MacroServer.py index 704780eb..4d8b9748 100644 --- a/src/sardana/tango/macroserver/MacroServer.py +++ b/src/sardana/tango/macroserver/MacroServer.py @@ -347,7 +347,7 @@ class MacroServerClass(SardanaDeviceClass): [10] ], 'EnvironmentDb': [DevString, - "The environment database (usualy a plain file).", + "The environment database (usually a plain file).", os.path.join(DefaultEnvBaseDir, DefaultEnvRelDir) ], 'RConsolePort': [DevLong, diff --git a/src/sardana/util/wrap.py b/src/sardana/util/wrap.py new file mode 100644 index 00000000..1ef099bb --- /dev/null +++ b/src/sardana/util/wrap.py @@ -0,0 +1,64 @@ +#!/usr/bin/env python + +############################################################################# +## +## This file is part of Taurus, a Tango User Interface Library +## +## http://www.tango-controls.org/static/taurus/latest/doc/html/index.html +## +## Copyright 2011 CELLS / ALBA Synchrotron, Bellaterra, Spain +## +## Taurus is free software: you can redistribute it and/or modify +## it under the terms of the GNU Lesser General Public License as published by +## the Free Software Foundation, either version 3 of the License, or +## (at your option) any later version. +## +## Taurus is distributed in the hope that it will be useful, +## but WITHOUT ANY WARRANTY; without even the implied warranty of +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +## GNU Lesser General Public License for more details. +## +## You should have received a copy of the GNU Lesser General Public License +## along with Taurus. If not, see <http://www.gnu.org/licenses/>. +## +############################################################################# + +"""""" + +__all__ = ["wraps", "wrapped", "is_wrapping", "is_wrapped"] + +import weakref +from functools import wraps as _wraps + +__WRAPPED = "__wrapped__" +__WRAPPER = "__wrapper__" + +def wraps(wrapped, *args, **kwargs): + """A wrap decorator which stores in the returned function a reference to + the wrapped function (in member '__wrapped__')""" + wrapper = _wraps(wrapped, *args, **kwargs) + setattr(wrapper, __WRAPPED, weakref.ref(wrapped)) + setattr(wrapped, __WRAPPER, weakref.ref(wrapper)) + return wrapper + +def is_wrapping(wrapper): + """Determines if the given callable is a wrapper for another callable""" + return hasattr(wrapper, __WRAPPED) + +def is_wrapped(wrapped): + """Determines if the given callable is being wrapped by another callable""" + return hasattr(wrapped, __WRAPPER) + +def wrapped(wrapper, recursive=True): + """Returns the wrapped function around the given wrapper. If the given + callable is not "wrapping" any function, the wrapper itself is returned""" + if is_wrapping(wrapper): + _wrapped = wrapper.__wrapped__() + else: + return wrapper + + if recursive: + return wrapped(_wrapped) + return _wrapped + +
\ No newline at end of file |