本文整理匯總了Python中dbus.ByteArray方法的典型用法代碼示例。如果您正苦於以下問題:Python dbus.ByteArray方法的具體用法?Python dbus.ByteArray怎麽用?Python dbus.ByteArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dbus
的用法示例。
在下文中一共展示了dbus.ByteArray方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: unwrap
# 需要導入模塊: import dbus [as 別名]
# 或者: from dbus import ByteArray [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
示例2: unwrap
# 需要導入模塊: import dbus [as 別名]
# 或者: from dbus import ByteArray [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
示例3: set_icon_from_pixbuf
# 需要導入模塊: import dbus [as 別名]
# 或者: from dbus import ByteArray [as 別名]
def set_icon_from_pixbuf(self, icon):
"""Set a custom icon from a GdkPixbuf.
"""
struct = (
icon.get_width(),
icon.get_height(),
icon.get_rowstride(),
icon.get_has_alpha(),
icon.get_bits_per_sample(),
icon.get_n_channels(),
dbus.ByteArray(icon.get_pixels())
)
self.hints['icon_data'] = struct
示例4: base_to_python
# 需要導入模塊: import dbus [as 別名]
# 或者: from dbus import ByteArray [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
示例5: addr_to_dbus
# 需要導入模塊: import dbus [as 別名]
# 或者: from dbus import ByteArray [as 別名]
def addr_to_dbus(addr,family):
if (family == socket.AF_INET):
return dbus.UInt32(struct.unpack('I', socket.inet_pton(family,addr))[0])
else:
return dbus.ByteArray(socket.inet_pton(family,addr))
示例6: wrap
# 需要導入模塊: import dbus [as 別名]
# 或者: from dbus import ByteArray [as 別名]
def wrap(self, val):
if isinstance(val, NMDbusInterface):
return val.object_path
if hasattr(val, 'mro'):
for klass in val.mro():
if klass.__module__ == '_dbus_bindings':
return val
if hasattr(val, '__iter__') and not isinstance(val, basestring):
if hasattr(val, 'items'):
return dict([(x, self.wrap(y)) for x, y in val.items()])
else:
if (isinstance(val, dbus.Struct) or isinstance(val, dbus.ByteArray)):
return val
return [self.wrap(x) for x in val]
return val
示例7: addr_to_dbus
# 需要導入模塊: import dbus [as 別名]
# 或者: from dbus import ByteArray [as 別名]
def addr_to_dbus(addr, family):
if (family == socket.AF_INET):
return dbus.UInt32(struct.unpack('I', socket.inet_pton(family, addr))[0])
else:
return dbus.ByteArray(socket.inet_pton(family, addr))
示例8: base_to_python
# 需要導入模塊: import dbus [as 別名]
# 或者: from dbus import ByteArray [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)
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
示例9: addr_to_dbus
# 需要導入模塊: import dbus [as 別名]
# 或者: from dbus import ByteArray [as 別名]
def addr_to_dbus(addr, family):
if family == socket.AF_INET:
return dbus.UInt32(struct.unpack('I', socket.inet_pton(family, addr))[0])
else:
return dbus.ByteArray(socket.inet_pton(family, addr))