Skip to content

Add support for deep introspection #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions pydbus/proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class ProxyMixin(object):
__slots__ = ()

def get(self, bus_name, object_path=None, **kwargs):
def get(self, bus_name, object_path=None, deep=True, **kwargs):
"""Get a remote object.

Parameters
Expand All @@ -20,6 +20,10 @@ def get(self, bus_name, object_path=None, **kwargs):
You may start with "." - then org.freedesktop will be automatically prepended.
object_path : string, optional
Path of the object. If not provided, bus_name translated to path format is used.
deep : boolean, optional (default True)
Turn on or off deep introspection, if turned on, the returned object will have an
attribute node that corresponds to its sub-tree of objects.
For legacy behaviour, set this to False.

Returns
-------
Expand Down Expand Up @@ -56,7 +60,12 @@ def get(self, bus_name, object_path=None, **kwargs):
except:
raise KeyError("object provides invalid introspection XML")

return CompositeInterface(introspection)(self, bus_name, object_path)
ci = CompositeInterface(introspection)(self, bus_name, object_path)
if deep:
node_names = [ n.attrib["name"] for n in introspection if n.tag == "node" ]
ci.nodes = { n: self.get(bus_name, object_path + "/" + n, deep=True, **kwargs)
for n in node_names }
return ci

class ProxyObject(object):
def __init__(self, bus, bus_name, path, object=None):
Expand Down