[pytango] 82/122: Remove duplication of TO_TANGO_TYPE

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


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

sbodomerle-guest pushed a commit to tag v9.2.1
in repository pytango.

commit 5c6ec57d9519e53010f47cb1dbade9576b6e334a
Author: Vincent Michel <vincent.michel at maxlab.lu.se>
Date:   Mon Nov 14 15:41:49 2016 +0100

    Remove duplication of TO_TANGO_TYPE
---
 tango/server.py | 89 ++++++---------------------------------------------------
 tango/utils.py  | 36 +++++++++++------------
 2 files changed, 27 insertions(+), 98 deletions(-)

diff --git a/tango/server.py b/tango/server.py
index 13c0d6e..1e0a820 100644
--- a/tango/server.py
+++ b/tango/server.py
@@ -15,10 +15,6 @@ from __future__ import with_statement
 from __future__ import print_function
 from __future__ import absolute_import
 
-__all__ = ["DeviceMeta", "Device", "LatestDeviceImpl", "attribute",
-           "command", "pipe", "device_property", "class_property",
-           "run", "server_run", "Server", "get_worker", "get_async_worker"]
-
 import os
 import sys
 import copy
@@ -29,92 +25,25 @@ import weakref
 import functools
 import traceback
 
-from ._tango import (CmdArgType, AttrDataFormat, AttrWriteType,
-                       DevFailed, Except, GreenMode, constants,
-                       Database, DbDevInfo, DevState, CmdArgType,
-                       Attr, PipeWriteType)
+from ._tango import (AttrDataFormat, AttrWriteType,
+                     DevFailed, Except, GreenMode, constants,
+                     Database, DbDevInfo, DevState, CmdArgType,
+                     PipeWriteType)
 from .attr_data import AttrData
 from .pipe_data import PipeData
 from .device_class import DeviceClass
 from .utils import (get_latest_device_class, is_seq, is_non_str_seq,
-                    scalar_to_array_type)
+                    scalar_to_array_type, TO_TANGO_TYPE)
 from .codec import loads, dumps
 
+__all__ = ["DeviceMeta", "Device", "LatestDeviceImpl", "attribute",
+           "command", "pipe", "device_property", "class_property",
+           "run", "server_run", "Server", "get_worker", "get_async_worker"]
+
 API_VERSION = 2
 
 LatestDeviceImpl = get_latest_device_class()
 
-def __build_to_tango_type():
-    ret = \
-    {
-        int         : CmdArgType.DevLong64,
-        str         : CmdArgType.DevString,
-        bool        : CmdArgType.DevBoolean,
-        bytearray   : CmdArgType.DevEncoded,
-        float       : CmdArgType.DevDouble,
-        chr         : CmdArgType.DevUChar,
-        None        : CmdArgType.DevVoid,
-
-        'int'       : CmdArgType.DevLong64,
-        'int16'     : CmdArgType.DevShort,
-        'int32'     : CmdArgType.DevLong,
-        'int64'     : CmdArgType.DevLong64,
-        'uint'      : CmdArgType.DevULong64,
-        'uint16'    : CmdArgType.DevUShort,
-        'uint32'    : CmdArgType.DevULong,
-        'uint64'    : CmdArgType.DevULong64,
-        'str'       : CmdArgType.DevString,
-        'string'    : CmdArgType.DevString,
-        'text'      : CmdArgType.DevString,
-        'bool'      : CmdArgType.DevBoolean,
-        'boolean'   : CmdArgType.DevBoolean,
-        'bytes'     : CmdArgType.DevEncoded,
-        'bytearray' : CmdArgType.DevEncoded,
-        'float'     : CmdArgType.DevDouble,
-        'float32'   : CmdArgType.DevFloat,
-        'float64'   : CmdArgType.DevDouble,
-        'double'    : CmdArgType.DevDouble,
-        'byte'      : CmdArgType.DevUChar,
-        'chr'       : CmdArgType.DevUChar,
-        'char'      : CmdArgType.DevUChar,
-        'None'      : CmdArgType.DevVoid,
-        'state'     : CmdArgType.DevState,
-        'enum'      : CmdArgType.DevEnum,
-    }
-
-    try:
-        ret[long] = ret[int]
-    except NameError:
-        pass
-
-
-    for key in dir(CmdArgType):
-        if key.startswith("Dev"):
-            value = getattr(CmdArgType, key)
-            ret[key] = ret[value] = value
-
-    if constants.NUMPY_SUPPORT:
-        import numpy
-        FROM_TANGO_TO_NUMPY_TYPE = { \
-                   CmdArgType.DevBoolean : numpy.bool8,
-                     CmdArgType.DevUChar : numpy.ubyte,
-                     CmdArgType.DevShort : numpy.short,
-                    CmdArgType.DevUShort : numpy.ushort,
-                      CmdArgType.DevLong : numpy.int32,
-                     CmdArgType.DevULong : numpy.uint32,
-                    CmdArgType.DevLong64 : numpy.int64,
-                   CmdArgType.DevULong64 : numpy.uint64,
-                    CmdArgType.DevString : numpy.str,
-                    CmdArgType.DevDouble : numpy.float64,
-                     CmdArgType.DevFloat : numpy.float32,
-        }
-
-        for key, value in FROM_TANGO_TO_NUMPY_TYPE.items():
-            ret[value] = key
-    return ret
-
-TO_TANGO_TYPE = __build_to_tango_type()
-
 
 def _get_tango_type_format(dtype=None, dformat=None):
     if dformat is None:
diff --git a/tango/utils.py b/tango/utils.py
index 10b7b66..48e3e77 100644
--- a/tango/utils.py
+++ b/tango/utils.py
@@ -26,7 +26,8 @@ __all__ = [
     "document_method", "document_static_method", "document_enum",
     "CaselessList", "CaselessDict", "EventCallBack", "get_home",
     "from_version_str_to_hex_str", "from_version_str_to_int",
-    "seq_2_StdStringVector", "StdStringVector_2_seq" ]
+    "seq_2_StdStringVector", "StdStringVector_2_seq",
+    "TO_TANGO_TYPE"]
 
 __docformat__ = "restructuredtext"
 
@@ -78,9 +79,9 @@ _array_types = _array_numerical_types + _array_bool_types + _array_str_types + \
 
 _binary_types = (CmdArgType.DevEncoded, CmdArgType.DevVarCharArray)
 
+
 def __build_to_tango_type():
-    ret = \
-    {
+    ret = {
         int         : CmdArgType.DevLong64,
         str         : CmdArgType.DevString,
         bool        : CmdArgType.DevBoolean,
@@ -89,11 +90,11 @@ def __build_to_tango_type():
         chr         : CmdArgType.DevUChar,
         None        : CmdArgType.DevVoid,
 
-        'int'       : CmdArgType.DevLong,
+        'int'       : CmdArgType.DevLong64,
         'int16'     : CmdArgType.DevShort,
         'int32'     : CmdArgType.DevLong,
         'int64'     : CmdArgType.DevLong64,
-        'uint'      : CmdArgType.DevULong,
+        'uint'      : CmdArgType.DevULong64,
         'uint16'    : CmdArgType.DevUShort,
         'uint32'    : CmdArgType.DevULong,
         'uint64'    : CmdArgType.DevULong64,
@@ -122,7 +123,6 @@ def __build_to_tango_type():
     except NameError:
         pass
 
-
     for key in dir(CmdArgType):
         if key.startswith("Dev"):
             value = getattr(CmdArgType, key)
@@ -130,18 +130,18 @@ def __build_to_tango_type():
 
     if constants.NUMPY_SUPPORT:
         import numpy
-        FROM_TANGO_TO_NUMPY_TYPE = { \
-                   CmdArgType.DevBoolean : numpy.bool8,
-                     CmdArgType.DevUChar : numpy.ubyte,
-                     CmdArgType.DevShort : numpy.short,
-                    CmdArgType.DevUShort : numpy.ushort,
-                      CmdArgType.DevLong : numpy.int32,
-                     CmdArgType.DevULong : numpy.uint32,
-                    CmdArgType.DevLong64 : numpy.int64,
-                   CmdArgType.DevULong64 : numpy.uint64,
-                    CmdArgType.DevString : numpy.str,
-                    CmdArgType.DevDouble : numpy.float64,
-                     CmdArgType.DevFloat : numpy.float32,
+        FROM_TANGO_TO_NUMPY_TYPE = {
+            CmdArgType.DevBoolean: numpy.bool8,
+            CmdArgType.DevUChar: numpy.ubyte,
+            CmdArgType.DevShort: numpy.short,
+            CmdArgType.DevUShort: numpy.ushort,
+            CmdArgType.DevLong: numpy.int32,
+            CmdArgType.DevULong: numpy.uint32,
+            CmdArgType.DevLong64: numpy.int64,
+            CmdArgType.DevULong64: numpy.uint64,
+            CmdArgType.DevString: numpy.str,
+            CmdArgType.DevDouble: numpy.float64,
+            CmdArgType.DevFloat: numpy.float32,
         }
 
         for key, value in FROM_TANGO_TO_NUMPY_TYPE.items():

-- 
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