def AddAdapter(self, device_name, system_name): '''Convenience method to add a Bluetooth adapter You have to specify a device name which must be a valid part of an object path, e. g. "hci0", and an arbitrary system name (pretty hostname). Returns the new object path. ''' path = '/org/bluez/' + device_name adapter_properties = { 'UUIDs': dbus.Array([ '00001000-0000-1000-8000-00805f9b34fb', '00001001-0000-1000-8000-00805f9b34fb', '0000112d-0000-1000-8000-00805f9b34fb', '00001112-0000-1000-8000-00805f9b34fb', '0000111f-0000-1000-8000-00805f9b34fb', '0000111e-0000-1000-8000-00805f9b34fb', '0000110c-0000-1000-8000-00805f9b34fb', '0000110e-0000-1000-8000-00805f9b34fb', '0000110a-0000-1000-8000-00805f9b34fb', '0000110b-0000-1000-8000-00805f9b34fb', ], variant_level=1), 'Discoverable': dbus.Boolean(False, variant_level=1), 'Discovering': dbus.Boolean(False, variant_level=1), 'Pairable': dbus.Boolean(True, variant_level=1), 'Powered': dbus.Boolean(True, variant_level=1), 'Address': dbus.String('00:01:02:03:04:05', variant_level=1), 'Alias': dbus.String(system_name, variant_level=1), 'Name': dbus.String(system_name, variant_level=1), # Reference: # http://bluetooth-pentest.narod.ru/software/ # bluetooth_class_of_device-service_generator.html 'Class': dbus.UInt32(268, variant_level=1), # Computer, Laptop } self.AddObject( path, ADAPTER_IFACE, # Properties adapter_properties, # Methods [ ('GetProperties', '', 'a{sv}', 'ret = self.GetAll("org.bluez.Adapter")'), ('SetProperty', 'sv', '', 'self.Set("org.bluez.Adapter", args[0], args[1]); ' 'self.EmitSignal("org.bluez.Adapter", "PropertyChanged",' ' "sv", [args[0], args[1]])'), ]) manager = mockobject.objects['/'] manager.props[MANAGER_IFACE]['Adapters'] \ = [dbus.ObjectPath(path, variant_level=1)] manager.EmitSignal(OBJECT_MANAGER_IFACE, 'InterfacesAdded', 'oa{sa{sv}}', [ dbus.ObjectPath(path, variant_level=1), { ADAPTER_IFACE: adapter_properties }, ]) manager.EmitSignal(MANAGER_IFACE, 'AdapterAdded', 'o', [dbus.ObjectPath(path, variant_level=1)]) manager.EmitSignal(MANAGER_IFACE, 'DefaultAdapterChanged', 'o', [dbus.ObjectPath(path, variant_level=1)]) manager.EmitSignal(MANAGER_IFACE, 'PropertyChanged', 'sv', [ "Adapters", dbus.Array([ dbus.ObjectPath(path, variant_level=1), ], variant_level=1), ]) return path
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")
def buffer_input(number, buffer, message): signal = getSignal() if signal is not None: signal.sendMessage(message, dbus.Array(signature="s"), number) show_msg(number, "", message, False) return weechat.WEECHAT_RC_OK
def test(q, bus, mc): params = dbus.Dictionary( { "account": "*****@*****.**", "password": "******" }, signature='sv') simulated_cm, account = create_fakecm_account(q, bus, mc, params) conn = enable_fakecm_account(q, bus, mc, account, params) text_fixed_properties = dbus.Dictionary( { cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT, cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT, }, signature='sv') # subscribe to the OperationList interface (MC assumes that until this # property has been retrieved once, nobody cares) cd = bus.get_object(cs.CD, cs.CD_PATH) cd_props = dbus.Interface(cd, cs.PROPERTIES_IFACE) assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == [] client = SimulatedClient(q, bus, 'Client', observe=[text_fixed_properties], approve=[text_fixed_properties], handle=[], bypass_approval=False) # wait for MC to download the properties expect_client_setup(q, [client]) channel_properties = dbus.Dictionary(text_fixed_properties, signature='sv') channel_properties[cs.CHANNEL + '.TargetID'] = 'juliet' channel_properties[cs.CHANNEL + '.TargetHandle'] = \ conn.ensure_handle(cs.HT_CONTACT, 'juliet') channel_properties[cs.CHANNEL + '.InitiatorID'] = 'juliet' channel_properties[cs.CHANNEL + '.InitiatorHandle'] = \ conn.ensure_handle(cs.HT_CONTACT, 'juliet') channel_properties[cs.CHANNEL + '.Requested'] = False channel_properties[cs.CHANNEL + '.Interfaces'] = dbus.Array(signature='s') forbidden = [ EventPattern('dbus-method-call', method='AddDispatchOperation'), ] q.forbid_events(forbidden) chan = SimulatedChannel(conn, channel_properties) chan.announce() e = q.expect('dbus-signal', path=cs.CD_PATH, interface=cs.CD_IFACE_OP_LIST, signal='NewDispatchOperation') cdo_path = e.args[0] cdo_properties = e.args[1] assert cdo_properties[cs.CDO + '.Account'] == account.object_path assert cdo_properties[cs.CDO + '.Connection'] == conn.object_path assert cs.CDO + '.Interfaces' in cdo_properties handlers = cdo_properties[cs.CDO + '.PossibleHandlers'][:] assertEquals([], handlers) e = q.expect('dbus-method-call', path=client.object_path, interface=cs.OBSERVER, method='ObserveChannels', handled=False) sync_dbus(bus, q, mc) q.dbus_return(e.message, signature='') # now (but only now) MC kills the channel q.expect_many( EventPattern('dbus-signal', path=cdo_path, signal='Finished'), EventPattern('dbus-method-call', path=chan.object_path, method='Close', handled=True), ) # There are no active channel dispatch operations assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == []
def get_properties(self, ids=None, property_names=None): property_names = property_names or None ans = dbus.Array(signature='(ia{sv})') for action_id in (ids or self._id_to_action): ans.append((action_id, self.action_properties(action_id, property_names))) return ans
def py2_dbus_array(self, prop): return dbus.Array(prop, signature = dbus.Signature('s'))
def modify_connection(params, nm=NetworkManager()): types = { 'wired': '802-3-ethernet', 'wireless': '802-11-wireless', 'cdma': 'cdma', } type2desc = {1: '802-3-ethernet', 2: '802-11-wireless'} #uuid = params['nm.uuid'] #conn = None #if uuid != "": # conn = nm.get_connection(uuid) #if conn == None: conn_list = [] for conn in nm.connections: for interface in nm.devices: if str(conn.settings.mac_address) == str(interface.hwaddress): dev_state = interface.proxy.Get(NM_DEVICE, "State") dev_type_int = interface.proxy.Get(NM_DEVICE, "DeviceType") dev_type = type2desc.get(dev_type_int, None) conn_list.append((conn, dev_type, int(dev_state))) break try: xbmc.log("conn_list: " + str(conn_list)) except: syslog.syslog("conn_list: " + str(conn_list)) active_conn_list = [] for a in conn_list: if a[2] >= 20: # http://projects.gnome.org/NetworkManager/developers/api/09/spec.html#type-NM_DEVICE_STATE # any states other than NM_DEVICE_STATE_UNKNOWN # NM_DEVICE_STATE_UNMANAGED active_conn_list.append(a) #for b in active_conn_list: # conn = b[0] # if b[1] == type2desc[1]: # Wired Network # break #if conn == None: # for c in conn_list: # conn = c[0] # if c[1] == type2desc[1]: # Wired Networ # break RETURN_CODE = -11 if len(active_conn_list) > 0: for a in active_conn_list: conn = a[0] settings = conn.settings old_settings = str(settings._settings) if a[1] == type2desc[1]: # Wired Network if params['nm.dhcp'] == "false": address = params['nm.address'] netmask = params['nm.netmask'] gateway = params['nm.gateway'] dns = params['nm.dns'] dns_search = params['nm.search'] if a[1] == type2desc[2]: # Wireless Network if params['nm.wifi.dhcp'] == "false": address = params['nm.wifi.address'] netmask = params['nm.wifi.netmask'] gateway = params['nm.wifi.gateway'] dns = params['nm.wifi.dns'] dns_search = params['nm.wifi.search'] # 802-11-wireless if params["nm.wifi.5GOnly"] == "true": # 5GHz 802.11a band = "a" else: # 2.4GHz 802.11 band = "bg" ## WiFi network mode if params["nm.wifi.adhoc"] == "true": mode = "adhoc" else: mode = "infrastructure" security = "802-11-wireless-security" key_mgmt = "none" # None if params["nm.wifi.security"] == "0": security = "" # WEP (Open Key) if params["nm.wifi.security"] == "1": key_mgmt = "none" auth_alg = "open" # WEP (Shared Key) if params["nm.wifi.security"] == "2": key_mgmt = "none" auth_alg = "shared" # Dynamic WEP if params["nm.wifi.security"] == "3": key_mgmt = "ieee8021x" # WPA/WPA2 if params["nm.wifi.security"] == "4": if mode == "adhoc": key_mgmt = "wpa-none" else: key_mgmt = "wpa-psk" if "802-11-wireless" in settings._settings: try: xbmc.log(a[1] + " 802-11-wireless old: " + str(settings._settings['802-11-wireless'])) except: syslog.syslog( a[1] + " 802-11-wireless old: " + str(settings._settings['802-11-wireless'])) else: settings._settings['802-11-wireless'] = dbus.Dictionary( signature='sv') # clear 802-11-wireless settings # settings._settings['802-11-wireless'] = dbus.Dictionary(signature='sv') settings._settings['802-11-wireless'][ 'security'] = dbus.String(security) settings._settings['802-11-wireless']['mode'] = dbus.String( mode) settings._settings['802-11-wireless']['band'] = dbus.String( band) SSID = [] for c in params["nm.wifi.ssid"]: SSID.append(dbus.Byte(int(ord(c)))) settings._settings['802-11-wireless']['ssid'] = dbus.Array( SSID, signature='y') if "802-11-wireless-security" in settings._settings: try: xbmc.log(a[1] + " 802-11-wireless-security old: " + str(settings. _settings['802-11-wireless-security'])) except: syslog.syslog( a[1] + " 802-11-wireless-security old: " + str(settings._settings['802-11-wireless-security']) ) else: if key_mgmt != "": settings._settings[ '802-11-wireless-security'] = dbus.Dictionary( signature='sv') # clear 802-11-wireless-security settings # settings._settings['802-11-wireless-security'] = dbus.Dictionary(signature='sv') if key_mgmt == "" and "802-11-wireless-security" in settings._settings: del (settings._settings['802-11-wireless-security']) CONFIG_DIFFERENCE = True if key_mgmt != "": settings._settings['802-11-wireless-security'][ 'security'] = dbus.String(security) settings._settings['802-11-wireless-security'][ 'key-mgmt'] = dbus.String(key_mgmt) if key_mgmt == "none": settings._settings['802-11-wireless-security'][ 'auth-alg'] = dbus.String(auth_alg) if len(params["nm.wifi.key"]) > 0: settings._settings['802-11-wireless-security'][ 'wep-key0'] = dbus.String(params["nm.wifi.key"]) settings._settings['802-11-wireless-security'][ 'wep-key1'] = dbus.String(params["nm.wifi.key"]) else: if len(params["nm.wifi.key"]) > 0: settings._settings['802-11-wireless-security'][ 'psk'] = dbus.String(params["nm.wifi.key"]) if not "ipv6" in settings._settings: settings._settings['ipv6'] = dbus.Dictionary(signature='sv') settings._settings['ipv6']['method'] = dbus.String("ignore") if "ipv4" in settings._settings: try: xbmc.log(a[1] + " ipv4 old: " + str(settings._settings['ipv4'])) except: syslog.syslog(a[1] + " ipv4 old: " + str(settings._settings['ipv4'])) else: settings._settings['ipv4'] = dbus.Dictionary(signature='sv') DHCP = False if a[1] == type2desc[1] and params['nm.dhcp'] == "true": DHCP = True if a[1] == type2desc[2] and params['nm.wifi.dhcp'] == "true": DHCP = True if DHCP: settings.set_auto() if params['nm.uid.enable'] == "true": mac_list = settings.mac_address.split(":") uid = "xbmc-" + mac_list[4].lower() + mac_list[5].lower() else: uid = "xbmc" settings._settings['ipv4']['dhcp-client-id'] = dbus.String(uid) settings._settings['ipv4']['dhcp-hostname'] = dbus.String(uid) settings._settings['ipv4'][ 'dhcp-send-hostname'] = dbus.Boolean(1) else: if not 'addresses' in settings._settings['ipv4']: settings._settings['ipv4']['addresses'] = dbus.Array( [], signature='au') settings.address = address settings.netmask = netmask settings.gateway = gateway settings.dns = dns settings._settings['ipv4']['dns-search'] = dbus.Array( [dns_search], signature='s') #conn.proxy.Update(settings._settings, dbus_interface=NM_SETTINGS_CONNECTION) if old_settings != str(settings._settings): try: xbmc.log(str(settings.type)) if "ipv4" in settings._settings: xbmc.log(a[1] + "ipv4 new: " + str(settings._settings['ipv4'])) if "802-11-wireless" in settings._settings: xbmc.log(a[1] + "802-11-wireless: " + str(settings._settings['802-11-wireless'])) if "802-11-wireless-security" in settings._settings: xbmc.log(a[1] + "802-11-wireless-security: " + str( settings._settings['802-11-wireless-security'])) except: syslog.syslog(str(settings.type)) if "ipv4" in settings._settings: syslog.syslog(a[1] + "ipv4 new: " + str(settings._settings['ipv4'])) if "802-11-wireless" in settings._settings: syslog.syslog( a[1] + "802-11-wireless new: " + str(settings._settings['802-11-wireless'])) if "802-11-wireless-security" in settings._settings: syslog.syslog( a[1] + "802-11-wireless-security new: " + str(settings._settings['802-11-wireless-security']) ) conn.update(settings) # return 10 if settings need to update RETURN_CODE = 10 else: # return 0 if settings do not need to update RETURN_CODE = 0 return RETURN_CODE
def ip_to_int(ip_string): return struct.unpack("=I", socket.inet_aton(ip_string))[0] # full duplex s_wired = dbus.Dictionary({"duplex": "full"}) s_con = dbus.Dictionary({ "type": "802-3-ethernet", "uuid": str(uuid.uuid4()), "id": "MyConnectionExample" }) addr1 = dbus.Array( [ip_to_int("10.1.2.3"), dbus.UInt32(8), ip_to_int("10.1.2.1")], signature=dbus.Signature("u"), ) s_ip4 = dbus.Dictionary({ "addresses": dbus.Array([addr1], signature=dbus.Signature("au")), "method": "manual", }) s_ip6 = dbus.Dictionary({"method": "ignore"}) con = dbus.Dictionary({ "802-3-ethernet": s_wired, "connection": s_con, "ipv4": s_ip4,
def test(q, bus, mc): params = dbus.Dictionary({"account": "*****@*****.**", "password": "******"}, signature='sv') simulated_cm, account = create_fakecm_account(q, bus, mc, params) conn = enable_fakecm_account(q, bus, mc, account, params) text_fixed_properties = dbus.Dictionary({ cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT, cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT, }, signature='sv') vague_fixed_properties = dbus.Dictionary({ cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT, }, signature='sv') empathy_bus = dbus.bus.BusConnection() q.attach_to_bus(empathy_bus) empathy = SimulatedClient(q, empathy_bus, 'Empathy', observe=[text_fixed_properties], approve=[text_fixed_properties], handle=[text_fixed_properties], bypass_approval=False) # Kopete's filter is less specific than Empathy's, so we'll prefer Empathy kopete_bus = dbus.bus.BusConnection() q.attach_to_bus(kopete_bus) kopete = SimulatedClient(q, kopete_bus, 'Kopete', observe=[], approve=[], handle=[vague_fixed_properties], bypass_approval=False) # wait for MC to download the properties expect_client_setup(q, [empathy, kopete]) # subscribe to the OperationList interface (MC assumes that until this # property has been retrieved once, nobody cares) cd = bus.get_object(cs.CD, cs.CD_PATH) cd_props = dbus.Interface(cd, cs.PROPERTIES_IFACE) assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == [] channel_properties = dbus.Dictionary(text_fixed_properties, signature='sv') channel_properties[cs.CHANNEL + '.TargetID'] = 'juliet' channel_properties[cs.CHANNEL + '.TargetHandle'] = \ conn.ensure_handle(cs.HT_CONTACT, 'juliet') channel_properties[cs.CHANNEL + '.InitiatorID'] = 'juliet' channel_properties[cs.CHANNEL + '.InitiatorHandle'] = \ conn.ensure_handle(cs.HT_CONTACT, 'juliet') channel_properties[cs.CHANNEL + '.Requested'] = False channel_properties[cs.CHANNEL + '.Interfaces'] = dbus.Array(signature='s') chan = SimulatedChannel(conn, channel_properties) chan.announce() # A channel dispatch operation is created e = q.expect('dbus-signal', path=cs.CD_PATH, interface=cs.CD_IFACE_OP_LIST, signal='NewDispatchOperation') cdo_path = e.args[0] cdo_properties = e.args[1] assert cdo_properties[cs.CDO + '.Account'] == account.object_path assert cdo_properties[cs.CDO + '.Connection'] == conn.object_path assert cs.CDO + '.Interfaces' in cdo_properties # In this test Empathy's filter has more things in it than Kopete's, so # MC will prefer Empathy handlers = cdo_properties[cs.CDO + '.PossibleHandlers'][:] assert handlers == [cs.tp_name_prefix + '.Client.Empathy', cs.tp_name_prefix + '.Client.Kopete'], handlers assert cs.CD_IFACE_OP_LIST in cd_props.Get(cs.CD, 'Interfaces') assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') ==\ [(cdo_path, cdo_properties)] cdo = bus.get_object(cs.CD, cdo_path) cdo_iface = dbus.Interface(cdo, cs.CDO) cdo_props_iface = dbus.Interface(cdo, cs.PROPERTIES_IFACE) assert cdo_props_iface.Get(cs.CDO, 'Interfaces') == \ cdo_properties[cs.CDO + '.Interfaces'] assert cdo_props_iface.Get(cs.CDO, 'Connection') == conn.object_path assert cdo_props_iface.Get(cs.CDO, 'Account') == account.object_path assert cdo_props_iface.Get(cs.CDO, 'Channels') == [(chan.object_path, channel_properties)] assert cdo_props_iface.Get(cs.CDO, 'PossibleHandlers') == \ cdo_properties[cs.CDO + '.PossibleHandlers'] e = q.expect('dbus-method-call', path=empathy.object_path, interface=cs.OBSERVER, method='ObserveChannels', handled=False) assert e.args[0] == account.object_path, e.args assert e.args[1] == conn.object_path, e.args assert e.args[3] == cdo_path, e.args assert e.args[4] == [], e.args # no requests satisfied channels = e.args[2] assert len(channels) == 1, channels assert channels[0][0] == chan.object_path, channels assert channels[0][1] == channel_properties, channels q.dbus_return(e.message, bus=empathy_bus, signature='') e = q.expect('dbus-method-call', path=empathy.object_path, interface=cs.APPROVER, method='AddDispatchOperation', handled=False) assert e.args == [[(chan.object_path, channel_properties)], cdo_path, cdo_properties] q.dbus_return(e.message, bus=empathy_bus, signature='') call_async(q, cdo_iface, 'HandleWith', cs.tp_name_prefix + '.Client.Empathy') # Empathy is asked to handle the channels e = q.expect('dbus-method-call', path=empathy.object_path, interface=cs.HANDLER, method='HandleChannels', handled=False) # Empathy rejects the channels q.dbus_raise(e.message, cs.NOT_AVAILABLE, 'Blind drunk', bus=empathy_bus) e = q.expect('dbus-error', method='HandleWith') assert e.error.get_dbus_name() == cs.NOT_AVAILABLE assert e.error.get_dbus_message() == 'Blind drunk' # The channels no longer count as having been approved. Check that MC # doesn't carry on regardless forbidden = [EventPattern('dbus-method-call', method='HandleChannels')] q.forbid_events(forbidden) sync_dbus(bus, q, mc) q.unforbid_events(forbidden) # I'm Feeling Lucky. It might work if I try again? Maybe? call_async(q, cdo_iface, 'HandleWith', cs.tp_name_prefix + '.Client.Empathy') # Empathy is asked to handle the channels, again e = q.expect('dbus-method-call', path=empathy.object_path, interface=cs.HANDLER, method='HandleChannels', handled=False) # Empathy rejects the channels, again q.dbus_raise(e.message, cs.NOT_CAPABLE, 'Still drunk', bus=empathy_bus) e = q.expect('dbus-error', method='HandleWith') assert e.error.get_dbus_name() == cs.NOT_CAPABLE assert e.error.get_dbus_message() == 'Still drunk' # OK, OK, is anyone else competent enough to handle them? # (Also, assert that MC doesn't offer them back to Empathy, knowing that # it already tried and failed) forbidden = [EventPattern('dbus-method-call', method='HandleChannels', path=empathy.object_path)] q.forbid_events(forbidden) call_async(q, cdo_iface, 'HandleWith', '') # Kopete is asked to handle the channels k = q.expect('dbus-method-call', path=kopete.object_path, interface=cs.HANDLER, method='HandleChannels', handled=False) # Kopete rejects the channels too q.dbus_raise(k.message, cs.NOT_AVAILABLE, 'Also blind drunk', bus=kopete_bus) e = q.expect('dbus-error', method='HandleWith') assert e.error.get_dbus_name() == cs.NOT_AVAILABLE assert e.error.get_dbus_message() == 'Also blind drunk' # MC gives up and closes the channel. This is the end of the CDO. q.expect_many( EventPattern('dbus-method-call', path=chan.object_path, interface=cs.CHANNEL, method='Close', args=[]), EventPattern('dbus-signal', interface=cs.CDO, signal='Finished'), EventPattern('dbus-signal', interface=cs.CD_IFACE_OP_LIST, signal='DispatchOperationFinished'), ) # Now there are no more active channel dispatch operations assert cd_props.Get(cs.CD_IFACE_OP_LIST, 'DispatchOperations') == []
def get_SupportedUriSchemes(self): return dbus.Array(self.core.uri_schemes.get(), signature='s')
def test_action_multiple_device_batteries(self): '''critical actions for multiple device batteries''' # add a fake battery to upower bat1_path = self.obj_upower.AddDischargingBattery( 'mock_BAT1', 'Bat0', 30.0, 1200) obj_bat1 = self.system_bus_con.get_object('org.freedesktop.UPower', bat1_path) self.obj_upower.EmitSignal('', 'DeviceAdded', 'o', [bat1_path], dbus_interface='org.freedesktop.DBus.Mock') bat2_path = '/org/freedesktop/UPower/devices/' + 'mock_MOUSE_BAT1' self.obj_upower.AddObject( bat2_path, 'org.freedesktop.UPower.Device', { 'PowerSupply': dbus.Boolean(False, variant_level=1), 'IsPresent': dbus.Boolean(True, variant_level=1), 'Model': dbus.String('Bat1', variant_level=1), 'Percentage': dbus.Double(40.0, variant_level=1), 'TimeToEmpty': dbus.Int64(1600, variant_level=1), 'EnergyFull': dbus.Double(100.0, variant_level=1), 'Energy': dbus.Double(40.0, variant_level=1), # UP_DEVICE_STATE_DISCHARGING 'State': dbus.UInt32(2, variant_level=1), # UP_DEVICE_KIND_BATTERY 'Type': dbus.UInt32(2, variant_level=1), }, dbus.Array([], signature='(ssss)')) obj_bat2 = self.system_bus_con.get_object('org.freedesktop.UPower', bat2_path) self.obj_upower.EmitSignal('', 'DeviceAdded', 'o', [bat2_path], dbus_interface='org.freedesktop.DBus.Mock') time.sleep(1) # now change the mouse battery to critical charge obj_bat2.Set('org.freedesktop.UPower.Device', 'TimeToEmpty', dbus.Int64(30, variant_level=1), dbus_interface=dbus.PROPERTIES_IFACE) obj_bat2.Set('org.freedesktop.UPower.Device', 'Energy', dbus.Double(0.5, variant_level=1), dbus_interface=dbus.PROPERTIES_IFACE) obj_bat2.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') self.obj_upower.EmitSignal('', 'DeviceChanged', 'o', [bat2_path], dbus_interface='org.freedesktop.DBus.Mock') # wait long enough to ensure it didn't do anything (as we still have # the second battery) self.check_no_suspend(5) # now change the main battery to critical charge as well obj_bat1.Set('org.freedesktop.UPower.Device', 'TimeToEmpty', dbus.Int64(25, variant_level=1), dbus_interface=dbus.PROPERTIES_IFACE) obj_bat1.Set('org.freedesktop.UPower.Device', 'Energy', dbus.Double(0.4, variant_level=1), dbus_interface=dbus.PROPERTIES_IFACE) obj_bat1.EmitSignal('', 'Changed', '', [], dbus_interface='org.freedesktop.DBus.Mock') self.obj_upower.EmitSignal('', 'DeviceChanged', 'o', [bat1_path], dbus_interface='org.freedesktop.DBus.Mock') self.check_for_suspend(5)
def test_channel_creation(q, bus, account, client, conn, ensure): user_action_time = dbus.Int64(1238582606) cd = bus.get_object(cs.CD, cs.CD_PATH) cd_props = dbus.Interface(cd, cs.PROPERTIES_IFACE) # chat UI calls ChannelDispatcher.EnsureChannel or CreateChannel request = dbus.Dictionary( { cs.CHANNEL + '.ChannelType': cs.CHANNEL_TYPE_TEXT, cs.CHANNEL + '.TargetHandleType': cs.HT_CONTACT, cs.CHANNEL + '.TargetID': 'juliet', }, signature='sv') call_async(q, cd, (ensure and 'EnsureChannel' or 'CreateChannel'), account.object_path, request, user_action_time, client.bus_name, dbus_interface=cs.CD) ret = q.expect('dbus-return', method=(ensure and 'EnsureChannel' or 'CreateChannel')) request_path = ret.value[0] # chat UI connects to signals and calls ChannelRequest.Proceed() cr = bus.get_object(cs.AM, request_path) request_props = cr.GetAll(cs.CR, dbus_interface=cs.PROPERTIES_IFACE) assert request_props['Account'] == account.object_path assert request_props['Requests'] == [request] assert request_props['UserActionTime'] == user_action_time assert request_props['PreferredHandler'] == client.bus_name assert request_props['Interfaces'] == [] cr.Proceed(dbus_interface=cs.CR) # FIXME: should the EnsureChannel/CreateChannel call, and the AddRequest # call, be in a defined order? Probably not though, since CMs and Clients # aren't meant to be the same process! cm_request_call, add_request_call = q.expect_many( EventPattern('dbus-method-call', interface=cs.CONN_IFACE_REQUESTS, method=(ensure and 'EnsureChannel' or 'CreateChannel'), path=conn.object_path, args=[request], handled=False), EventPattern('dbus-method-call', handled=False, interface=cs.CLIENT_IFACE_REQUESTS, method='AddRequest', path=client.object_path), ) assert add_request_call.args[0] == request_path request_props = add_request_call.args[1] assert request_props[cs.CR + '.Account'] == account.object_path assert request_props[cs.CR + '.Requests'] == [request] assert request_props[cs.CR + '.UserActionTime'] == user_action_time assert request_props[cs.CR + '.PreferredHandler'] == client.bus_name assert request_props[cs.CR + '.Interfaces'] == [] q.dbus_return(add_request_call.message, signature='') # Time passes. A channel is returned. channel_immutable = dbus.Dictionary(request) channel_immutable[cs.CHANNEL + '.InitiatorID'] = conn.self_ident channel_immutable[cs.CHANNEL + '.InitiatorHandle'] = conn.self_handle channel_immutable[cs.CHANNEL + '.Requested'] = True channel_immutable[cs.CHANNEL + '.Interfaces'] = \ dbus.Array([], signature='s') channel_immutable[cs.CHANNEL + '.TargetHandle'] = \ conn.ensure_handle(cs.HT_CONTACT, 'juliet') channel = SimulatedChannel(conn, channel_immutable) # this order of events is guaranteed by telepathy-spec (since 0.17.14) if ensure: q.dbus_return( cm_request_call.message, True, # <- Yours channel.object_path, channel.immutable, signature='boa{sv}') else: # Create q.dbus_return(cm_request_call.message, channel.object_path, channel.immutable, signature='oa{sv}') channel.announce() # Observer should get told, processing waits for it e = q.expect('dbus-method-call', path=client.object_path, interface=cs.OBSERVER, method='ObserveChannels', handled=False) assert e.args[0] == account.object_path, e.args assert e.args[1] == conn.object_path, e.args assert e.args[3] == '/', e.args # no dispatch operation assert e.args[4] == [request_path], e.args channels = e.args[2] assert len(channels) == 1, channels assert channels[0][0] == channel.object_path, channels assert channels[0][1] == channel_immutable, channels # Observer says "OK, go" q.dbus_return(e.message, signature='') # Handler is next e = q.expect('dbus-method-call', path=client.object_path, interface=cs.HANDLER, method='HandleChannels', handled=False) assert e.args[0] == account.object_path, e.args assert e.args[1] == conn.object_path, e.args channels = e.args[2] assert len(channels) == 1, channels assert channels[0][0] == channel.object_path, channels assert channels[0][1] == channel_immutable, channels assert e.args[3] == [request_path], e.args assert e.args[4] == user_action_time assert isinstance(e.args[5], dict) assert len(e.args) == 6 # Handler fails at handling channels q.dbus_raise(e.message, cs.INVALID_ARGUMENT, 'Parlez vous Freezepop?') e = q.expect('dbus-method-call', path=client.object_path, interface=cs.CLIENT_IFACE_REQUESTS, method='RemoveRequest', handled=False) q.dbus_raise(e.message, cs.INVALID_ARGUMENT, 'Do you realise?') q.expect_many( EventPattern('dbus-signal', path=cr.object_path, interface=cs.CR, signal='Failed'), EventPattern('dbus-method-call', path=channel.object_path, interface=cs.CHANNEL, method='Close', handled=True), )
def seen_bssids(self, new_seen_bssids): self.prop_dict["seen-bssids"] = dbus.Array( new_seen_bssids, signature=dbus.Signature('s'))
# add IPv4 setting if it doesn't yet exist if 'ipv4' not in c_settings: c_settings['ipv4'] = {} # clear existing address info if c_settings['ipv4'].has_key('addresses'): del c_settings['ipv4']['addresses'] if c_settings['ipv4'].has_key('address-data'): del c_settings['ipv4']['address-data'] if c_settings['ipv4'].has_key('gateway'): del c_settings['ipv4']['gateway'] # set the method and change properties c_settings['ipv4']['method'] = method if method == "manual": # Add the static IP address, prefix, and (optional) gateway addr = dbus.Dictionary({ 'address': sys.argv[3], 'prefix': dbus.UInt32(int(sys.argv[4])) }) c_settings['ipv4']['address-data'] = dbus.Array( [addr], signature=dbus.Signature('a{sv}')) if len(sys.argv) == 6: c_settings['ipv4']['gateway'] = sys.argv[5] # Save all the updated settings back to NetworkManager c_obj.Update(c_settings) break sys.exit(0)
def bytes_to_ay(self, bytes): """Convert Python bytes to a DBus bytearray""" return dbus.Array([dbus.Byte(b) for b in bytes], signature=dbus.Signature('y'), variant_level=1)
def GetComplexArray(self): ret = [] for i in range(0,100): ret.append((random.randint(0,100), random.randint(0,100), str(random.randint(0,100)))) return dbus.Array(ret, signature="(uus)")
def to_path_array(src): array = dbus.Array([], signature=dbus.Signature('o')) for o in src: array.append(to_path(o)) return array
def __add_connection(self, ssid): debug("Adding connection: " + ssid) server_alt_subject_name_list = dbus.Array(Config.servers) server_name = Config.server_match if self.nm_version == "0.9" or self.nm_version == "1.0": match_key = 'altsubject-matches' match_value = server_alt_subject_name_list else: match_key = 'subject-match' match_value = server_name s_8021x_data = { 'eap': [Config.eap_outer.lower()], 'identity': self.user_data.username, 'ca-cert': dbus.ByteArray("file://{0}\0".format( self.cacert_file).encode('utf8')), match_key: match_value } if Config.eap_outer == 'PEAP' or Config.eap_outer == 'TTLS': s_8021x_data['password'] = self.user_data.password s_8021x_data['phase2-auth'] = Config.eap_inner.lower() if Config.anonymous_identity != '': s_8021x_data['anonymous-identity'] = Config.anonymous_identity s_8021x_data['password-flags'] = 0 if Config.eap_outer == 'TLS': s_8021x_data['client-cert'] = dbus.ByteArray("file://{0}\0".format( self.pfx_file).encode('utf8')) s_8021x_data['private-key'] = dbus.ByteArray("file://{0}\0".format( self.pfx_file).encode('utf8')) s_8021x_data['private-key-password'] = self.user_data.password s_8021x_data['private-key-password-flags'] = 0 s_con = dbus.Dictionary({ 'type': '802-11-wireless', 'uuid': str(uuid.uuid4()), 'permissions': ['user:'******'USER')], 'id': ssid }) s_wifi = dbus.Dictionary({ 'ssid': dbus.ByteArray(ssid.encode('utf8')), 'security': '802-11-wireless-security' }) s_wsec = dbus.Dictionary({ 'key-mgmt': 'wpa-eap', 'proto': ['rsn'], 'pairwise': ['ccmp'], 'group': ['ccmp', 'tkip'] }) s_8021x = dbus.Dictionary(s_8021x_data) s_ip4 = dbus.Dictionary({'method': 'auto'}) s_ip6 = dbus.Dictionary({'method': 'auto'}) con = dbus.Dictionary({ 'connection': s_con, '802-11-wireless': s_wifi, '802-11-wireless-security': s_wsec, '802-1x': s_8021x, 'ipv4': s_ip4, 'ipv6': s_ip6 }) self.settings.AddConnection(con)
def py2_dbus_bytearray(self, prop): return dbus.Array([dbus.Byte(x) for x in prop], signature = dbus.Signature('y'))
def get_devices(self): r = [] for device in self.devices.values(): #r.append(device.path()) r.append(device.get_info()) return dbus.Array(r, signature='v', variant_level=2)
def prompt_callback(): for object in prompts: object.perform_xlock(lock) return dbus.Array([o.path for o in prompts], signature='o')
def done(generator): dbus_async_cb(dbus.Array(infos, signature='v', variant_level=2))
def Lvs(self): return dbus.Array(self.state.Lvs, signature='o')
def get_device_icons(self): return dbus.Array(self.device.icons, signature='av', variant_level=2)
def IconThemePath(self): return dbus.Array(signature='s')
def serialize(self, struct): super(PropList, self).serialize(struct) props = map(lambda p: serialize_object(p), self.__props) struct.append(dbus.Array(props, signature="v"))
def add_service_data(self, uuid, data): if not self.service_data: self.service_data = dbus.Dictionary({}, signature="sv") self.service_data[uuid] = dbus.Array(data, signature="y")
def __get_filters_handler_cb(self): filter_dict = dbus.Dictionary({}, signature='sv') return dbus.Array([filter_dict], signature='a{sv}')
def getDMSList(self): return dbus.Array(self._get_devices_of_type('MediaServer'), signature='v', variant_level=2)
def AddDevice(self, adapter_device_name, device_address, alias): '''Convenience method to add a Bluetooth device You have to specify a device address which must be a valid Bluetooth address (e.g. 'AA:BB:CC:DD:EE:FF'). The alias is the human-readable name for the device (e.g. as set on the device itself), and the adapter device name is the device_name passed to AddAdapter. This will create a new, unpaired and unconnected device. Returns the new object path. ''' device_name = 'dev_' + device_address.replace(':', '_').upper() adapter_path = '/org/bluez/' + adapter_device_name path = adapter_path + '/' + device_name if adapter_path not in mockobject.objects: raise dbus.exceptions.DBusException( 'No such adapter.', name='org.bluez.Error.NoSuchAdapter') properties = { 'UUIDs': dbus.Array([], signature='s', variant_level=1), 'Blocked': dbus.Boolean(False, variant_level=1), 'Connected': dbus.Boolean(False, variant_level=1), 'LegacyPairing': dbus.Boolean(False, variant_level=1), 'Paired': dbus.Boolean(False, variant_level=1), 'Trusted': dbus.Boolean(False, variant_level=1), 'RSSI': dbus.Int16(-79, variant_level=1), # arbitrary 'Adapter': dbus.ObjectPath(adapter_path, variant_level=1), 'Address': dbus.String(device_address, variant_level=1), 'Alias': dbus.String(alias, variant_level=1), 'Name': dbus.String(alias, variant_level=1), 'Class': dbus.UInt32(0x240404, variant_level=1), # Audio, headset. 'Icon': dbus.String('audio-headset', variant_level=1), } self.AddObject( path, DEVICE_IFACE, # Properties properties, # Methods [ ('GetProperties', '', 'a{sv}', 'ret = self.GetAll("org.bluez.Device")'), ('SetProperty', 'sv', '', 'self.Set("org.bluez.Device", args[0], args[1]); ' 'self.EmitSignal("org.bluez.Device", "PropertyChanged",' ' "sv", [args[0], args[1]])'), ]) manager = mockobject.objects['/'] manager.EmitSignal(OBJECT_MANAGER_IFACE, 'InterfacesAdded', 'oa{sa{sv}}', [ dbus.ObjectPath(path, variant_level=1), { DEVICE_IFACE: properties }, ]) adapter = mockobject.objects[adapter_path] adapter.EmitSignal(ADAPTER_IFACE, 'DeviceFound', 'sa{sv}', [ properties['Address'], properties, ]) return path