annet 3.9.2__py3-none-any.whl → 3.9.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of annet might be problematic. Click here for more details.
- annet/tracing.py +56 -8
- {annet-3.9.2.dist-info → annet-3.9.3.dist-info}/METADATA +1 -1
- {annet-3.9.2.dist-info → annet-3.9.3.dist-info}/RECORD +8 -8
- {annet-3.9.2.dist-info → annet-3.9.3.dist-info}/WHEEL +0 -0
- {annet-3.9.2.dist-info → annet-3.9.3.dist-info}/entry_points.txt +0 -0
- {annet-3.9.2.dist-info → annet-3.9.3.dist-info}/licenses/AUTHORS +0 -0
- {annet-3.9.2.dist-info → annet-3.9.3.dist-info}/licenses/LICENSE +0 -0
- {annet-3.9.2.dist-info → annet-3.9.3.dist-info}/top_level.txt +0 -0
annet/tracing.py
CHANGED
|
@@ -6,7 +6,6 @@ from typing import Optional, Type, Union
|
|
|
6
6
|
|
|
7
7
|
from annet.connectors import CachedConnector
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
MinDurationT = Optional[Union[str, int]]
|
|
11
10
|
|
|
12
11
|
|
|
@@ -145,9 +144,9 @@ def function(arg=None, /, **outer_kwargs):
|
|
|
145
144
|
|
|
146
145
|
def contextmanager(arg=None, /, **outer_kwargs):
|
|
147
146
|
def decorator(cls_or_func):
|
|
148
|
-
|
|
149
|
-
cache = None
|
|
147
|
+
cache = None
|
|
150
148
|
|
|
149
|
+
if inspect.isfunction(cls_or_func):
|
|
151
150
|
@contextlib.contextmanager
|
|
152
151
|
@wraps(cls_or_func)
|
|
153
152
|
def wrapper(*args, **kwargs):
|
|
@@ -159,12 +158,61 @@ def contextmanager(arg=None, /, **outer_kwargs):
|
|
|
159
158
|
|
|
160
159
|
return wrapper
|
|
161
160
|
else:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
161
|
+
original_enter = cls_or_func.__enter__
|
|
162
|
+
original_exit = cls_or_func.__exit__
|
|
163
|
+
|
|
164
|
+
@wraps(original_enter)
|
|
165
|
+
def one_shot_enter(*args, **kwargs):
|
|
166
|
+
"""Wrap after first call, tracing_connector was set up"""
|
|
167
|
+
nonlocal cache
|
|
168
|
+
if cache is None:
|
|
169
|
+
cls_or_func.__enter__ = original_enter
|
|
170
|
+
cls_or_func.__exit__ = original_exit
|
|
171
|
+
cache = tracing_connector.get().contextmanager(cls_or_func, **outer_kwargs)
|
|
172
|
+
return cache.__enter__(*args, **kwargs) # pylint: disable=unnecessary-dunder-call
|
|
173
|
+
|
|
174
|
+
@wraps(original_exit)
|
|
175
|
+
def one_shot_exit(*args, **kwargs):
|
|
176
|
+
nonlocal cache
|
|
177
|
+
return cache.__exit__(*args, **kwargs)
|
|
178
|
+
|
|
179
|
+
setattr(cls_or_func, "__enter__", one_shot_enter)
|
|
180
|
+
setattr(cls_or_func, "__exit__", one_shot_exit)
|
|
166
181
|
|
|
167
|
-
setattr(cls_or_func, "__enter__", enter)
|
|
168
182
|
return cls_or_func
|
|
169
183
|
|
|
170
184
|
return decorator if arg is None else decorator(arg)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def class_methods(arg=None, /, **outer_kwargs):
|
|
188
|
+
def decorator(cls):
|
|
189
|
+
has_enter, has_exit = False, False
|
|
190
|
+
|
|
191
|
+
for name, attr in inspect.getmembers(cls, lambda x: (
|
|
192
|
+
inspect.isroutine(x)
|
|
193
|
+
and not inspect.ismethoddescriptor(x)
|
|
194
|
+
and not inspect.isbuiltin(x)
|
|
195
|
+
)):
|
|
196
|
+
if getattr(attr, "_disable_class_methods", False):
|
|
197
|
+
continue
|
|
198
|
+
if name == "__enter__":
|
|
199
|
+
has_enter = True
|
|
200
|
+
elif name == "__exit__":
|
|
201
|
+
has_exit = True
|
|
202
|
+
else:
|
|
203
|
+
method = function(**outer_kwargs)(attr)
|
|
204
|
+
if isinstance(inspect.getattr_static(cls, name), staticmethod):
|
|
205
|
+
method = staticmethod(method)
|
|
206
|
+
setattr(cls, name, method)
|
|
207
|
+
|
|
208
|
+
if all((has_enter, has_exit)):
|
|
209
|
+
cls = contextmanager(**outer_kwargs)(cls)
|
|
210
|
+
|
|
211
|
+
return cls
|
|
212
|
+
|
|
213
|
+
return decorator if arg is None else decorator(arg)
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
def disable_class_methods(func):
|
|
217
|
+
setattr(func, "_disable_class_methods", True)
|
|
218
|
+
return func
|
|
@@ -20,7 +20,7 @@ annet/patching.py,sha256=nILbY5oJajN0b1j3f0HEJm05H3HVThnWvB7vDVh7UQw,559
|
|
|
20
20
|
annet/reference.py,sha256=B8mH8VUMcecPnzULiTVb_kTQ7jQrCL7zp4pfIZQa5fk,4035
|
|
21
21
|
annet/storage.py,sha256=44f2aHNFOsQMSJwFvGxyu26oRcs3QmS24TKivcfPlxU,4064
|
|
22
22
|
annet/text_term_format.py,sha256=y0U6VuFEAEil8Ab3HB8DBbVHisu31EHiRV7AOVruCeA,2816
|
|
23
|
-
annet/tracing.py,sha256=
|
|
23
|
+
annet/tracing.py,sha256=GpFULDQroXREXzRkXvotA15O1QRcia15kGOqGeBQDig,5668
|
|
24
24
|
annet/types.py,sha256=f2HwqoKa6AucwFwDMszoouB6m1B8n6VmdjHMktO30Kc,7175
|
|
25
25
|
annet/adapters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
26
26
|
annet/adapters/fetchers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
@@ -200,8 +200,8 @@ annet/vendors/library/optixtrans.py,sha256=VdME69Ca4HAEgoaKN21fZxnmmsqqaxOe_HZja
|
|
|
200
200
|
annet/vendors/library/pc.py,sha256=vfv31_NPi7M-4AUDL89UcpawK2E6xvCpELA209cd1ho,1086
|
|
201
201
|
annet/vendors/library/ribbon.py,sha256=DDOBq-_-FL9dCxqXs2inEWZ-pvw-dJ-A-prA7cKMhec,1216
|
|
202
202
|
annet/vendors/library/routeros.py,sha256=iQa7m_4wjuvcgBOI9gyZwlw1BvzJfOkvUbyoEk-NI9I,1254
|
|
203
|
-
annet-3.9.
|
|
204
|
-
annet-3.9.
|
|
203
|
+
annet-3.9.3.dist-info/licenses/AUTHORS,sha256=rh3w5P6gEgqmuC-bw-HB68vBCr-yIBFhVL0PG4hguLs,878
|
|
204
|
+
annet-3.9.3.dist-info/licenses/LICENSE,sha256=yPxl7dno02Pw7gAcFPIFONzx_gapwDoPXsIsh6Y7lC0,1079
|
|
205
205
|
annet_generators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
206
206
|
annet_generators/example/__init__.py,sha256=OJ77uj8axc-FIyIu_Xdcnzmde3oQW5mk5qbODkhuVc8,355
|
|
207
207
|
annet_generators/example/hostname.py,sha256=RloLzNVetEoWPLITzfJ13Nk3CC0yi-cZB1RTd6dnuhI,2541
|
|
@@ -214,8 +214,8 @@ annet_generators/rpl_example/generator.py,sha256=EWah19gOH8G-QyNyWqxCqdRi0BK7GbM
|
|
|
214
214
|
annet_generators/rpl_example/items.py,sha256=HPgxScDvSqJPdz0c2SppDrH82DZYC4zUaniQwcWmh4A,1176
|
|
215
215
|
annet_generators/rpl_example/mesh.py,sha256=z_WgfDZZ4xnyh3cSf75igyH09hGvtexEVwy1gCD_DzA,288
|
|
216
216
|
annet_generators/rpl_example/route_policy.py,sha256=z6nPb0VDeQtKD1NIg9sFvmUxBD5tVs2frfNIuKdM-5c,2318
|
|
217
|
-
annet-3.9.
|
|
218
|
-
annet-3.9.
|
|
219
|
-
annet-3.9.
|
|
220
|
-
annet-3.9.
|
|
221
|
-
annet-3.9.
|
|
217
|
+
annet-3.9.3.dist-info/METADATA,sha256=9nMZSogPh79v5jBuhfrcLwRXcSRLVyQL7IpH4q-f9Ck,815
|
|
218
|
+
annet-3.9.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
219
|
+
annet-3.9.3.dist-info/entry_points.txt,sha256=5lIaDGlGi3l6QQ2ry2jZaqViP5Lvt8AmsegdD0Uznck,192
|
|
220
|
+
annet-3.9.3.dist-info/top_level.txt,sha256=QsoTZBsUtwp_FEcmRwuN8QITBmLOZFqjssRfKilGbP8,23
|
|
221
|
+
annet-3.9.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|