Skip to content

Commit 1763e88

Browse files
committed
Added docstrings for DBusMio and others.
1 parent bc343eb commit 1763e88

File tree

2 files changed

+50
-3
lines changed

2 files changed

+50
-3
lines changed

dbusclient/__init__.py

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,47 @@
1+
"Convenience wrappers around dbus-python"
2+
13
import dbus
24
import functools
35
from func import *
46

57
def object_path(o):
8+
"""Return the object path of o.
9+
10+
If o is a proxy object, use its appropriate attribute.
11+
Otherwise assume that o already is an object path.
12+
"""
613
if isinstance(o, dbus.proxies.ProxyObject):
714
return o.object_path
815
# hope it is ok
916
return o
1017

1118
class DBusMio(dbus.proxies.ProxyObject):
12-
"""Multi-interface object
19+
"""Multi-interface object.
20+
21+
Will look into introspection data to find which interface
22+
to use for a method or a property, obviating the need for
23+
dbus.proxies.Interface.
24+
If introspection is not available, provide default_interface
25+
to the constructor.
1326
1427
BUGS: 1st method call will block with introspection"""
1528

1629
def __init__(self, conn=None, bus_name=None, object_path=None, introspect=True, follow_name_owner_changes=False, **kwargs):
30+
"""Constructor.
31+
32+
kwargs may contain default_interface, to be used
33+
if introspection does not provide it for a method/property
34+
"""
35+
1736
# FIXME common for this class, all classes?
1837
self.__default_interface = kwargs.pop("default_interface", None)
1938
super(DBusMio, self).__init__(conn, bus_name, object_path, introspect, follow_name_owner_changes, **kwargs)
2039

2140
def __getattr__(self, name):
41+
"""Proxied DBus methods.
42+
43+
Uses introspection or default_interface to find the interface.
44+
"""
2245
# TODO cache
2346
# iface = self._interface_cache.get(name)
2447
# if iface == None:
@@ -37,12 +60,30 @@ def __getattr__(self, name):
3760

3861
# properties
3962
def __getitem__(self, key):
63+
"""Proxies DBus properties as dictionary items.
64+
65+
a = DBusMio(...)
66+
p = a["Prop"]
67+
68+
Uses default_interface (because dbus.proxies.ProxyObject
69+
does not store introspection data for properties, boo. TODO.)
70+
"""
71+
4072
iface = self.__default_interface # TODO cache
4173
# TODO _introspect_property_map
4274
pmi = dbus.Interface(self, "org.freedesktop.DBus.Properties")
4375
return pmi.Get(iface, key)
4476

4577
def __setitem__(self, key, value):
78+
"""Proxies DBus properties as dictionary items.
79+
80+
a = DBusMio(...)
81+
a["Prop"] = "Hello"
82+
83+
Uses default_interface (because dbus.proxies.ProxyObject
84+
does not store introspection data for properties, boo. TODO.)
85+
"""
86+
4687
iface = self.__default_interface # TODO cache
4788
# TODO _introspect_property_map
4889
pmi = dbus.Interface(self, "org.freedesktop.DBus.Properties")
@@ -69,7 +110,10 @@ class DBusClient(DBusMio):
69110
def _get_adaptor(cls, kind, name):
70111
# print "GET", cls, kind, name
71112
try:
72-
return cls._adaptors[kind][name]
113+
a = cls._adaptors[kind][name]
114+
# print ">", a
115+
# TODO cache somehow?
116+
return a
73117
except KeyError:
74118
scls = cls.__mro__[1] # can use "super"? how?
75119
try:
@@ -96,7 +140,8 @@ def _add_adaptor(cls, kind, name, adaptor):
96140
@classmethod
97141
def _add_adaptors(cls, *args, **kwargs):
98142
"""
99-
either
143+
a nested dictionary of kind:name:adaptor,
144+
either as kwargs (new) or as a single dict arg (old, newest)
100145
"""
101146
if not cls.__dict__.has_key("_adaptors"):
102147
# do not use inherited attribute

dbusclient/monitor.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import string
22

33
class Monitor(object):
4+
"""A Base for printing signals on the bus"""
5+
46
def __init__(self, bus):
57
self.bus = bus
68

0 commit comments

Comments
 (0)