osbot-utils 1.45.0__py3-none-any.whl → 1.47.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.
@@ -22,6 +22,7 @@ class Flow(Type_Safe):
22
22
  flow_id : str
23
23
  flow_name : str
24
24
  flow_config : Flow__Config
25
+ flow_error : Exception = None
25
26
  flow_target : callable
26
27
  flow_args : tuple
27
28
  flow_kwargs : dict
@@ -62,6 +63,7 @@ class Flow(Type_Safe):
62
63
  with Stdout() as stdout:
63
64
  self.flow_return_value = self.flow_target(*self.flow_args, **self.flow_kwargs) # todo, capture *args, **kwargs in logs
64
65
  except Exception as error:
66
+ self.flow_error = error
65
67
  self.logger.error(self.cformat.red(f"Error executing flow: {error}"))
66
68
 
67
69
  self.log_captured_stdout (stdout)
@@ -3,8 +3,8 @@ from typing import TypeVar, Callable, Any
3
3
 
4
4
  from osbot_utils.helpers.flows.Flow import Flow
5
5
 
6
- # todo: find way to make the casting below work for the users of this decorator
7
-
6
+ # todo: BUG find way to make the casting below work for the users of this decorator
7
+ # since at the moment we need to use: flow = cast(Flow, _.create_flow()) where create_flow is the method with the @flow decorator
8
8
  def flow(**flow_kwargs):
9
9
  def decorator(function) -> Flow:
10
10
  @wraps(function)
@@ -1,6 +1,7 @@
1
1
  import asyncio
2
2
  import logging
3
3
  import typing
4
+ from concurrent.futures import ThreadPoolExecutor
4
5
 
5
6
  def invoke_async_function(target: typing.Coroutine):
6
7
  """Run an asynchronous coroutine in a new event loop."""
@@ -24,4 +25,21 @@ def invoke_async_function(target: typing.Coroutine):
24
25
  else:
25
26
  asyncio.set_event_loop(None)
26
27
 
27
- logger.level = level_original # restore the original log level
28
+ logger.level = level_original # restore the original log level
29
+
30
+
31
+ def invoke_in_new_event_loop(target: typing.Coroutine): # Runs a coroutine in a new event loop in a separate thread and returns the result
32
+ def run_in_new_loop(): # Function to run the coroutine in a new event loop
33
+ new_loop = asyncio.new_event_loop() # Create a new event loop
34
+ asyncio.set_event_loop(new_loop) # Set the new event loop as the current event loop
35
+ try:
36
+ return new_loop.run_until_complete(target) # Run the coroutine in the new event loop
37
+ finally:
38
+ new_loop.close() # Close the event loop to free resources
39
+
40
+ with ThreadPoolExecutor() as pool: # Create a thread pool executor
41
+ future = pool.submit(run_in_new_loop) # Submit the function to run in the thread pool
42
+ result = future.result() # Wait for the result of the future
43
+ return result # Return the result from the coroutine
44
+
45
+ async_invoke_in_new_loop = invoke_in_new_event_loop
osbot_utils/utils/Toml.py CHANGED
@@ -43,5 +43,5 @@ def toml_to_dict(str_toml):
43
43
  raise NotImplementedError("TOML parsing is not supported in Python versions earlier than 3.11")
44
44
  return tomllib.loads(str_toml)
45
45
 
46
-
46
+ json_load_file = toml_dict_from_file
47
47
  toml_file_load = toml_dict_from_file
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.45.0
1
+ v1.47.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.45.0
3
+ Version: 1.47.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.45.0-blue)
25
+ ![Current Release](https://img.shields.io/badge/release-v1.47.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
 
@@ -154,12 +154,12 @@ osbot_utils/helpers/cache_requests/Cache__Requests__Row.py,sha256=h-yc7NkpScbHww
154
154
  osbot_utils/helpers/cache_requests/Cache__Requests__Table.py,sha256=RgxAYhm-FIrXXteQRtD91pOLq8JXhSzxb51Jb6MTUdY,391
155
155
  osbot_utils/helpers/cache_requests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
156
156
  osbot_utils/helpers/cache_requests/flows/flow__Cache__Requests.py,sha256=xgx_oExxkcvRwQN1UCobimECIMUKGoIX5oGdCmp8Nyw,243
157
- osbot_utils/helpers/flows/Flow.py,sha256=_93-0FpH_bq7j--6DvKW7n2YC6hU_tINx8YMvMX4_uM,5659
157
+ osbot_utils/helpers/flows/Flow.py,sha256=hVIjIzotQyHc4Ms0K_Rh1Jtb5rg1zYWdfaUnBROLYxI,5747
158
158
  osbot_utils/helpers/flows/Flow__Config.py,sha256=PE8hH8KXDHz1Ex93cPMuR9nkv8AoXzXQwVxleSDkU7k,341
159
159
  osbot_utils/helpers/flows/Task.py,sha256=edbvtd78kzz5ghKp-awyOWop2QYxqDB0-aupcz0sjVM,3530
160
160
  osbot_utils/helpers/flows/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
161
161
  osbot_utils/helpers/flows/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
162
- osbot_utils/helpers/flows/decorators/flow.py,sha256=7H9NXR7416BCBC-2wgQz7KCA0_d8I0gZbxSyxcL4khQ,595
162
+ osbot_utils/helpers/flows/decorators/flow.py,sha256=LUL7bHjZ_lC3QoTNh-KsDZHzjE2u4mU-5EpZnfsEGuc,738
163
163
  osbot_utils/helpers/flows/decorators/task.py,sha256=2Eg8abx7ky8PVKVQijy6Oji60UKW31nXmtYftqBDB0k,394
164
164
  osbot_utils/helpers/html/Dict_To_Css.py,sha256=u6B4Mx7PXr-gDrTrs1hgknnvsZVK4Fic5LqedKjo-lk,1097
165
165
  osbot_utils/helpers/html/Dict_To_Html.py,sha256=OlRSaDGOeseBNTxRB2ho5whqEacMXeAXWOfeVSEYqC4,3355
@@ -292,13 +292,13 @@ osbot_utils/utils/Python_Logger.py,sha256=tx8N6wRKL3RDHboDRKZn8SirSJdSAE9cACyJkx
292
292
  osbot_utils/utils/Regex.py,sha256=0ubgp8HKsS3PNe2H6XlzMIcUuV7jhga3VkQVDNOJWuA,866
293
293
  osbot_utils/utils/Status.py,sha256=Yq4s0TelXgn0i2QjCP9V8mP30GabXp_UL-jjM6Iwiw4,4305
294
294
  osbot_utils/utils/Str.py,sha256=kxdY8ROX4FdJtCaMTfOc8fK_xcDICprNkefHu2MMNU4,2585
295
- osbot_utils/utils/Threads.py,sha256=fgFrZZXY2G9yJmfQcOv76GB_8MhCrvoUdcbkAhYxDBI,909
296
- osbot_utils/utils/Toml.py,sha256=dqiegndCJF7V1YT1Tc-b0-Bl6QWyL5q30urmQwMXfMQ,1402
295
+ osbot_utils/utils/Threads.py,sha256=RB6NNPqQxbmGwoaQ2OzkY4vyjVq6pzN2OjB6Y7SBILo,2175
296
+ osbot_utils/utils/Toml.py,sha256=SD6IA4-mrtoBXcI0dIGKV9POMQNd6WYKvmDQq7GQ6ZQ,1438
297
297
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
298
298
  osbot_utils/utils/Zip.py,sha256=G6Hk_hDcm9yvWzhTKzhT0R_6f0NBIAchHqMxGb3kfh4,14037
299
299
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
300
- osbot_utils/version,sha256=8XvA-W5tRj_AQS8FtlMP3PtCMBpTiglUjp-DGhdTGZY,8
301
- osbot_utils-1.45.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
302
- osbot_utils-1.45.0.dist-info/METADATA,sha256=CZxciwssi8uAl_O1N7wfuoPBMeg3x8e5G6qjieln_Ac,1266
303
- osbot_utils-1.45.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
304
- osbot_utils-1.45.0.dist-info/RECORD,,
300
+ osbot_utils/version,sha256=ybXNKWCKaEXFNoc6Pk5GIikdkvQM-RC7qdKIjQo88V4,8
301
+ osbot_utils-1.47.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
302
+ osbot_utils-1.47.0.dist-info/METADATA,sha256=A3c6zDzb3VAaDjlh9lsrfUAupaukx_cIAnRcNwoDpes,1266
303
+ osbot_utils-1.47.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
304
+ osbot_utils-1.47.0.dist-info/RECORD,,