Introspection Representation In DBussy
Lawrence D'Oliveiro
ldo at geek-central.gen.nz
Thu May 25 02:54:43 UTC 2017
XML is not something you want to deal with when you don’t have to. It’s
useful enough as an interchange format, but it is not easy to manipulate.
In particular, I don’t consider it “Pythonic” to have to carry around
long strings of XML in Python code.
That’s why DBussy has the Introspection object hierarchy. Inside one of
these, you have Introspection.Interface objects, and within those, you
have Introspection.Interface.Method, Introspection.Interface.Signal,
Introspection.Interface.Property, and so on, down to individual
arguments, annotations etc. Plus Node objects of course.
Naturally, it is easy to generate one of these object trees from a
standard D-Bus XML introspection string. And conversely, it is easy to
generate the standard D-Bus XML format from an Introspection tree. As
a convenience, I include prebuilt Introspection trees for the standard
interfaces. Such trees can also be automatically generated from the
information you supply when defining a server-side interface class.
The native Python representation lends itself to all kinds of useful
manipulations. I previously mentioned the “introspect_all” script from
the examples repo <https://github.com/ldo/dbussy_examples>,
<https://gitlab.com/ldo/dbussy_examples>: this traverses the Node
objects, and does recursive introspection of each and replacement with
the results so that the Introspection tree holds the complete
description of the bus peer’s entire object hierarchy.
And of course, proxy interface classes can be automatically generated
from the Introspection format. The def_proxy_interface routine in the
ravel module is the workhorse for this.
More information about the dbus
mailing list