Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 3 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ A Python Library for Generating dbus-python Client Code

Function
--------
This library contains a function, invoker_builder, that consumes
an XML specification of a D-Bus interface and yields a function suitable
for use in a new_class method invocation. ::
This library contains a function, make_class, that consumes
an XML specification of a D-Bus interface. ::

>>> builder = invoker_builder(spec)
>>> Klass = types.new_class("Klass", bases=(object,), exec_body=builder)
>>> Klass = make_class("Klass", spec)

This call yields a Python class, called Klass, with two static class
members, "Methods" and "Properties". The "Methods" class has a static
Expand Down
2 changes: 1 addition & 1 deletion src/dbus_python_client_gen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
Top-level classes and methods.
"""

from ._invokers import invoker_builder
from ._invokers import make_class
49 changes: 34 additions & 15 deletions src/dbus_python_client_gen/_invokers.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,14 @@ def dbus_func(proxy_object): # pragma: no cover
"""
The property getter.
"""
return proxy_object.Get(
interface_name,
name,
dbus_interface=dbus.PROPERTIES_IFACE
)
try:
return proxy_object.Get(
interface_name,
name,
dbus_interface=dbus.PROPERTIES_IFACE
)
except dbus.DBusException as err:
raise DPClientRuntimeError() from err

return dbus_func

Expand All @@ -114,12 +117,15 @@ def dbus_func(proxy_object, value): # pragma: no cover
"""
The property setter.
"""
return proxy_object.Set(
interface_name,
name,
xformer(value),
dbus_interface=dbus.PROPERTIES_IFACE
)
try:
return proxy_object.Set(
interface_name,
name,
xformer(value),
dbus_interface=dbus.PROPERTIES_IFACE
)
except dbus.DBusException as err:
raise DPClientRuntimeError() from err

return dbus_func

Expand Down Expand Up @@ -247,10 +253,10 @@ def build_method(spec):

signature = "".join(e.attrib["type"] for e in inargs)

# This function is expected to work for all legal signatures,
# and the attributes are expected to contain only legal signatures.
# Thus, it should never fail.
func = xformers(signature)
try:
func = xformers(signature)
except IntoDPError as err: #pragma: no cover
raise DPClientGenerationError() from err

def dbus_func(proxy_object, **kwargs): # pragma: no cover
"""
Expand Down Expand Up @@ -327,3 +333,16 @@ def builder(namespace):
)

return builder

def make_class(name, spec):
"""
Make a class, name, from the given spec.
The class defines static properties and methods according to the spec.

:param str name: the name of the class.
:param spec: the interface specification
:type spec: xml.element.ElementTree.Element
:returns: the constructed class
:rtype: type
"""
return types.new_class(name, bases=(object,), exec_body=invoker_builder(spec))
2 changes: 1 addition & 1 deletion src/dbus_python_client_gen/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@
.. moduleauthor:: mulhern <amulhern@redhat.com>
"""

__version__ = '0.1'
__version__ = '0.2'
__version_info__ = tuple(int(x) for x in __version__.split('.'))
5 changes: 2 additions & 3 deletions tests/test_generated.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import xml.etree.ElementTree as ET

from dbus_python_client_gen import invoker_builder
from dbus_python_client_gen import make_class

from dbus_python_client_gen._invokers import method_builder
from dbus_python_client_gen._invokers import prop_builder
Expand Down Expand Up @@ -91,8 +91,7 @@ def _testKlass(self):
fields, "Properties" and "Methods".
"""
for name, spec in self._data.items():
builder = invoker_builder(spec)
klass = types.new_class(name, bases=(object,), exec_body=builder)
klass = make_class(name, spec)
self.assertTrue(hasattr(klass, "Properties"))
properties = getattr(klass, "Properties")
self.assertTrue(hasattr(klass, "Methods"))
Expand Down