Skip to content

Commit

Permalink
Use an anonymous function to get the interface specification
Browse files Browse the repository at this point in the history
Signed-off-by: mulhern <[email protected]>
  • Loading branch information
mulkieran committed Dec 4, 2023
1 parent 456d6e4 commit 20e4e26
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/stratis_cli/_actions/_dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,23 @@ class Purpose(Enum):


_LOOKUP = {
"Manager": (Purpose.INVOKE, MANAGER_INTERFACE, None),
"ObjectManager": (Purpose.INVOKE, "org.freedesktop.DBus.ObjectManager", None),
"Report": (Purpose.INVOKE, REPORT_INTERFACE, None),
"Manager": (
Purpose.INVOKE,
lambda: ET.fromstring(SPECS[MANAGER_INTERFACE]), # nosec B314
None,
),
"ObjectManager": (
Purpose.INVOKE,
lambda: ET.fromstring(
SPECS["org.freedesktop.DBus.ObjectManager"]
), # nosec B314
None,
),
"Report": (
Purpose.INVOKE,
lambda: ET.fromstring(SPECS[REPORT_INTERFACE]), # nosec B314
None,
),
}


Expand Down Expand Up @@ -82,16 +96,18 @@ def make_dyn_class(name):
:param str name: name of class to make
"""
(purpose, interface_name, klass) = _LOOKUP[name]
(purpose, interface_func, klass) = _LOOKUP[name]

if klass is not None:
return klass

assert interface_func is not None

if purpose is Purpose.INVOKE: # pragma: no cover
try:
klass = make_class(
name,
ET.fromstring(SPECS[interface_name]), # nosec B314
interface_func(),
TIMEOUT,
)

Expand All @@ -117,6 +133,7 @@ def make_dyn_class(name):
"dbus-python methods"
) from err

_LOOKUP[name] = (purpose, interface_name, klass)
# set the function to None since the class has been obtained
_LOOKUP[name] = (purpose, None, klass)

return klass

0 comments on commit 20e4e26

Please sign in to comment.