Skip to content

Commit 0f77dff

Browse files
committed
Use an anonymous function to get the interface specification
Signed-off-by: mulhern <amulhern@redhat.com>
1 parent 326ecee commit 0f77dff

File tree

1 file changed

+23
-6
lines changed

1 file changed

+23
-6
lines changed

src/stratis_cli/_actions/_dynamic.py

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,23 @@ class Purpose(Enum):
4545

4646

4747
_LOOKUP = {
48-
"Manager": (Purpose.INVOKE, MANAGER_INTERFACE, None),
49-
"ObjectManager": (Purpose.INVOKE, "org.freedesktop.DBus.ObjectManager", None),
50-
"Report": (Purpose.INVOKE, REPORT_INTERFACE, None),
48+
"Manager": (
49+
Purpose.INVOKE,
50+
lambda: ET.fromstring(SPECS[MANAGER_INTERFACE]), # nosec B314
51+
None,
52+
),
53+
"ObjectManager": (
54+
Purpose.INVOKE,
55+
lambda: ET.fromstring(
56+
SPECS["org.freedesktop.DBus.ObjectManager"]
57+
), # nosec B314
58+
None,
59+
),
60+
"Report": (
61+
Purpose.INVOKE,
62+
lambda: ET.fromstring(SPECS[REPORT_INTERFACE]), # nosec B314
63+
None,
64+
),
5165
}
5266

5367

@@ -82,16 +96,18 @@ def make_dyn_class(name):
8296
8397
:param str name: name of class to make
8498
"""
85-
(purpose, interface_name, klass) = _LOOKUP[name]
99+
(purpose, interface_func, klass) = _LOOKUP[name]
86100

87101
if klass is not None:
88102
return klass
89103

104+
assert interface_func is not None
105+
90106
if purpose is Purpose.INVOKE: # pragma: no cover
91107
try:
92108
klass = make_class(
93109
name,
94-
ET.fromstring(SPECS[interface_name]), # nosec B314
110+
interface_func(),
95111
TIMEOUT,
96112
)
97113

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

120-
_LOOKUP[name] = (purpose, interface_name, klass)
136+
# set the function to None since the class has been obtained
137+
_LOOKUP[name] = (purpose, None, klass)
121138

122139
return klass

0 commit comments

Comments
 (0)