Skip to content

Commit 7e0f7ff

Browse files
committed
Allow passing timeout value to a generated D-Bus function
This grants the flexibility to override the default value established when the class was built with a value specific to this method. Signed-off-by: mulhern <amulhern@redhat.com>
1 parent 4b9b9aa commit 7e0f7ff

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

src/dbus_python_client_gen/_invokers.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
def prop_builder(
31-
interface_name: str, properties: Sequence[ET.Element], timeout: int
31+
interface_name: str, properties: Sequence[ET.Element], default_timeout: int
3232
) -> Callable[[MutableMapping[str, Type]], None]:
3333
"""
3434
Returns a function that builds a property interface based on arguments.
@@ -51,7 +51,7 @@ def prop_builder(
5151
:param str interface_name: the interface to which these properties belong
5252
:param properties: iterable of interface specifications for each property
5353
:type properties: iterable of xml.element.ElementTree.Element
54-
:param int timeout: the dbus method timeout, -1 is the libdbus default ~25s.
54+
:param int defaul_timeout: the D-Bus timeout, -1 is the libdbus default ~25s
5555
5656
:raises DPClientGenerationError:
5757
"""
@@ -63,7 +63,9 @@ def build_property_getter(name: str) -> Callable[[ProxyObject], Any]:
6363
:param str name: the name of the property
6464
"""
6565

66-
def dbus_func(proxy_object: ProxyObject) -> Any:
66+
def dbus_func(
67+
proxy_object: ProxyObject, *, timeout: int = default_timeout
68+
) -> Any:
6769
"""
6870
The property getter.
6971
@@ -108,7 +110,9 @@ def build_property_setter(
108110
fmt_str % (signature, name, interface_name)
109111
) from err
110112

111-
def dbus_func(proxy_object: ProxyObject, value: Any) -> None:
113+
def dbus_func(
114+
proxy_object: ProxyObject, value: Any, *, timeout: int = default_timeout
115+
) -> None:
112116
"""
113117
The property setter.
114118
@@ -243,7 +247,7 @@ class has up to two static methods, a Get method if the property is
243247

244248

245249
def method_builder(
246-
interface_name: str, methods: Sequence[ET.Element], timeout: int
250+
interface_name: str, methods: Sequence[ET.Element], default_timeout: int
247251
) -> Callable[[MutableMapping[str, Callable]], None]:
248252
"""
249253
Returns a function that builds a method interface based on 'spec'.
@@ -262,7 +266,7 @@ def method_builder(
262266
:param str interface_name: name the interface to which the methods belong
263267
:param methods: the iterable of interface specification for each method
264268
:type methods: iterator of xml.element.ElementTree.Element
265-
:param int timeout: the dbus method timeout, -1 is the libdbus default ~25s.
269+
:param int default_timeout: D-Bus timeout, -1 is the libdbus default ~25s.
266270
267271
:raises DPClientGenerationError:
268272
"""
@@ -309,7 +313,12 @@ def build_method(
309313
) from err
310314
arg_names_set = frozenset(arg_names)
311315

312-
def dbus_func(proxy_object: ProxyObject, func_args: Mapping[str, Any]) -> Any:
316+
def dbus_func(
317+
proxy_object: ProxyObject,
318+
func_args: Mapping[str, Any],
319+
*,
320+
timeout=default_timeout,
321+
) -> Any:
313322
"""
314323
The method proper.
315324
@@ -417,7 +426,7 @@ def make_class(name: str, spec: ET.Element, timeout: int = -1) -> Type:
417426
:param str name: the name of the class.
418427
:param spec: the interface specification
419428
:type spec: xml.element.ElementTree.Element
420-
:param int timeout: dbus timeout for method(s), -1 is libdbus default ~25s.
429+
:param int timeout: D-Bus timeout, -1 is libdbus default ~25s
421430
:returns: the constructed class
422431
:rtype: type
423432
"""

0 commit comments

Comments
 (0)