3 from __future__ import absolute_import, print_function, unicode_literals
8 import dbus.mainloop.glib
10 from gi.repository import GObject
12 import gobject as GObject
14 BUS_NAME = 'org.bluez.obex'
15 PATH = '/org/bluez/obex'
16 AGENT_MANAGER_INTERFACE = 'org.bluez.obex.AgentManager1'
17 AGENT_INTERFACE = 'org.bluez.obex.Agent1'
18 TRANSFER_INTERFACE = 'org.bluez.obex.Transfer1'
22 return raw_input(prompt)
26 class Agent(dbus.service.Object):
27 def __init__(self, conn=None, obj_path=None):
28 dbus.service.Object.__init__(self, conn, obj_path)
29 self.pending_auth = False
31 @dbus.service.method(AGENT_INTERFACE, in_signature="o",
33 def AuthorizePush(self, path):
34 transfer = dbus.Interface(bus.get_object(BUS_NAME, path),
35 'org.freedesktop.DBus.Properties')
36 properties = transfer.GetAll(TRANSFER_INTERFACE);
38 self.pending_auth = True
39 auth = ask("Authorize (%s, %s) (Y/n):" % (path,
42 if auth == "n" or auth == "N":
43 self.pending_auth = False
44 raise dbus.DBusException(
45 "org.bluez.obex.Error.Rejected: "
48 self.pending_auth = False
50 return properties['Name']
52 @dbus.service.method(AGENT_INTERFACE, in_signature="",
55 print("Authorization Canceled")
56 self.pending_auth = False
58 if __name__ == '__main__':
59 dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
61 bus = dbus.SessionBus()
62 manager = dbus.Interface(bus.get_object(BUS_NAME, PATH),
63 AGENT_MANAGER_INTERFACE)
66 agent = Agent(bus, path)
68 mainloop = GObject.MainLoop()
70 manager.RegisterAgent(path)
71 print("Agent registered")
77 except KeyboardInterrupt:
78 if agent.pending_auth:
80 elif len(transfers) > 0:
86 # manager.UnregisterAgent(path)
87 # print "Agent unregistered"