Python dbus 模块,String() 实例源码

我们从Python开源项目中,提取了以下22个代码示例,用于说明如何使用dbus.String()

项目:my-weather-indicator    作者:atareao    | 项目源码 | 文件源码
def unwrap(self, val):
        if isinstance(val, dbus.ByteArray):
            return "".join([str(x) for x in val])
        if isinstance(val, (dbus.Array, list, tuple)):
            return [self.unwrap(x) for x in val]
        if isinstance(val, (dbus.Dictionary, dict)):
            return dict([(self.unwrap(x), self.unwrap(y)) for x, y in val.items()])
        if isinstance(val, dbus.ObjectPath):
            if val.startswith('/org/freedesktop/NetworkManager/'):
                classname = val.split('/')[4]
                classname = {
                    'Settings': 'Connection',
                    'Devices': 'Device',
                }.get(classname, classname)
                return globals()[classname](val)
        if isinstance(val, (dbus.Signature, dbus.String)):
            return unicode(val)
        if isinstance(val, dbus.Boolean):
            return bool(val)
        if isinstance(val, (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64)):
            return int(val)
        if isinstance(val, dbus.Byte):
            return bytes([int(val)])
        return val
项目:DevOps    作者:YoLoveLife    | 项目源码 | 文件源码
def dict_to_string(self, d):
        # Try to trivially translate a dictionary's elements into nice string
        # formatting.
        dstr=""
        for key in d:
            val=d[key]
            str_val=""
            add_string=True
            if type(val)==type(dbus.Array([])):
                for elt in val:
                    if type(elt)==type(dbus.Byte(1)):
                        str_val+="%s " % int(elt)
                    elif type(elt)==type(dbus.String("")):
                        str_val+="%s" % elt
            elif type(val)==type(dbus.Dictionary({})):
                dstr+=self.dict_to_string(val)
                add_string=False
            else:
                str_val=val
            if add_string:
                dstr+="%s: %s\n" % ( key, str_val)
        return dstr
项目:genivi_swm    作者:GENIVI    | 项目源码 | 文件源码
def result(operation_id, code, text):
    """Encode a result

    This method encodes operation id, result code and result text into
    a dictionary of dbus types.

    @param operation_id Id of the operation for which the result is reported
    @param code Result code of the operation (one of SWMResult)
    @param text Text message

    @return Result dictionary using dbus types.
    """
    if not SWMResult.isValid(code):
        code = SWMResult.SWM_GENERAL_ERROR

    return {
        'id': dbus.String(operation_id, variant_level=1),
        'result_code': dbus.Int32(code, variant_level=1),
        'result_text': dbus.String(text, variant_level=1)
    }
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _return_credentials(self):
        c = dbus.Dictionary(
            {
              dbus.String(u'consumer_secret'): dbus.String(
                self._random_unicode_string(30)),
              dbus.String(u'token'): dbus.String(
                self._random_unicode_string(50)),
              dbus.String(u'consumer_key'): dbus.String(
                self._random_unicode_string(7)),
              dbus.String(u'name'): dbus.String('Ubuntu Software Center @ ' +
                self._random_unicode_string(6)),
              dbus.String(u'token_secret'): dbus.String(
                self._random_unicode_string(50))
             },
             signature=dbus.Signature('ss')
             )
        return c
项目:x-mario-center    作者:fossasia    | 项目源码 | 文件源码
def _return_credentials(self):
        c = dbus.Dictionary(
            {
              dbus.String(u'consumer_secret'): dbus.String(
                self._random_unicode_string(30)),
              dbus.String(u'token'): dbus.String(
                self._random_unicode_string(50)),
              dbus.String(u'consumer_key'): dbus.String(
                self._random_unicode_string(7)),
              dbus.String(u'name'): dbus.String('Ubuntu Software Center @ ' +
                self._random_unicode_string(6)),
              dbus.String(u'token_secret'): dbus.String(
                self._random_unicode_string(50))
             },
             signature=dbus.Signature('ss')
             )
        return c
项目:my-weather-indicator    作者:atareao    | 项目源码 | 文件源码
def convert(dbus_obj):
    """Converts dbus_obj from dbus type to python type.
    :param dbus_obj: dbus object.
    :returns: dbus_obj in python type.
    """
    _isinstance = partial(isinstance, dbus_obj)
    ConvertType = namedtuple('ConvertType', 'pytype dbustypes')

    pyint = ConvertType(int, (dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64,
                              dbus.UInt16, dbus.UInt32, dbus.UInt64))
    pybool = ConvertType(bool, (dbus.Boolean, ))
    pyfloat = ConvertType(float, (dbus.Double, ))
    pylist = ConvertType(lambda _obj: list(map(convert, dbus_obj)),
                         (dbus.Array, ))
    pytuple = ConvertType(lambda _obj: tuple(map(convert, dbus_obj)),
                          (dbus.Struct, ))
    types_str = (dbus.ObjectPath, dbus.Signature, dbus.String)
    pystr = ConvertType(str, types_str)

    pydict = ConvertType(
        lambda _obj: dict(list(zip(list(map(convert, dbus_obj.keys())),
                                   list(map(convert, dbus_obj.values()))
                                   ))
                          ),
        (dbus.Dictionary, )
    )

    for conv in (pyint, pybool, pyfloat, pylist, pytuple, pystr, pydict):
        if any(map(_isinstance, conv.dbustypes)):
            return conv.pytype(dbus_obj)
    else:
        return dbus_obj
项目:cpu-g    作者:atareao    | 项目源码 | 文件源码
def convert(dbus_obj):
    """Converts dbus_obj from dbus type to python type.
    :param dbus_obj: dbus object.
    :returns: dbus_obj in python type.
    """
    _isinstance = partial(isinstance, dbus_obj)
    ConvertType = namedtuple('ConvertType', 'pytype dbustypes')

    pyint = ConvertType(int, (dbus.Byte, dbus.Int16, dbus.Int32, dbus.Int64,
                              dbus.UInt16, dbus.UInt32, dbus.UInt64))
    pybool = ConvertType(bool, (dbus.Boolean, ))
    pyfloat = ConvertType(float, (dbus.Double, ))
    pylist = ConvertType(lambda _obj: list(map(convert, dbus_obj)),
                         (dbus.Array, ))
    pytuple = ConvertType(lambda _obj: tuple(map(convert, dbus_obj)),
                          (dbus.Struct, ))
    types_str = (dbus.ObjectPath, dbus.Signature, dbus.String)
    pystr = ConvertType(str, types_str)

    pydict = ConvertType(
        lambda _obj: dict(zip(map(convert, dbus_obj.keys()),
                              map(convert, dbus_obj.values())
                              )
                          ),
        (dbus.Dictionary, )
    )

    for conv in (pyint, pybool, pyfloat, pylist, pytuple, pystr, pydict):
        if any(map(_isinstance, conv.dbustypes)):
            return conv.pytype(dbus_obj)
    else:
        return dbus_obj
项目:python-eduvpn-client    作者:eduvpn    | 项目源码 | 文件源码
def base_to_python(val):
        if isinstance(val, dbus.ByteArray):
            return "".join([str(x) for x in val])
        if isinstance(val, (dbus.Array, list, tuple)):
            return [fixups.base_to_python(x) for x in val]
        if isinstance(val, (dbus.Dictionary, dict)):
            return dict([(fixups.base_to_python(x), fixups.base_to_python(y)) for x, y in val.items()])
        if isinstance(val, dbus.ObjectPath):
            for obj in (NetworkManager, Settings, AgentManager):
                if val == obj.object_path:
                    return obj
            if val.startswith('/org/freedesktop/NetworkManager/'):
                classname = val.split('/')[4]
                classname = {
                    'Settings': 'Connection',
                    'Devices': 'Device',
                }.get(classname, classname)
                try:
                    return globals()[classname](val)
                except ObjectVanished:
                    return None
            if val == '/':
                return None
        if isinstance(val, (dbus.Signature, dbus.String)):
            return six.text_type(val)
        if isinstance(val, dbus.Boolean):
            return bool(val)
        if isinstance(val, (dbus.Int16, dbus.UInt16, dbus.Int32, dbus.UInt32, dbus.Int64, dbus.UInt64)):
            return int(val)
        if isinstance(val, dbus.Byte):
            return six.int2byte(int(val))
        return val
项目:dbus-mqtt    作者:victronenergy    | 项目源码 | 文件源码
def test_dbus_wrap_string(self):
        value = 'text'
        dbus_value = dbus_mqtt.wrap_dbus_value(value)
        self.assertIsInstance(dbus_value, dbus.String)
        self.assertEqual(dbus.String(value, variant_level=1), dbus_value)
项目:dbus-mqtt    作者:victronenergy    | 项目源码 | 文件源码
def test_dbus_wrap_dict(self):
        value = {'a' : 3, 'b': 7.0}
        dbus_value = dbus_mqtt.wrap_dbus_value(value)
        print(dbus_value)
        self.assertIsInstance(dbus_value, dbus.Dictionary)
        self.assertEqual(dbus.Dictionary({
            dbus.String('a', variant_level=1): dbus.Int32(3, variant_level=1),
            dbus.String('b', variant_level=1): dbus.Double(7.0, variant_level=1)}, variant_level=1),
            dbus_value)
项目:dbus-mqtt    作者:victronenergy    | 项目源码 | 文件源码
def test_dbus_unwrap_string(self):
        dbus_value = dbus.String('abcd', variant_level=1)
        value = dbus_mqtt.unwrap_dbus_value(dbus_value)
        self.assertIsInstance(value, unicode)
        self.assertEqual(str(dbus_value), value)
项目:dbus-mqtt    作者:victronenergy    | 项目源码 | 文件源码
def test_dbus_unwrap_dict(self):
        dbus_value = dbus.Dictionary({
            dbus.String('a', variant_level=1): dbus.Double(3.2, variant_level=1),
            dbus.String('b', variant_level=1): dbus.Double(3.7, variant_level=1)},
            variant_level=1)
        value = dbus_mqtt.unwrap_dbus_value(dbus_value)
        self.assertIsInstance(value, dict)
        self.assertEqual({'a':3.2, 'b':3.7}, value)
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def get_debug_level(self):
        return self.__get_property(dbus.String("DebugLevel"))
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def set_debug_level(self, parameter):
        self.__set_property(dbus.String("DebugLevel"), dbus.String(parameter))
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def get_debug_timestamp(self):
        return self.__get_property(dbus.String("DebugTimestamp"))
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def set_debug_level(self, parameter):
        self.__set_property(dbus.String("DebugTimestamp"), dbus.Boolean(parameter))
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def get_debug_show_keys(self):
        return self.__get_property(dbus.String("DebugShowKeys"))
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def get_interfaces(self):
        return self.__get_property(dbus.String("Interfaces"))
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def get_EAP_methods(self):
        return self.__get_property(dbus.String("EapMethods"))
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def get_capabilities(self):
        return self.__get_property(dbus.String("Capabilities"))
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def get_WFDIEs(self):
        return self.__get_property(dbus.String("WFDIEs"))
项目:pywificontrol    作者:emlid    | 项目源码 | 文件源码
def set_WFDIEs(self, parameter):
        self.__set_property(dbus.String("WFDIEs"), dbus.Array(parameter, "y"))