3636from ._utils import long_running_operation
3737
3838
39+ def _make_class (spec , class_name , * , methods = None , timeout = - 1 ):
40+ """
41+ Make a class from spec, with only requested methods.
42+ Interpret None as all methods.
43+ """
44+ new_spec = ET .Element (spec .tag , spec .attrib )
45+ new_spec .extend (
46+ [
47+ child
48+ for child in spec
49+ if child .tag == "method" and methods is None or child .get ("name" ) in methods
50+ ]
51+ )
52+ return make_class (class_name , new_spec , timeout = timeout )
53+
54+
3955class CryptActions :
4056 """
4157 Whole pool encryption actions.
@@ -54,15 +70,9 @@ def encrypt(namespace: Namespace):
5470 # pylint: disable=import-outside-toplevel
5571 from ._data import MOPool , ObjectManager , pool_spec , pools
5672
57- spec = ET .Element (pool_spec .tag , pool_spec .attrib )
58- spec .extend (
59- [
60- child
61- for child in pool_spec
62- if child .tag == "method" and child .get ("name" ) == "EncryptPool"
63- ]
73+ Pool = _make_class ( # pylint: disable=invalid-name
74+ pool_spec , "Pool" , methods = ["EncryptPool" ], timeout = 10
6475 )
65- Pool = make_class ("Pool" , spec , timeout = 10 ) # pylint: disable=invalid-name
6676
6777 pool_id = PoolId .from_parser_namespace (namespace )
6878 assert pool_id is not None
@@ -124,15 +134,10 @@ def unencrypt(namespace: Namespace):
124134 # pylint: disable=import-outside-toplevel
125135 from ._data import MOPool , ObjectManager , pool_spec , pools
126136
127- spec = ET .Element (pool_spec .tag , pool_spec .attrib )
128- spec .extend (
129- [
130- child
131- for child in pool_spec
132- if child .tag == "method" and child .get ("name" ) == "DecryptPool"
133- ]
137+ Pool = _make_class ( # pylint: disable=invalid-name
138+ pool_spec , "Pool" , methods = ["DecryptPool" ], timeout = 10
134139 )
135- Pool = make_class ( "Pool" , spec , timeout = 10 ) # pylint: disable=invalid-name
140+
136141 pool_id = PoolId .from_parser_namespace (namespace )
137142 assert pool_id is not None
138143
@@ -175,15 +180,9 @@ def reencrypt(namespace: Namespace):
175180 # pylint: disable=import-outside-toplevel
176181 from ._data import ObjectManager , pool_spec , pools
177182
178- spec = ET .Element (pool_spec .tag , pool_spec .attrib )
179- spec .extend (
180- [
181- child
182- for child in pool_spec
183- if child .tag == "method" and child .get ("name" ) == "ReencryptPool"
184- ]
183+ Pool = _make_class ( # pylint: disable=invalid-name
184+ pool_spec , "Pool" , methods = ["ReencryptPool" ], timeout = 10
185185 )
186- Pool = make_class ("Pool" , spec , timeout = 10 ) # pylint: disable=invalid-name
187186
188187 pool_id = PoolId .from_parser_namespace (namespace )
189188 assert pool_id is not None
0 commit comments