#!/usr/bin/python
+from __future__ import print_function
+
import dbus
import dbus.exceptions
import dbus.mainloop.glib
import dbus.service
import array
-import gobject
+
+try:
+ from gi.repository import GObject # python3
+except ImportError:
+ import gobject as GObject # python2
from random import randint
in_signature='s',
out_signature='a{sv}')
def GetAll(self, interface):
- print 'GetAll'
+ print('GetAll')
if interface != LE_ADVERTISEMENT_IFACE:
raise InvalidArgsException()
- print 'returning props'
+ print('returning props')
return self.get_properties()[LE_ADVERTISEMENT_IFACE]
@dbus.service.method(LE_ADVERTISEMENT_IFACE,
in_signature='',
out_signature='')
def Release(self):
- print '%s: Released!' % self.path
+ print('%s: Released!' % self.path)
class TestAdvertisement(Advertisement):
def register_ad_cb():
- print 'Advertisement registered'
+ print('Advertisement registered')
def register_ad_error_cb(error):
- print 'Failed to register advertisement: ' + str(error)
+ print('Failed to register advertisement: ' + str(error))
mainloop.quit()
DBUS_OM_IFACE)
objects = remote_om.GetManagedObjects()
- for o, props in objects.iteritems():
+ for o, props in objects.items():
if LE_ADVERTISING_MANAGER_IFACE in props:
return o
adapter = find_adapter(bus)
if not adapter:
- print 'LEAdvertisingManager1 interface not found'
+ print('LEAdvertisingManager1 interface not found')
return
adapter_props = dbus.Interface(bus.get_object(BLUEZ_SERVICE_NAME, adapter),
test_advertisement = TestAdvertisement(bus, 0)
- mainloop = gobject.MainLoop()
+ mainloop = GObject.MainLoop()
ad_manager.RegisterAdvertisement(test_advertisement.get_path(), {},
reply_handler=register_ad_cb,