osbot-utils 1.46.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.
@@ -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.46.0
1
+ v1.47.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.46.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.46.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
 
@@ -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=2UVhPxE0DB52FVzBzTdqVU8YPmmHK5prh4BaymedynQ,8
301
- osbot_utils-1.46.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
302
- osbot_utils-1.46.0.dist-info/METADATA,sha256=QbqZVF7WvOz21zrolLt3nURWtjuMBHQY18RcXUkb01c,1266
303
- osbot_utils-1.46.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
304
- osbot_utils-1.46.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,,