osbot-utils 1.37.0__py3-none-any.whl → 1.39.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.
@@ -26,6 +26,7 @@ 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
+ # todo: fix bug that happens when the value of reload_cache is set to False
29
30
  if 'reload_cache' in kwargs: # if the reload parameter is set to True
30
31
  reload_cache = True # set reload to True
31
32
  del kwargs['reload_cache'] # remove the reload parameter from the kwargs
@@ -0,0 +1,14 @@
1
+ # todo add to osbot utils
2
+ from osbot_utils.utils.Misc import random_guid
3
+
4
+ class Random_Guid(str):
5
+ def __new__(cls, value=None):
6
+ if value is None:
7
+ value = random_guid()
8
+ return str.__new__(cls, value)
9
+
10
+ def __init__(self, value=None):
11
+ self.value = value if value is not None else random_guid()
12
+
13
+ def __str__(self):
14
+ return self
@@ -8,11 +8,18 @@ class Temp_Env_Vars(Type_Safe):
8
8
  original_env_vars: dict
9
9
 
10
10
  def __enter__(self):
11
+ return self.set_vars()
12
+
13
+ def __exit__(self, exc_type, exc_value, traceback):
14
+ self.restore_vars()
15
+
16
+ def set_vars(self):
11
17
  for key, value in self.env_vars.items():
12
18
  self.original_env_vars[key] = os.environ.get(key) # Backup original environment variables and set new ones
13
19
  os.environ[key] = value
20
+ return self
14
21
 
15
- def __exit__(self, exc_type, exc_value, traceback):
22
+ def restore_vars(self):
16
23
  for key in self.env_vars: # Restore original environment variables
17
24
  if self.original_env_vars[key] is None:
18
25
  del os.environ[key]
@@ -489,6 +489,22 @@ 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]
494
+
495
+ def files_names_in_folder(target, with_extension=False):
496
+ if with_extension:
497
+ return files_names(files_in_folder(target))
498
+ else:
499
+ return files_names_without_extension(files_in_folder(target))
500
+
501
+ def files_in_folder(path,pattern='*', only_files=True):
502
+ result = []
503
+ for file in Path(path).glob(pattern):
504
+ if only_files and is_not_file(file):
505
+ continue
506
+ result.append(str(file)) # todo: see if there is a better way to do this conversion to string
507
+ return sorted(result)
492
508
 
493
509
  def folders_names_in_folder(target):
494
510
  folders = folders_in_folder(target)
@@ -93,6 +93,9 @@ def list_index_by(values, index_by):
93
93
  def list_lower(input_list):
94
94
  return [item.lower() for item in input_list]
95
95
 
96
+ def list_minus_list(list_a, list_b):
97
+ return [item for item in list_a if item not in list_b]
98
+
96
99
  def list_not_empty(list):
97
100
  if list and type(list).__name__ == 'list' and len(list) >0:
98
101
  return True
osbot_utils/utils/Misc.py CHANGED
@@ -8,6 +8,7 @@ import string
8
8
  import sys
9
9
  import textwrap
10
10
  import re
11
+ import threading
11
12
  import uuid
12
13
  import warnings
13
14
  from datetime import datetime, timedelta
@@ -67,6 +68,10 @@ def convert_to_number(value):
67
68
  else:
68
69
  return 0
69
70
 
71
+ def current_thread_id():
72
+ return threading.current_thread().native_id
73
+
74
+
70
75
  def date_time_from_to_str(date_time_str, format_from, format_to, print_conversion_error=False):
71
76
  try:
72
77
  date_time = datetime.strptime(date_time_str, format_from)
@@ -119,6 +124,9 @@ def date_time_now_less_time_delta(days=0,hours=0, minutes=0, seconds=0, date_tim
119
124
  def date_to_str(date, date_format='%Y-%m-%d'):
120
125
  return date.strftime(date_format)
121
126
 
127
+ def date_today():
128
+ return date_time_now(date_time_format='%Y-%m-%d')
129
+
122
130
  #note: this is here at the moment due to a circular dependency with lists and objects
123
131
  def list_set(target: object) -> object:
124
132
  if hasattr(target, '__iter__'):
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.37.0
1
+ v1.39.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.37.0
3
+ Version: 1.39.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.37.0-blue)
25
+ ![Current Release](https://img.shields.io/badge/release-v1.39.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
 
@@ -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=zhE1YoYma8eyx9i7dpTmpdrVzf5CkBJRe9aYok9xlgs,3527
21
+ osbot_utils/decorators/methods/cache_on_self.py,sha256=FODnv36jAwNPs11j2fGg6u-4A7MdaeRd1ES6fyPgP78,3611
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
@@ -62,6 +62,7 @@ osbot_utils/helpers/Local_Cache.py,sha256=0JZZX3fFImcwtbBvxAQl-EbBegSNJRhRMYF6ov
62
62
  osbot_utils/helpers/Local_Caches.py,sha256=aQmi1HSM0TH6WQPedG2fbz4KCCJ3DQTU9d18rB1jR0M,1885
63
63
  osbot_utils/helpers/Print_Table.py,sha256=LEXbyqGg_6WSraI4cob4bNNSu18ddqvALp1zGK7bPhs,19126
64
64
  osbot_utils/helpers/Python_Audit.py,sha256=shpZlluJwqJBAlad6xN01FkgC1TsQ48RLvR5ZjmrKa4,1539
65
+ osbot_utils/helpers/Random_Guid.py,sha256=_wlyM17SIr-FeYESwnVt4cfkEtRRf-dbYh_lTnrKVG0,379
65
66
  osbot_utils/helpers/Random_Seed.py,sha256=14btja8LDN9cMGWaz4fCNcMRU_eyx49gas-_PQvHgy4,634
66
67
  osbot_utils/helpers/Type_Registry.py,sha256=Ajk3SyMSKDi2g9SJYUtTgg7PZkAgydaHcpbGuEN3S94,311
67
68
  osbot_utils/helpers/Zip_Bytes.py,sha256=d5hYXNOJkOaYa7h2CJ0Y3ojEuGTOvCxPuSic2quwMY4,4236
@@ -252,7 +253,7 @@ osbot_utils/testing/Profiler.py,sha256=4em6Lpp0ONRDoDDCZsc_CdAOi_QolKOp4eA7KHN96
252
253
  osbot_utils/testing/Pytest.py,sha256=R3qdsIXGcNQcu7iobz0RB8AhbbHhc6t757tZoSZRrxA,730
253
254
  osbot_utils/testing/Stderr.py,sha256=ynf0Wle9NvgneLChzAxFBQ0QlE5sbri_fzJ8bEJMNkc,718
254
255
  osbot_utils/testing/Stdout.py,sha256=Gmxd_dOplXlucdSbOhYhka9sWP-Hmqb7ZuLs_JjtW7Y,592
255
- osbot_utils/testing/Temp_Env_Vars.py,sha256=oFuaegBlaV0aySkPe1Nzf-mdIKN03oTUKNfKijGz__M,751
256
+ osbot_utils/testing/Temp_Env_Vars.py,sha256=CE_lk54QcibkQVtIj2DrQPS3k2LgQZUctU5b-WwWvbo,884
256
257
  osbot_utils/testing/Temp_File.py,sha256=yZBL9MmcNU4PCQ4xlF4rSss4GylKoX3T_AJF-BlQhdI,1693
257
258
  osbot_utils/testing/Temp_Folder.py,sha256=Dbcohr2ciex6w-kB79R41Nuoa0pgpDbKtPGnlMmJ73k,5194
258
259
  osbot_utils/testing/Temp_Sys_Path.py,sha256=gOMD-7dQYQlejoDYUqsrmuZQ9DLC07ymPZB3zYuNmG4,256
@@ -268,14 +269,14 @@ osbot_utils/utils/Csv.py,sha256=oHLVpjRJqrLMz9lubMCNEoThXWju5rNTprcwHc1zq2c,1012
268
269
  osbot_utils/utils/Dev.py,sha256=HibpQutYy_iG8gGV8g1GztxNN4l29E4Bi7UZaVL6-L8,1203
269
270
  osbot_utils/utils/Env.py,sha256=9r1xxCDszX1UUOu0dy3Kf_djaU3I39xgB_QdC80Szdo,5669
270
271
  osbot_utils/utils/Exceptions.py,sha256=KyOUHkXQ_6jDTq04Xm261dbEZuRidtsM4dgzNwSG8-8,389
271
- osbot_utils/utils/Files.py,sha256=7W0FmxPvxOapUchEVOKDgUx4JBRs9TCesu60uKkvrto,21765
272
+ osbot_utils/utils/Files.py,sha256=z-egRBPDYp6AJkZxK-JnXOwz1OezgzEDG_fgSHVcCCM,22427
272
273
  osbot_utils/utils/Functions.py,sha256=0E6alPJ0fJpBiJgFOWooCOi265wSRyxxXAJ5CELBnso,3498
273
274
  osbot_utils/utils/Http.py,sha256=WlXEfgT_NaiDVD7vCDUxy_nOm5Qf8x_L0A3zd8B5tX8,4706
274
275
  osbot_utils/utils/Int.py,sha256=PmlUdU4lSwf4gJdmTVdqclulkEp7KPCVUDO6AcISMF4,116
275
276
  osbot_utils/utils/Json.py,sha256=UNaBazuH1R40fsHjpjuK8kmAANmUHoK9Q0PUeYmgPeY,6254
276
277
  osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
277
- osbot_utils/utils/Lists.py,sha256=CLEjgZwAixJAFlubWEKjnUUhUN85oqvR7UqExVW7rdY,5502
278
- osbot_utils/utils/Misc.py,sha256=AN-JTs9-Em2jVyoQ6Kd7dCA0eiqVQSlXajKjKxRAhyY,16639
278
+ osbot_utils/utils/Lists.py,sha256=tPz5x5s3sRO97WZ_nsxREBPC5cwaHrhgaYBhsrffTT8,5599
279
+ osbot_utils/utils/Misc.py,sha256=nODZT6p44B4xYiIiqfEeKYEErQiKR9SGthhGtZWGhkI,16804
279
280
  osbot_utils/utils/Objects.py,sha256=qAWNLISL-gYTl1Ihj4fBSZ9I6n-p-YPUhRZu9YQwqWQ,15235
280
281
  osbot_utils/utils/Png.py,sha256=V1juGp6wkpPigMJ8HcxrPDIP4bSwu51oNkLI8YqP76Y,1172
281
282
  osbot_utils/utils/Process.py,sha256=lr3CTiEkN3EiBx3ZmzYmTKlQoPdkgZBRjPulMxG-zdo,2357
@@ -287,8 +288,8 @@ osbot_utils/utils/Toml.py,sha256=dqiegndCJF7V1YT1Tc-b0-Bl6QWyL5q30urmQwMXfMQ,140
287
288
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
288
289
  osbot_utils/utils/Zip.py,sha256=riPLKkZJxQjVu8lCm19cOTx5uiLPm1HreB9_BzNXi30,12209
289
290
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
290
- osbot_utils/version,sha256=2lsyLVdcS9K9UON7nV7FJNEMLVIqIhp0nDRL0qX80gE,8
291
- osbot_utils-1.37.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
292
- osbot_utils-1.37.0.dist-info/METADATA,sha256=9xLglgYIN1kPnaGfr0hMSIVtvm7e_F9h9xEC-cttwAQ,1266
293
- osbot_utils-1.37.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
294
- osbot_utils-1.37.0.dist-info/RECORD,,
291
+ osbot_utils/version,sha256=fWfv3M5aLzIMdVIWJcenCiN596BO4a0gEyF73y5p_xY,8
292
+ osbot_utils-1.39.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
293
+ osbot_utils-1.39.0.dist-info/METADATA,sha256=SY4oAlcFR6WCUnCBX1Zq20PQ2sqLHpL2uQeTA3PuwuY,1266
294
+ osbot_utils-1.39.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
295
+ osbot_utils-1.39.0.dist-info/RECORD,,