osbot-utils 1.30.0__py3-none-any.whl → 1.31.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/utils/Env.py CHANGED
@@ -6,14 +6,28 @@ 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 env__home_root(): # todo: this should be refatored to be env__home__is__root
9
+
10
+ def env__home():
11
+ return get_env('HOME', '')
12
+
13
+ def env__home__is__root():
10
14
  return os.getenv('HOME') == '/root'
11
15
 
12
- def env__terminal_xterm(): # todo: this should be refatored to be env__terminal__is__xterm
16
+ def env__old_pwd():
17
+ return get_env('OLDPWD', '')
18
+
19
+ def env__pwd():
20
+ return get_env('PWD', '')
21
+
22
+ def env__old_pwd__remove(value):
23
+ return value.replace(env__old_pwd(), '')
24
+
25
+ def env__terminal__is__xterm():
13
26
  return os.getenv('TERM') == 'xterm'
14
27
 
15
- def env__not_terminal_xterm():
16
- return not env__terminal_xterm()
28
+ def env__terminal__is_not__xterm():
29
+ return not env__terminal__is__xterm()
30
+
17
31
 
18
32
  def platform_darwin():
19
33
  return platform == 'darwin'
@@ -21,6 +35,10 @@ def platform_darwin():
21
35
  def env_value(var_name):
22
36
  return env_vars().get(var_name, None)
23
37
 
38
+ def env_var_set(var_name):
39
+ value = os.getenv(var_name)
40
+ return value is not None and value != ''
41
+
24
42
  def env_vars_list():
25
43
  return list_set(env_vars())
26
44
 
@@ -109,6 +127,6 @@ def unload_dotenv(dotenv_path=None):
109
127
  env_unload_from_file(env_path) # Process it
110
128
  break # Stop after unloading the first .env file
111
129
 
112
-
113
- env_load = load_dotenv
114
- get_env = os.getenv
130
+ is_env_var_set = env_var_set
131
+ env_load = load_dotenv
132
+ get_env = os.getenv
@@ -340,6 +340,8 @@ class Files:
340
340
  def parent_folder_combine(file, path):
341
341
  return Files.path_combine(os.path.dirname(file),path)
342
342
 
343
+
344
+
343
345
  @staticmethod
344
346
  def pickle_save_to_file(object_to_save, path=None):
345
347
  path = path or temp_file(extension=".pickle")
@@ -491,12 +493,26 @@ def folders_names_in_folder(target):
491
493
  folders = folders_in_folder(target)
492
494
  return folders_names(folders)
493
495
 
496
+ def path_combine_safe(base_path, file_location, raise_exception=False): # handle possible directory transversal attacks
497
+ full_path = os.path.join(base_path, file_location) # Combine and normalize paths
498
+ normalised_base_path = os.path.normpath(base_path)
499
+ normalised_full_path = os.path.normpath(full_path)
500
+
501
+ if os.path.commonpath([normalised_base_path, normalised_full_path]) == normalised_base_path: # Check for directory traversal
502
+ return normalised_full_path
503
+ if raise_exception:
504
+ raise ValueError("Invalid file location: directory traversal attempt detected.")
505
+ return None
506
+
494
507
  def parent_folder_create(target):
495
508
  return folder_create(parent_folder(target))
496
509
 
497
510
  def parent_folder_exists(target):
498
511
  return folder_exists(parent_folder(target))
499
512
 
513
+ def parent_folder_name(target):
514
+ return folder_name(parent_folder(target))
515
+
500
516
  def parent_folder_not_exists(target):
501
517
  return parent_folder_exists(target) is False
502
518
 
osbot_utils/utils/Http.py CHANGED
@@ -22,6 +22,13 @@ def current_host_online(url_to_use=URL_CHECK_HOST_ONLINE):
22
22
  def dns_ip_address(host):
23
23
  return socket.gethostbyname(host)
24
24
 
25
+ def is_url_online(target):
26
+ try:
27
+ http_request(target, method='HEAD')
28
+ return True
29
+ except:
30
+ return False
31
+
25
32
  def is_port_open(host, port, timeout=0.5):
26
33
  return port_is_open(host=host, port=port, timeout=timeout)
27
34
 
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.30.0
1
+ v1.31.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.30.0
3
+ Version: 1.31.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.30.0-blue)
25
+ ![Current Release](https://img.shields.io/badge/release-v1.31.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
 
@@ -265,11 +265,11 @@ osbot_utils/utils/Assert.py,sha256=u9XLgYn91QvNWZGyPi29SjPJSXRHlm9andIn3NJEVog,1
265
265
  osbot_utils/utils/Call_Stack.py,sha256=MAq_0vMxnbeLfCe9qQz7GwJYaOuXpt3qtQwN6wiXsU0,6595
266
266
  osbot_utils/utils/Csv.py,sha256=oHLVpjRJqrLMz9lubMCNEoThXWju5rNTprcwHc1zq2c,1012
267
267
  osbot_utils/utils/Dev.py,sha256=HibpQutYy_iG8gGV8g1GztxNN4l29E4Bi7UZaVL6-L8,1203
268
- osbot_utils/utils/Env.py,sha256=Pbel6npitij9zag6SsWdPVH2j1BTZjxnwOR1vLiIyMo,5248
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=bZFvjyC4TAmFH6RSp3Xvj_xBxfybCT2cE7x2qNTQmeE,20834
270
+ osbot_utils/utils/Files.py,sha256=RHbxq8AVdGT9S-OrxEWhNEOhbIrHDRU1UbGB1O05Ga8,21615
271
271
  osbot_utils/utils/Functions.py,sha256=0E6alPJ0fJpBiJgFOWooCOi265wSRyxxXAJ5CELBnso,3498
272
- osbot_utils/utils/Http.py,sha256=Z8V149M2HDrKBoXkDD5EXgqTGx6vQoUqXugXK__wcuw,4572
272
+ osbot_utils/utils/Http.py,sha256=WlXEfgT_NaiDVD7vCDUxy_nOm5Qf8x_L0A3zd8B5tX8,4706
273
273
  osbot_utils/utils/Int.py,sha256=PmlUdU4lSwf4gJdmTVdqclulkEp7KPCVUDO6AcISMF4,116
274
274
  osbot_utils/utils/Json.py,sha256=UNaBazuH1R40fsHjpjuK8kmAANmUHoK9Q0PUeYmgPeY,6254
275
275
  osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
@@ -286,8 +286,8 @@ osbot_utils/utils/Toml.py,sha256=dqiegndCJF7V1YT1Tc-b0-Bl6QWyL5q30urmQwMXfMQ,140
286
286
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
287
287
  osbot_utils/utils/Zip.py,sha256=t9txUxJzLBEHot6WJwF0iTTUQ1Gf_V2pVwsWzAqw_NU,12163
288
288
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
289
- osbot_utils/version,sha256=rySeFYh2TX0iwzR0MwppiJ1yllnTK1JQxMRPUGe8DS0,8
290
- osbot_utils-1.30.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
291
- osbot_utils-1.30.0.dist-info/METADATA,sha256=XspSKWOcbtP6-hGL3r9N7NmMZn7n91lK68mf8vPxetI,1266
292
- osbot_utils-1.30.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
293
- osbot_utils-1.30.0.dist-info/RECORD,,
289
+ osbot_utils/version,sha256=xqw0vpyVEQS2xRHlm1kwNututCAIDLAR7pKKQAdsSZo,8
290
+ osbot_utils-1.31.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
291
+ osbot_utils-1.31.0.dist-info/METADATA,sha256=QLHGRLf7-AaRW446YXqvjj86DdwwGuZgC-TeaEgwPTI,1266
292
+ osbot_utils-1.31.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
293
+ osbot_utils-1.31.0.dist-info/RECORD,,