[pytango] 310/483: fixes #615

Sandor Bodo-Merle sbodomerle-guest at moszumanska.debian.org
Thu Sep 28 19:14:54 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 06b432c253f879c3be355a6eaa8d5530938c9f11
Author: tiagocoutinho <tiagocoutinho at 4e9c00fd-8f2e-0410-aa12-93ce3db5e235>
Date:   Thu Nov 21 16:31:09 2013 +0000

    fixes #615
    
    git-svn-id: http://svn.code.sf.net/p/tango-cs/code/bindings/PyTango/trunk@24330 4e9c00fd-8f2e-0410-aa12-93ce3db5e235
---
 src/boost/cpp/device_data.cpp |  6 +++---
 src/boost/cpp/fast_from_py.h  | 13 ++++++++++---
 src/boost/python/server.py    | 18 +++++++++++++-----
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/src/boost/cpp/device_data.cpp b/src/boost/cpp/device_data.cpp
index 68f9e32..42eef88 100644
--- a/src/boost/cpp/device_data.cpp
+++ b/src/boost/cpp/device_data.cpp
@@ -33,9 +33,9 @@ namespace PyDeviceData {
         void insert_scalar(Tango::DeviceData &self, object py_value)
         {
             typedef typename TANGO_const2type(tangoTypeConst) TangoScalarType;
-            TangoScalarType val;
-            val = boost::python::extract<TangoScalarType>(py_value);
-            self << val;
+            TangoScalarType value;
+	    from_py<tangoTypeConst>::convert(py_value.ptr(), value);
+            self << value;
         }
         template <>
         void insert_scalar<Tango::DEV_ENCODED>(Tango::DeviceData &self, object py_value)
diff --git a/src/boost/cpp/fast_from_py.h b/src/boost/cpp/fast_from_py.h
index e0c6086..d7f70b1 100644
--- a/src/boost/cpp/fast_from_py.h
+++ b/src/boost/cpp/fast_from_py.h
@@ -91,6 +91,7 @@ struct from_py<tangoTypeConst> \
         { \
             cpy_type cpy_value = FN(o); \
             if(PyErr_Occurred()) { \
+	        PyErr_Clear(); \
                 PyErr_SetString(PyExc_TypeError, "Expecting a numeric type, it is not."); \
                 boost::python::throw_error_already_set();  \
             } \
@@ -123,18 +124,20 @@ struct from_py<tangoTypeConst> \
         { \
             cpy_type cpy_value = FN(o); \
             if(PyErr_Occurred()) { \
+	        PyErr_Clear(); \
                 if(PyArray_CheckScalar(o) && \
                 ( PyArray_DescrFromScalar(o) \
                     == PyArray_DescrFromType(TANGO_const2numpy(tangoTypeConst)))) \
                 { \
                     PyArray_ScalarAsCtype(o, reinterpret_cast<void*>(&tg)); \
                     return; \
-                } else \
+                } else { \
                     PyErr_SetString(PyExc_TypeError, "Expecting a numeric type," \
                         " but it is not. If you use a numpy type instead of" \
                         " python core types, then it must exactly match (ex:" \
-                        " numpy.int32 for PyTango.DevLong)"); \
+                        " numpy.int32 for PyTango.DevLong (1))"); \
                     boost::python::throw_error_already_set();  \
+		} \
             } \
             if (TangoScalarTypeLimits::is_integer) { \
                 if (cpy_value > (cpy_type)TangoScalarTypeLimits::max()) { \
@@ -151,6 +154,8 @@ struct from_py<tangoTypeConst> \
     };
 #endif // !DISABLE_PYTANGO_NUMPY
 
+
+
 DEFINE_FAST_TANGO_FROMPY_NUM(Tango::DEV_BOOLEAN, long, PyLong_AsLong)
 DEFINE_FAST_TANGO_FROMPY_NUM(Tango::DEV_UCHAR, unsigned long, PyLong_AsUnsignedLong)
 DEFINE_FAST_TANGO_FROMPY_NUM(Tango::DEV_SHORT, long, PyLong_AsLong)
@@ -190,6 +195,7 @@ struct array_element_from_py<Tango::DEVVAR_CHARARRAY>
     {
         long cpy_value = PyLong_AsLong(o);
         if(PyErr_Occurred()) {
+            PyErr_Clear();
             PyErr_SetString(PyExc_TypeError, "Expecting a numeric type,"
                 " but it is not");
             boost::python::throw_error_already_set(); 
@@ -211,6 +217,7 @@ struct array_element_from_py<Tango::DEVVAR_CHARARRAY>
     {
         long cpy_value = PyLong_AsLong(o);
         if(PyErr_Occurred()) {
+	    PyErr_Clear();
             if(PyArray_CheckScalar(o) &&
             ( PyArray_DescrFromScalar(o)
                 == PyArray_DescrFromType(TANGO_const2scalarnumpy(tangoArrayTypeConst))))
@@ -221,7 +228,7 @@ struct array_element_from_py<Tango::DEVVAR_CHARARRAY>
                 PyErr_SetString(PyExc_TypeError, "Expecting a numeric type,"
                     " but it is not. If you use a numpy type instead of"
                     " python core types, then it must exactly match (ex:"
-                    " numpy.int32 for PyTango.DevLong)");
+                    " numpy.int32 for PyTango.DevLong (2))");
                 boost::python::throw_error_already_set();
             }
         }
diff --git a/src/boost/python/server.py b/src/boost/python/server.py
index 508f331..ca7130a 100644
--- a/src/boost/python/server.py
+++ b/src/boost/python/server.py
@@ -17,7 +17,8 @@
 
 When declaring attributes, properties or commands, one of the most important
 information is the data type. It is given by the keyword argument *dtype*.
-This argument is not retricted to the :obj:`~PyTango.CmdArgType` options.
+In order to provide a more *pythonic* interface, this argument is not retricted
+to the :obj:`~PyTango.CmdArgType` options.
 
 For example, to define a *SCALAR* :obj:`~PyTango.CmdArgType.DevLong`
 attribute you have several possibilities:
@@ -33,14 +34,16 @@ attribute you have several possibilities:
 To define a *SPECTRUM* attribute simply wrap the scalar data type in any
 python sequence:
 
-* (:obj:`int`,)
-* [:obj:`int`]
+* using a *tuple*: ``(:obj:`int`,)`` or
+* using a *list*: ``[:obj:`int`]`` or
+* any other sequence type
 
 To define an *IMAGE* attribute simply wrap the scalar data type in any
 python sequence of sequences:
 
-* ((:obj:`int`,),)
-* [[:obj:`int`]]
+* using a *tuple*: ``((:obj:`int`,),)`` or
+* using a *list*: ``[[:obj:`int`]]`` or
+* any other sequence type
 
 Below is the complete table of equivalences.
 
@@ -461,6 +464,11 @@ class Device(LatestDeviceImpl):
         """Tango always_executed_hook. Default implementation does nothing"""
         pass
 
+    def initialize_dynamic_attributes(self):
+        """Method executed at initializion phase to create dynamic attributes.
+        Default implementation does nothing. Overwrite when necessary."""
+        pass
+
 
 class attribute(AttrData):
     """declares a new tango attribute in a :class:`Device`. To be used like

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