osbot-utils 1.32.0__py3-none-any.whl → 1.34.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.
@@ -1,6 +1,7 @@
1
1
  from osbot_utils.base_classes.Type_Safe import Type_Safe
2
2
  from osbot_utils.utils.Dev import pprint
3
3
  from osbot_utils.utils.Files import files_list, file_create_from_bytes, temp_file, parent_folder, parent_folder_create
4
+ from osbot_utils.utils.Misc import random_text
4
5
  from osbot_utils.utils.Regex import list__match_regex, list__match_regexes
5
6
  from osbot_utils.utils.Zip import zip_bytes_empty, zip_bytes__files, zip_bytes__add_file, zip_bytes__add_files, \
6
7
  zip_bytes__replace_files, zip_bytes__replace_file, zip_bytes__file_list, zip_bytes__file, \
@@ -10,8 +11,8 @@ from osbot_utils.utils.Zip import zip_bytes_empty, zip_bytes__files, zip_bytes__
10
11
  class Zip_Bytes(Type_Safe):
11
12
  zip_bytes : bytes = None
12
13
 
13
- def __init__(self):
14
- super().__init__()
14
+ def __init__(self, **kwargs):
15
+ super().__init__(**kwargs)
15
16
  self.zip_bytes = zip_bytes_empty()
16
17
 
17
18
  def __enter__(self):
@@ -44,6 +45,12 @@ class Zip_Bytes(Type_Safe):
44
45
  files_to_add = list__match_regexes(all_files_in_folder, *patterns)
45
46
  return self.add_files__from_disk(base_path, files_to_add)
46
47
 
48
+ def add_random_file(self):
49
+ random_file_name = random_text('file_name' )
50
+ random_file_contents = random_text('file_contents')
51
+ self.add_file(random_file_name, random_file_contents)
52
+ return self
53
+
47
54
  def add_folder__from_disk__with_prefix(self, folder_to_add, path_prefix, *patterns):
48
55
  base_path = folder_to_add
49
56
  all_files_in_folder = files_list(folder_to_add)
@@ -101,5 +101,8 @@ class Cache__Requests__Data(Type_Safe):
101
101
 
102
102
  def response_data_serialize(self, response_data):
103
103
  if self.config.pickle_response:
104
- return pickle_save_to_bytes(response_data)
104
+ try:
105
+ return pickle_save_to_bytes(response_data)
106
+ except: # todo: look at a better way to handle this and any possible side effects (saw this with a couple boto3 class)
107
+ return None
105
108
  return response_data
@@ -1,3 +1,4 @@
1
+ import threading
1
2
  import types
2
3
 
3
4
  from osbot_utils.base_classes.Type_Safe import Type_Safe
@@ -11,6 +12,14 @@ class Cache__Requests__Invoke(Type_Safe):
11
12
  cache_data : Cache__Requests__Data
12
13
  config : Cache__Requests__Config
13
14
  on_invoke_target : types.FunctionType
15
+ cursor_thread_id : int
16
+
17
+ def __init__(self, **kwargs):
18
+ super().__init__(**kwargs)
19
+ self.cursor_thread_id = threading.get_ident() # we need to capture this to make sure we are operating on the same thread
20
+
21
+ def can_operate_in_this_thread(self):
22
+ return self.cursor_thread_id == threading.get_ident()
14
23
 
15
24
  def invoke(self, target, target_args, target_kwargs):
16
25
  return self.invoke_with_cache(target, target_args, target_kwargs)
@@ -22,7 +31,11 @@ class Cache__Requests__Invoke(Type_Safe):
22
31
  raw_response = target(*target_args, **target_kwargs)
23
32
  return self.transform_raw_response(raw_response)
24
33
 
34
+
35
+
25
36
  def invoke_with_cache(self, target, target_args, target_kwargs, request_data=None):
37
+ if self.can_operate_in_this_thread() is False: # make sure we are in the correct thread
38
+ return self.invoke_target(target, target_args, target_kwargs)
26
39
  if self.config.enabled is False:
27
40
  if self.config.cache_only_mode:
28
41
  return None
@@ -43,7 +56,8 @@ class Cache__Requests__Invoke(Type_Safe):
43
56
  try:
44
57
  response_data_obj = self.invoke_target(target, target_args, target_kwargs)
45
58
  response_data = self.cache_data.response_data_serialize(response_data_obj)
46
- self.cache_actions.cache_add(request_data=request_data, response_data=response_data)
59
+ if response_data:
60
+ self.cache_actions.cache_add(request_data=request_data, response_data=response_data)
47
61
  return response_data_obj
48
62
  except Exception as exception:
49
63
  if self.config.capture_exceptions:
@@ -270,7 +270,8 @@ class Files:
270
270
  if isinstance(target, Path):
271
271
  return target.is_file()
272
272
  if type(target) is str:
273
- return os.path.isfile(target)
273
+ if len(target) < 4096: # max file size in Linux (handle the cases when the file contents was used as target)
274
+ return os.path.isfile(target)
274
275
  return False
275
276
 
276
277
  @staticmethod
osbot_utils/utils/Zip.py CHANGED
@@ -235,4 +235,5 @@ zip_bytes__get_file = zip_bytes__file
235
235
  zip_bytes__unzip_to_folder = zip_bytes__unzip
236
236
 
237
237
  zip_list_files = zip_file__list
238
- zip_file__file_list = zip_file__list
238
+ zip_file__file_list = zip_file__list
239
+ zip_file__files_list = zip_file__list
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.32.0
1
+ v1.34.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.32.0
3
+ Version: 1.34.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
- ![Current Release](https://img.shields.io/badge/release-v1.32.0-blue)
25
+ ![Current Release](https://img.shields.io/badge/release-v1.34.0-blue)
26
26
  [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
27
27
 
28
28
 
@@ -64,7 +64,7 @@ osbot_utils/helpers/Print_Table.py,sha256=LEXbyqGg_6WSraI4cob4bNNSu18ddqvALp1zGK
64
64
  osbot_utils/helpers/Python_Audit.py,sha256=shpZlluJwqJBAlad6xN01FkgC1TsQ48RLvR5ZjmrKa4,1539
65
65
  osbot_utils/helpers/Random_Seed.py,sha256=14btja8LDN9cMGWaz4fCNcMRU_eyx49gas-_PQvHgy4,634
66
66
  osbot_utils/helpers/Type_Registry.py,sha256=Ajk3SyMSKDi2g9SJYUtTgg7PZkAgydaHcpbGuEN3S94,311
67
- osbot_utils/helpers/Zip_Bytes.py,sha256=GQAwNEoMXdG7CU1RDhIJ51vkgfbJZnUxjlMUmFGHL1M,3937
67
+ osbot_utils/helpers/Zip_Bytes.py,sha256=d5hYXNOJkOaYa7h2CJ0Y3ojEuGTOvCxPuSic2quwMY4,4236
68
68
  osbot_utils/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
69
69
  osbot_utils/helpers/ast/Ast.py,sha256=lcPQOSxXI6zgmMnIVF9WM6ISqViWX-sq4d_UC0CDG8s,1155
70
70
  osbot_utils/helpers/ast/Ast_Base.py,sha256=5rHMupBlN_n6lOC31UnSW_lWqxqxaE31v0gn-t32OgQ,3708
@@ -144,8 +144,8 @@ osbot_utils/helpers/ast/nodes/Ast_Yield.py,sha256=7ATJnOHekV9XquMTYYSJ6xqyDvgwFc
144
144
  osbot_utils/helpers/ast/nodes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
145
145
  osbot_utils/helpers/cache_requests/Cache__Requests__Actions.py,sha256=r1CMR4qHO9is66lexJQ-BNUmBWcEjOSTG_qC0xsoorY,1228
146
146
  osbot_utils/helpers/cache_requests/Cache__Requests__Config.py,sha256=KxBjj56YTjZjKsO9TLsRfkcHYJPIGDXZ6rFskaNnh-4,935
147
- osbot_utils/helpers/cache_requests/Cache__Requests__Data.py,sha256=mx9mVGWwuixPxZmwU49Y4fUTfRaPNZosiX2PStaKBic,5284
148
- osbot_utils/helpers/cache_requests/Cache__Requests__Invoke.py,sha256=8sLJcLvxaHMnvD2gOL3kF3KR1dD2fIJq371SL9WNpRQ,2751
147
+ osbot_utils/helpers/cache_requests/Cache__Requests__Data.py,sha256=W0t4HyRgTTBbykBf_Ui9o84xLPu5ivreB-jSdOct1lc,5504
148
+ osbot_utils/helpers/cache_requests/Cache__Requests__Invoke.py,sha256=i8OiiA8afOnxVo_w9W8ySkMQygLAMMxDf3NAAmPCaE4,3348
149
149
  osbot_utils/helpers/cache_requests/Cache__Requests__Row.py,sha256=h-yc7NkpScbHwwf2km5wwKig-wLi4WuB9P4fVEdFGdM,3182
150
150
  osbot_utils/helpers/cache_requests/Cache__Requests__Table.py,sha256=RgxAYhm-FIrXXteQRtD91pOLq8JXhSzxb51Jb6MTUdY,391
151
151
  osbot_utils/helpers/cache_requests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -267,7 +267,7 @@ osbot_utils/utils/Csv.py,sha256=oHLVpjRJqrLMz9lubMCNEoThXWju5rNTprcwHc1zq2c,1012
267
267
  osbot_utils/utils/Dev.py,sha256=HibpQutYy_iG8gGV8g1GztxNN4l29E4Bi7UZaVL6-L8,1203
268
268
  osbot_utils/utils/Env.py,sha256=243O6ENzaRjHXp8DIHUuv4Wfk-zHTE18KZr0cU8uWyo,5474
269
269
  osbot_utils/utils/Exceptions.py,sha256=KyOUHkXQ_6jDTq04Xm261dbEZuRidtsM4dgzNwSG8-8,389
270
- osbot_utils/utils/Files.py,sha256=RHbxq8AVdGT9S-OrxEWhNEOhbIrHDRU1UbGB1O05Ga8,21615
270
+ osbot_utils/utils/Files.py,sha256=7W0FmxPvxOapUchEVOKDgUx4JBRs9TCesu60uKkvrto,21765
271
271
  osbot_utils/utils/Functions.py,sha256=0E6alPJ0fJpBiJgFOWooCOi265wSRyxxXAJ5CELBnso,3498
272
272
  osbot_utils/utils/Http.py,sha256=WlXEfgT_NaiDVD7vCDUxy_nOm5Qf8x_L0A3zd8B5tX8,4706
273
273
  osbot_utils/utils/Int.py,sha256=PmlUdU4lSwf4gJdmTVdqclulkEp7KPCVUDO6AcISMF4,116
@@ -284,10 +284,10 @@ osbot_utils/utils/Status.py,sha256=Yq4s0TelXgn0i2QjCP9V8mP30GabXp_UL-jjM6Iwiw4,4
284
284
  osbot_utils/utils/Str.py,sha256=kxdY8ROX4FdJtCaMTfOc8fK_xcDICprNkefHu2MMNU4,2585
285
285
  osbot_utils/utils/Toml.py,sha256=dqiegndCJF7V1YT1Tc-b0-Bl6QWyL5q30urmQwMXfMQ,1402
286
286
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
287
- osbot_utils/utils/Zip.py,sha256=t9txUxJzLBEHot6WJwF0iTTUQ1Gf_V2pVwsWzAqw_NU,12163
287
+ osbot_utils/utils/Zip.py,sha256=riPLKkZJxQjVu8lCm19cOTx5uiLPm1HreB9_BzNXi30,12209
288
288
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
289
- osbot_utils/version,sha256=bXbruCHeH-hb0hIQlj3n7tV2_vXn3ypQsk6TaP1y0Zk,8
290
- osbot_utils-1.32.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
291
- osbot_utils-1.32.0.dist-info/METADATA,sha256=B4r-4DcyCbnaGO-x7uJIrie537cYmE8Ux4hGFen0Wtc,1266
292
- osbot_utils-1.32.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
293
- osbot_utils-1.32.0.dist-info/RECORD,,
289
+ osbot_utils/version,sha256=6TnKtA5LdTAs5O7GY4t2C4qn-h6U96yDc0iddfveSQ8,8
290
+ osbot_utils-1.34.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
291
+ osbot_utils-1.34.0.dist-info/METADATA,sha256=PcsPtdbnPio1BPKI-PeNDxw91YQ4URN5xP0lOuPrj6g,1266
292
+ osbot_utils-1.34.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
293
+ osbot_utils-1.34.0.dist-info/RECORD,,