From b44c05a7f071d91e743b4ffaba2c693b72ce721c Mon Sep 17 00:00:00 2001 From: Masaki Murooka Date: Wed, 16 Aug 2023 07:24:20 +0900 Subject: [PATCH] Improve string handling in Python bindings of ControllerClient. Co-authored-by: Pierre Gergondet --- binding/python/mc_control/mc_control.pyx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/binding/python/mc_control/mc_control.pyx b/binding/python/mc_control/mc_control.pyx index 0ff3421ed5..1469d11685 100644 --- a/binding/python/mc_control/mc_control.pyx +++ b/binding/python/mc_control/mc_control.pyx @@ -372,7 +372,9 @@ cdef class MCGlobalController(object): cdef class ElementId(object): def __cinit__(self, category, name): - self.impl = c_mc_control.ElementId(category, name) + if isinstance(name, unicode): + name = name.encode(u'ascii') + self.impl = c_mc_control.ElementId([s.encode(u'ascii') if isinstance(s, unicode) else s for s in category] , name) property category: def __get__(self): return self.impl.category @@ -382,6 +384,10 @@ cdef class ElementId(object): cdef class ControllerClient(object): def __cinit__(self, sub_conn_uri, push_conn_uri, timeout = 0.0): + if isinstance(sub_conn_uri, unicode): + sub_conn_uri = sub_conn_uri.encode(u'ascii') + if isinstance(push_conn_uri, unicode): + push_conn_uri = push_conn_uri.encode(u'ascii') self.impl = new c_mc_control.ControllerClient(sub_conn_uri, push_conn_uri, timeout) def send_request(self, element_id, data = None): if data is None: