本文整理汇总了Python中dbus.Array方法的典型用法代码示例。如果您正苦于以下问题:Python dbus.Array方法的具体用法?Python dbus.Array怎么用?Python dbus.Array使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dbus
的用法示例。
在下文中一共展示了dbus.Array方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _connect
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def _connect(self, signals):
self.bus = self._get_bus()
self.core = self.bus.get_object(object_path='/org/pulseaudio/core1')
for sig_name, interface, sig_handler in signals:
self.bus.add_signal_receiver(sig_handler, sig_name)
self.core.ListenForSignal(
interface.format(sig_name), dbus.Array(signature='o'))
try:
fallback_sink_path = self.core.Get(
'org.PulseAudio.Core1', 'FallbackSink',
dbus_interface='org.freedesktop.DBus.Properties')
self.fallback_sink = PulseSinkFactory.new(
self.bus, fallback_sink_path)
except:
logger.info(
'Could not get default sink. Perhaps there is no one set?')
system_sink_paths = self.core.Get(
'org.PulseAudio.Core1', 'Sinks',
dbus_interface='org.freedesktop.DBus.Properties')
for sink_path in system_sink_paths:
sink = PulseSinkFactory.new(self.bus, sink_path)
if sink:
self.system_sinks.append(sink)
示例2: test_all
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def test_all(self):
val = [1, 2, 3, 4, 5]
self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Array, val), # noqa
dbus.Array(val))
val = -1
self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Int32, val), # noqa
dbus.Int32(val))
val = 1
self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.UInt32, val), # noqa
dbus.UInt32(val))
val = 'Test'
self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.String, val), # noqa
dbus.String(val))
val = {'Hello': 1}
self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Dictionary, # noqa
val),
dbus.Dictionary(val))
val = 'True'
self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Boolean, val), # noqa
dbus.Boolean(True))
val = 'False'
self.assertEqual(bt_manager.interface.translate_to_dbus_type(dbus.Boolean, val), # noqa
dbus.Boolean(False))
示例3: test_sbc_caps_conversion
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def test_sbc_caps_conversion(self, patched_system_bus):
mock_system_bus = mock.MagicMock()
patched_system_bus.return_value = mock_system_bus
mock_system_bus.get_object.return_value = dbus.ObjectPath('/org/bluez')
media = bt_manager.SBCAudioCodec(uuid='uuid', path='/endpoint/test')
config = bt_manager.SBCCodecConfig(bt_manager.SBCChannelMode.ALL,
bt_manager.SBCSamplingFrequency.ALL,
bt_manager.SBCAllocationMethod.ALL,
bt_manager.SBCSubbands.ALL,
bt_manager.SBCBlocks.ALL,
2,
64)
dbus_config = media._make_config(config)
self.assertEqual(dbus_config, dbus.Array([dbus.Byte(0xFF),
dbus.Byte(0xFF),
dbus.Byte(2),
dbus.Byte(64)]))
self.assertEqual(media._parse_config(dbus_config), config)
示例4: dict_to_string
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
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 isinstance(val, dbus.Array):
for elt in val:
if isinstance(elt, dbus.Byte):
str_val += "%s " % int(elt)
elif isinstance(elt, dbus.String):
str_val += "%s" % elt
elif isinstance(val, 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
示例5: unwrap
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def unwrap(val):
if isinstance(val, dbus.ByteArray):
return "".join([str(x) for x in val])
if isinstance(val, (dbus.Array, list, tuple)):
return [unwrap(x) for x in val]
if isinstance(val, (dbus.Dictionary, dict)):
return dict([(unwrap(x), unwrap(y)) for x, y in val.items()])
if isinstance(val, (dbus.Signature, dbus.String)):
return str(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
示例6: read_raw_value
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def read_raw_value(self, flags=''):
"""
Return this characteristic's value (if allowed).
:param flags: "offset": Start offset
"device": Device path (Server only)
:return:
Possible Errors: org.bluez.Error.Failed
org.bluez.Error.InProgress
org.bluez.Error.NotPermitted
org.bluez.Error.InvalidValueLength
org.bluez.Error.NotAuthorized
org.bluez.Error.NotSupported
"""
return self.characteristic_methods.ReadValue(dbus.Array())
示例7: get_properties
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def get_properties(self):
"""Return a dictionary of the service properties.
The dictionary has the following keys:
- UUID: the service UUID
- Primary: whether the service is the primary service
- Characteristics: D-Bus array of the characteristic object paths
associated with the service.
"""
return {
constants.GATT_SERVICE_IFACE: {
'UUID': self.uuid,
'Primary': self.primary,
'Characteristics': dbus.Array(
self.get_characteristic_paths(),
signature='o')
}
}
示例8: Set
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def Set(self, interface_name, property_name, value, *args, **kwargs):
"""Standard D-Bus API for setting a property value"""
try:
iface_props = self.props[interface_name]
except KeyError:
raise dbus.exceptions.DBusException(
'no such interface ' + interface_name,
name=self.interface + '.UnknownInterface')
if property_name not in iface_props:
raise dbus.exceptions.DBusException(
'no such property ' + property_name,
name=self.interface + '.UnknownProperty')
iface_props[property_name] = value
self.PropertiesChanged(interface_name,
dbus.Dictionary({property_name: value},
signature='sv'),
dbus.Array([], signature='s'))
示例9: unwrap
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
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
示例10: response
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def response(self, msg):
if isDebugAll() is True:
BLINKER_LOG('FFE1 Write: ' + str(msg))
msg = json.dumps(msg)
msg = msg + '\n'
length = len(msg)
a = []
b = []
for i in range(0, length):
a.append(dbus.Byte(ord(msg[i])))
b.append(msg[i])
# if isDebugAll() is True:
# BLINKER_LOG(len(msg))
# BLINKER_LOG(a)
# BLINKER_LOG(b)
msg = dbus.Array(a, signature=dbus.Signature('y'))
bleProto.BLE_Response.PropertiesChanged(GATT_CHRC_IFACE, { 'Value': msg }, [])
# if isDebugAll() is True:
# BLINKER_LOG('FFE1 Write: ' + str(msg))
示例11: test_one
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def test_one(self):
log.debug("")
manager = DeviceManagerMock("hci0")
obj = CustomDevice("AA", manager)
def callback(handle, value):
log.debug("%s: %s", type(value), str2hex(value))
if sys.version_info[0] == 2:
self.assertEquals("0f0004020126000000001000000010", str2hex(value))
obj.set_notific_handler(callback)
arr = "dbus.Array([dbus.Byte(15), dbus.Byte(0), dbus.Byte(4), dbus.Byte(2), dbus.Byte(1), dbus.Byte(38), " \
"dbus.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(0), dbus.Byte(16), dbus.Byte(0), dbus.Byte(0), " \
"dbus.Byte(0), dbus.Byte(16)], signature=dbus.Signature('y'), variant_level=1)"
obj.characteristic_value_updated(None, arr if sys.version_info[0] == 2 else bytes(arr, 'ascii'))
示例12: set_WFDIEs
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def set_WFDIEs(self, parameter):
self.__set_property(dbus.String("WFDIEs"), dbus.Array(parameter, "y"))
示例13: base_to_python
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
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)
return globals()[classname](val)
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
示例14: get_properties
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def get_properties(self):
properties = dict()
properties["Type"] = self.ad_type
if self.local_name is not None:
properties["LocalName"] = dbus.String(self.local_name)
if self.service_uuids is not None:
properties["ServiceUUIDs"] = dbus.Array(self.service_uuids,
signature='s')
if self.solicit_uuids is not None:
properties["SolicitUUIDs"] = dbus.Array(self.solicit_uuids,
signature='s')
if self.manufacturer_data is not None:
properties["ManufacturerData"] = dbus.Dictionary(
self.manufacturer_data, signature='qv')
if self.service_data is not None:
properties["ServiceData"] = dbus.Dictionary(self.service_data,
signature='sv')
if self.include_tx_power is not None:
properties["IncludeTxPower"] = dbus.Boolean(self.include_tx_power)
if self.local_name is not None:
properties["LocalName"] = dbus.String(self.local_name)
return {LE_ADVERTISEMENT_IFACE: properties}
示例15: add_manufacturer_data
# 需要导入模块: import dbus [as 别名]
# 或者: from dbus import Array [as 别名]
def add_manufacturer_data(self, manuf_code, data):
if not self.manufacturer_data:
self.manufacturer_data = dbus.Dictionary({}, signature="qv")
self.manufacturer_data[manuf_code] = dbus.Array(data, signature="y")