osbot-utils 1.41.0__py3-none-any.whl → 1.42.0__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.
- osbot_utils/decorators/methods/cache_on_self.py +9 -7
- osbot_utils/testing/Hook_Method.py +5 -1
- osbot_utils/utils/Env.py +3 -0
- osbot_utils/utils/Files.py +4 -4
- osbot_utils/version +1 -1
- {osbot_utils-1.41.0.dist-info → osbot_utils-1.42.0.dist-info}/METADATA +2 -2
- {osbot_utils-1.41.0.dist-info → osbot_utils-1.42.0.dist-info}/RECORD +9 -9
- {osbot_utils-1.41.0.dist-info → osbot_utils-1.42.0.dist-info}/LICENSE +0 -0
- {osbot_utils-1.41.0.dist-info → osbot_utils-1.42.0.dist-info}/WHEEL +0 -0
@@ -26,17 +26,19 @@ def cache_on_self(function: T) -> T:
|
|
26
26
|
def wrapper(*args, **kwargs):
|
27
27
|
if len(args) == 0 or inspect.isclass(type(args[0])) is False:
|
28
28
|
raise Exception("In Method_Wrappers.cache_on_self could not find self")
|
29
|
-
|
29
|
+
|
30
|
+
reload_cache = False # default is not to reload cache
|
30
31
|
if 'reload_cache' in kwargs: # if the reload parameter is set to True
|
31
|
-
reload_cache
|
32
|
+
if kwargs['reload_cache'] is True: # only if the reload is explicitly set to True
|
33
|
+
reload_cache = True # set reload value to True
|
32
34
|
del kwargs['reload_cache'] # remove the reload parameter from the kwargs
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
|
36
|
+
self = args[0] # get self
|
37
|
+
cache_id = cache_on_self__get_cache_in_key(function, args, kwargs) # get cache_id value
|
38
|
+
|
37
39
|
if reload_cache is True or hasattr(self, cache_id) is False: # check if return_value has been set or if reload is True
|
38
40
|
return_value = function(*args, **kwargs) # invoke function and capture the return value
|
39
|
-
setattr(self, cache_id,return_value) # set the return value
|
41
|
+
setattr(self, cache_id,return_value) # set the return value in the cache
|
40
42
|
return getattr(self, cache_id) # return the return value
|
41
43
|
return wrapper
|
42
44
|
|
@@ -5,9 +5,10 @@ from osbot_utils.testing.Duration import Duration
|
|
5
5
|
|
6
6
|
class Hook_Method:
|
7
7
|
|
8
|
-
def __init__(self, target_module, target_method):
|
8
|
+
def __init__(self, target_module, target_method, raise_exception=True):
|
9
9
|
self.target_module = target_module
|
10
10
|
self.target_method = target_method
|
11
|
+
self.raise_exception = raise_exception # todo: figure out the impact of raising this by default
|
11
12
|
self.target = getattr(target_module, target_method)
|
12
13
|
self.wrapper_method = None
|
13
14
|
self.calls = []
|
@@ -15,6 +16,7 @@ class Hook_Method:
|
|
15
16
|
self.on_after_call = []
|
16
17
|
self.mock_call = None
|
17
18
|
|
19
|
+
|
18
20
|
def __enter__(self):
|
19
21
|
self.wrap()
|
20
22
|
return self
|
@@ -107,6 +109,8 @@ class Hook_Method:
|
|
107
109
|
'duration' : int(duration.seconds()*1000)
|
108
110
|
}
|
109
111
|
self.calls.append(call)
|
112
|
+
if self.raise_exception and exception:
|
113
|
+
raise exception
|
110
114
|
return call['return_value']
|
111
115
|
|
112
116
|
self.wrapper_method = wrapper_method
|
osbot_utils/utils/Env.py
CHANGED
@@ -6,6 +6,9 @@ from osbot_utils.utils.Files import all_parent_folders, file_exists
|
|
6
6
|
from osbot_utils.utils.Misc import list_set
|
7
7
|
from osbot_utils.utils.Str import strip_quotes
|
8
8
|
|
9
|
+
def del_env(key):
|
10
|
+
if key in os.environ:
|
11
|
+
del os.environ[key]
|
9
12
|
|
10
13
|
def env__home():
|
11
14
|
return get_env('HOME', '')
|
osbot_utils/utils/Files.py
CHANGED
@@ -112,9 +112,9 @@ class Files:
|
|
112
112
|
return os.path.basename(path)
|
113
113
|
|
114
114
|
@staticmethod
|
115
|
-
def file_name_without_extension(path):
|
115
|
+
def file_name_without_extension(path, check_if_exists=False):
|
116
116
|
if path:
|
117
|
-
path_file_name = file_name(path)
|
117
|
+
path_file_name = file_name(path,check_if_exists=check_if_exists)
|
118
118
|
extension = file_extension(path_file_name)
|
119
119
|
if extension:
|
120
120
|
return path_file_name.replace(extension, '')
|
@@ -489,8 +489,8 @@ def file_move_to_folder(source_file, target_folder):
|
|
489
489
|
if file_move(source_file, target_file):
|
490
490
|
return target_file
|
491
491
|
|
492
|
-
def files_names_without_extension(files):
|
493
|
-
return [file_name_without_extension(file) for file in files]
|
492
|
+
def files_names_without_extension(files, check_if_exists=False):
|
493
|
+
return [file_name_without_extension(file, check_if_exists) for file in files]
|
494
494
|
|
495
495
|
def files_names_in_folder(target, with_extension=False):
|
496
496
|
if with_extension:
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v1.
|
1
|
+
v1.42.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.42.0
|
4
4
|
Summary: OWASP Security Bot - Utils
|
5
5
|
Home-page: https://github.com/owasp-sbot/OSBot-Utils
|
6
6
|
License: MIT
|
@@ -22,7 +22,7 @@ Description-Content-Type: text/markdown
|
|
22
22
|
|
23
23
|
Powerful Python util methods and classes that simplify common apis and tasks.
|
24
24
|
|
25
|
-

|
26
26
|
[](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
|
27
27
|
|
28
28
|
|
@@ -18,7 +18,7 @@ osbot_utils/decorators/lists/index_by.py,sha256=BEbfd13l11zROhXAb0vkB_aZi9P2Zt4p
|
|
18
18
|
osbot_utils/decorators/methods/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
19
19
|
osbot_utils/decorators/methods/cache.py,sha256=IMmHBeR6qtaOfBNgZUeI1SVLoexQQy6vk1LDW-20_5w,1062
|
20
20
|
osbot_utils/decorators/methods/cache_on_function.py,sha256=sDebxWjJnusb_w4R26OTYcmTF6CCeWrpesn-dgzEu8g,2694
|
21
|
-
osbot_utils/decorators/methods/cache_on_self.py,sha256=
|
21
|
+
osbot_utils/decorators/methods/cache_on_self.py,sha256=bVSOBXcKVR-ITotq9sReUP1RY3TmnvROfl90564miJY,3681
|
22
22
|
osbot_utils/decorators/methods/cache_on_tmp.py,sha256=8wLnRAUUkHobu6-B2Q8aAE8jLeIu3b-CQuMtXcnIN9w,3102
|
23
23
|
osbot_utils/decorators/methods/capture_exception.py,sha256=mTfjqIS_qvZLhX6_NF_fkD_EnMLZRXkUHqUaiAbqZkU,1160
|
24
24
|
osbot_utils/decorators/methods/capture_status.py,sha256=5xklG0usO3hGTjedhrmIucXtUjPd2pkuvA5jsty0a5E,659
|
@@ -244,7 +244,7 @@ osbot_utils/helpers/trace/Trace_Files.py,sha256=SNpAmuBlSUS9NyVocgZ5vevzqVaIqoh6
|
|
244
244
|
osbot_utils/helpers/trace/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
245
245
|
osbot_utils/testing/Catch.py,sha256=HdNoKnrPBjvVj87XYN-Wa1zpo5z3oByURT6TKbd5QpQ,2229
|
246
246
|
osbot_utils/testing/Duration.py,sha256=iBrczAuw6j3jXtG7ZPraT0PXbCILEcCplJbqei96deA,2217
|
247
|
-
osbot_utils/testing/Hook_Method.py,sha256=
|
247
|
+
osbot_utils/testing/Hook_Method.py,sha256=uCpc89ZhMCfWiyt3tFhIGIInXiY6wTuwAZ1I8UQVRuw,4365
|
248
248
|
osbot_utils/testing/Log_To_Queue.py,sha256=pZQ7I1ne-H365a4WLS60oAD-B16pxIZO4suvCdaTW8U,1703
|
249
249
|
osbot_utils/testing/Log_To_String.py,sha256=hkjWsJfV68uqgX9nvVqUN3mVPxZQDb-6UBwsSEbQnkA,1216
|
250
250
|
osbot_utils/testing/Logging.py,sha256=rzO1cCwty1oTucbV1q6U2QBIF87oOcvZoAY_R8SQB8A,3300
|
@@ -267,9 +267,9 @@ osbot_utils/utils/Assert.py,sha256=u9XLgYn91QvNWZGyPi29SjPJSXRHlm9andIn3NJEVog,1
|
|
267
267
|
osbot_utils/utils/Call_Stack.py,sha256=MAq_0vMxnbeLfCe9qQz7GwJYaOuXpt3qtQwN6wiXsU0,6595
|
268
268
|
osbot_utils/utils/Csv.py,sha256=oHLVpjRJqrLMz9lubMCNEoThXWju5rNTprcwHc1zq2c,1012
|
269
269
|
osbot_utils/utils/Dev.py,sha256=HibpQutYy_iG8gGV8g1GztxNN4l29E4Bi7UZaVL6-L8,1203
|
270
|
-
osbot_utils/utils/Env.py,sha256=
|
270
|
+
osbot_utils/utils/Env.py,sha256=XMwF5BrtpoPJdOraswAFPrcQ3tRTocjqvA8I61eOCJw,5741
|
271
271
|
osbot_utils/utils/Exceptions.py,sha256=KyOUHkXQ_6jDTq04Xm261dbEZuRidtsM4dgzNwSG8-8,389
|
272
|
-
osbot_utils/utils/Files.py,sha256=
|
272
|
+
osbot_utils/utils/Files.py,sha256=7fdqbfFyo6Ow5Repi_dZAzHqGb0XYh6tDALYAy42pBY,22522
|
273
273
|
osbot_utils/utils/Functions.py,sha256=0E6alPJ0fJpBiJgFOWooCOi265wSRyxxXAJ5CELBnso,3498
|
274
274
|
osbot_utils/utils/Http.py,sha256=WlXEfgT_NaiDVD7vCDUxy_nOm5Qf8x_L0A3zd8B5tX8,4706
|
275
275
|
osbot_utils/utils/Int.py,sha256=PmlUdU4lSwf4gJdmTVdqclulkEp7KPCVUDO6AcISMF4,116
|
@@ -288,8 +288,8 @@ osbot_utils/utils/Toml.py,sha256=dqiegndCJF7V1YT1Tc-b0-Bl6QWyL5q30urmQwMXfMQ,140
|
|
288
288
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
289
289
|
osbot_utils/utils/Zip.py,sha256=Gt4K7Q9LlYeRxOVv8aYpaBLKxrYriCAEUa_R6YWEbMg,13903
|
290
290
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
291
|
-
osbot_utils/version,sha256=
|
292
|
-
osbot_utils-1.
|
293
|
-
osbot_utils-1.
|
294
|
-
osbot_utils-1.
|
295
|
-
osbot_utils-1.
|
291
|
+
osbot_utils/version,sha256=XEDmF2gY0SXKEjwvdngDk1U0o2yRWMAxnldMBdQDSOM,8
|
292
|
+
osbot_utils-1.42.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
293
|
+
osbot_utils-1.42.0.dist-info/METADATA,sha256=A5I-YaoHJocPTRXNoGBep9eP3FhVTSndWFE9TcAGCLE,1266
|
294
|
+
osbot_utils-1.42.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
295
|
+
osbot_utils-1.42.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|