/usr/share/doc/python-telepathy/examples/account.py is in python-telepathy 0.15.19-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | import telepathy
from telepathy.interfaces import CONN_MGR_INTERFACE
import dbus
def parse_account(s):
lines = s.splitlines()
pairs = []
manager = None
protocol = None
for line in lines:
if not line.strip():
continue
k, v = line.split(':', 1)
k = k.strip()
v = v.strip()
if k == 'manager':
manager = v
elif k == 'protocol':
protocol = v
else:
if k not in ("account", "password"):
if v.lower() == "false":
v = False
elif v.lower() == "true":
v = True
else:
try:
v = dbus.UInt32(int(v))
except:
pass
pairs.append((k, v))
assert manager
assert protocol
return manager, protocol, dict(pairs)
def read_account(path):
return parse_account(file(path).read())
def connect(manager, protocol, account, ready_handler=None, bus=None):
reg = telepathy.client.ManagerRegistry(bus=bus)
reg.LoadManagers()
mgr = reg.GetManager(manager)
conn_bus_name, conn_object_path = \
mgr[CONN_MGR_INTERFACE].RequestConnection(protocol, account)
return telepathy.client.Connection(conn_bus_name, conn_object_path,
ready_handler=ready_handler, bus=bus)
def connection_from_file(path, ready_handler=None, bus=None):
manager, protocol, account = read_account(path)
return connect(manager, protocol, account,
ready_handler=ready_handler, bus=bus)
|