osbot-utils 1.67.0__py3-none-any.whl → 1.69.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.
@@ -14,9 +14,9 @@ from osbot_utils.helpers.Random_Guid import Random_Guid
14
14
  from osbot_utils.helpers.Random_Guid_Short import Random_Guid_Short
15
15
  from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
16
16
  from osbot_utils.utils.Dev import pprint
17
- from osbot_utils.utils.Json import json_parse
17
+ from osbot_utils.utils.Json import json_parse, json_to_bytes, json_to_gz
18
18
  from osbot_utils.utils.Misc import list_set
19
- from osbot_utils.utils.Objects import default_value, value_type_matches_obj_annotation_for_attr, \
19
+ from osbot_utils.utils.Objects import default_value, value_type_matches_obj_annotation_for_attr, \
20
20
  raise_exception_on_obj_type_annotation_mismatch, obj_is_attribute_annotation_of_type, enum_from_value, \
21
21
  obj_is_type_union_compatible, value_type_matches_obj_annotation_for_union_attr, \
22
22
  convert_dict_to_value_from_obj_annotation, dict_to_obj, convert_to_value_from_obj_annotation
@@ -230,9 +230,16 @@ class Type_Safe:
230
230
  # global methods added to any class that base classes this
231
231
  # todo: see if there should be a prefix on these methods, to make it easier to spot them
232
232
  # of if these are actually that useful that they should be added like this
233
+ def bytes(self):
234
+ return json_to_bytes(self.json())
235
+
236
+ def bytes_gz(self):
237
+ return json_to_gz(self.json())
238
+
233
239
  def json(self):
234
240
  return self.serialize_to_dict()
235
241
 
242
+
236
243
  def merge_with(self, target):
237
244
  original_attrs = {k: v for k, v in self.__dict__.items() if k not in target.__dict__} # Store the original attributes of self that should be retained.
238
245
  self.__dict__ = target.__dict__ # Set the target's __dict__ to self, now self and target share the same __dict__.
osbot_utils/utils/Http.py CHANGED
@@ -4,9 +4,10 @@ import re
4
4
  import socket
5
5
  import ssl
6
6
  import unicodedata
7
- from time import sleep
8
- from urllib.parse import quote, urljoin, urlparse, urlunparse
9
- from urllib.request import Request, urlopen
7
+ from http.cookies import SimpleCookie
8
+ from time import sleep
9
+ from urllib.parse import quote, urljoin, urlparse, urlunparse
10
+ from urllib.request import Request, urlopen
10
11
 
11
12
  from osbot_utils.utils.Str import html_decode
12
13
 
@@ -78,6 +79,24 @@ def http_request(url, data=None, headers=None, method='GET', encoding ='utf-8',
78
79
  return result.decode(encoding)
79
80
  return result
80
81
 
82
+
83
+ def parse_cookies(cookie_header, include_empty=True):
84
+ cookie = SimpleCookie()
85
+ cookie.load(cookie_header)
86
+ parsed_cookies = {}
87
+ for key, morsel in cookie.items():
88
+ cookie_attrs = {"value": morsel.value}
89
+ for attr, value in morsel.items():
90
+ if attr.lower() in ["secure", "httponly"]:
91
+ cookie_attrs[attr] = (value == True)
92
+ else:
93
+ if value or include_empty:
94
+ cookie_attrs[attr] = value.strip(', ') # we need to strip for the cases when there are multiple cookies split by , (as seen in FastAPI Test Client)
95
+ parsed_cookies[key] = cookie_attrs
96
+
97
+ return parsed_cookies
98
+
99
+
81
100
  def port_is_not_open(port, host='0.0.0.0', timeout=1.0):
82
101
  return port_is_open(port, host,timeout) is False
83
102
 
osbot_utils/utils/Json.py CHANGED
@@ -5,6 +5,8 @@ from osbot_utils.utils.Misc import str_lines, str_md5, str_sha256
5
5
  from osbot_utils.utils.Files import file_create_gz, file_create, load_file_gz, file_contents, file_lines, file_lines_gz
6
6
  from osbot_utils.utils.Zip import str_to_gz, gz_to_str
7
7
 
8
+ def bytes_to_json_loads(data):
9
+ return json.loads(data.decode())
8
10
 
9
11
  def json_dumps(python_object, indent=4, pretty=True, sort_keys=False, default=str, raise_exception=False):
10
12
  if python_object:
@@ -135,6 +137,7 @@ class Json:
135
137
  def json_save_tmp_file(python_object, pretty=True):
136
138
  return Json.save_file(python_object=python_object, pretty=pretty, path=None)
137
139
 
140
+ bytes_to_json = bytes_to_json_loads
138
141
  file_create_json = Json.save_file_pretty
139
142
  file_contents_json = Json.load_file
140
143
 
@@ -158,6 +161,7 @@ json_md5 = Json.md5
158
161
  json_lines_loads = Json.loads_json_lines
159
162
  json_parse = Json.loads
160
163
  json_lines_parse = Json.loads_json_lines
164
+ json_to_bytes = json_dumps_to_bytes
161
165
  json_to_str = json_dumps
162
166
  json_round_trip = Json.round_trip
163
167
  json_save = Json.save_file
osbot_utils/utils/Toml.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import sys
2
-
3
- from osbot_utils.utils.Files import file_create, file_contents
2
+ from osbot_utils.utils.Files import file_create, file_contents
3
+ from osbot_utils.utils.Objects import dict_to_obj
4
4
 
5
5
  if sys.version_info >= (3, 11):
6
6
  import tomllib
@@ -43,5 +43,11 @@ 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
+ def toml_obj_from_file(toml_file):
47
+ data = toml_dict_from_file(toml_file)
48
+ return dict_to_obj(data)
49
+
46
50
  json_load_file = toml_dict_from_file
47
- toml_file_load = toml_dict_from_file
51
+ toml_file_load = toml_dict_from_file
52
+ toml_load = toml_dict_from_file
53
+ toml_load_obj = toml_obj_from_file
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.67.0
1
+ v1.69.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.67.0
3
+ Version: 1.69.0
4
4
  Summary: OWASP Security Bot - Utils
5
5
  Home-page: https://github.com/owasp-sbot/OSBot-Utils
6
6
  License: MIT
@@ -23,7 +23,7 @@ Description-Content-Type: text/markdown
23
23
 
24
24
  Powerful Python util methods and classes that simplify common apis and tasks.
25
25
 
26
- ![Current Release](https://img.shields.io/badge/release-v1.67.0-blue)
26
+ ![Current Release](https://img.shields.io/badge/release-v1.69.0-blue)
27
27
  [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
28
28
 
29
29
 
@@ -2,7 +2,7 @@ osbot_utils/__init__.py,sha256=DdJDmQc9zbQUlPVyTJOww6Ixrn9n4bD3ami5ItQfzJI,16
2
2
  osbot_utils/base_classes/Cache_Pickle.py,sha256=kPCwrgUbf_dEdxUz7vW1GuvIPwlNXxuRhb-H3AbSpII,5884
3
3
  osbot_utils/base_classes/Kwargs_To_Disk.py,sha256=HHoy05NC_w35WcT-OnSKoSIV_cLqaU9rdjH0_KNTM0E,1096
4
4
  osbot_utils/base_classes/Kwargs_To_Self.py,sha256=weFNsBfBNV9W_qBkN-IdBD4yYcJV_zgTxBRO-ZlcPS4,141
5
- osbot_utils/base_classes/Type_Safe.py,sha256=N1RMyDEA9YFI5MciixobxM0ZjbEQpPtj8XzmzTrPTls,18789
5
+ osbot_utils/base_classes/Type_Safe.py,sha256=D8hxrU8LhuzZCuvijfYsLZzOWkQvIP5bxWtDjx-KB20,18962
6
6
  osbot_utils/base_classes/Type_Safe__List.py,sha256=-80C9OhsK6iDR2dAG8yNLAZV0qg5x3faqvSUigFCMJw,517
7
7
  osbot_utils/base_classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  osbot_utils/context_managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -287,9 +287,9 @@ osbot_utils/utils/Env.py,sha256=XMwF5BrtpoPJdOraswAFPrcQ3tRTocjqvA8I61eOCJw,5741
287
287
  osbot_utils/utils/Exceptions.py,sha256=KyOUHkXQ_6jDTq04Xm261dbEZuRidtsM4dgzNwSG8-8,389
288
288
  osbot_utils/utils/Files.py,sha256=7fdqbfFyo6Ow5Repi_dZAzHqGb0XYh6tDALYAy42pBY,22522
289
289
  osbot_utils/utils/Functions.py,sha256=0E6alPJ0fJpBiJgFOWooCOi265wSRyxxXAJ5CELBnso,3498
290
- osbot_utils/utils/Http.py,sha256=vFvD-xLkkXLTJvmYGourMLoUOfkZx_KBSLmo1RX73jM,7043
290
+ osbot_utils/utils/Http.py,sha256=Cm_-b2EgxKoQJ47ThZp-dgHCdeGv4UcCNLfTOH94-7s,7790
291
291
  osbot_utils/utils/Int.py,sha256=PmlUdU4lSwf4gJdmTVdqclulkEp7KPCVUDO6AcISMF4,116
292
- osbot_utils/utils/Json.py,sha256=yIT2hUI23gYd24Uf3LCjqPNV67zS46rYZftcCM3jw-Q,6492
292
+ osbot_utils/utils/Json.py,sha256=8fpYFXzNPSrwYfXMt3eGKpe-lhxh1kEaCRae1X1943A,6662
293
293
  osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
294
294
  osbot_utils/utils/Lists.py,sha256=tPz5x5s3sRO97WZ_nsxREBPC5cwaHrhgaYBhsrffTT8,5599
295
295
  osbot_utils/utils/Misc.py,sha256=4MkG2BE1VzZfV4KPzYZ4jVAoUwoA3pTTVPi609ldLGA,16961
@@ -301,12 +301,12 @@ osbot_utils/utils/Regex.py,sha256=0ubgp8HKsS3PNe2H6XlzMIcUuV7jhga3VkQVDNOJWuA,86
301
301
  osbot_utils/utils/Status.py,sha256=Yq4s0TelXgn0i2QjCP9V8mP30GabXp_UL-jjM6Iwiw4,4305
302
302
  osbot_utils/utils/Str.py,sha256=kxdY8ROX4FdJtCaMTfOc8fK_xcDICprNkefHu2MMNU4,2585
303
303
  osbot_utils/utils/Threads.py,sha256=lnh4doZWYUIoWBZRU_780QPeAIKGDh7INuqmU8Fzmdc,3042
304
- osbot_utils/utils/Toml.py,sha256=SD6IA4-mrtoBXcI0dIGKV9POMQNd6WYKvmDQq7GQ6ZQ,1438
304
+ osbot_utils/utils/Toml.py,sha256=-_Yv5T8ZhGGoDSSoNEdFhSsXiK_JPjGkPijm4JoeHSk,1669
305
305
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
306
306
  osbot_utils/utils/Zip.py,sha256=G6Hk_hDcm9yvWzhTKzhT0R_6f0NBIAchHqMxGb3kfh4,14037
307
307
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
308
- osbot_utils/version,sha256=zEYoXcLqYMMeBwLqI0fFRz3qocsd0oEVjcyEHe-v6Hs,8
309
- osbot_utils-1.67.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
310
- osbot_utils-1.67.0.dist-info/METADATA,sha256=vuHI4ctcabSC0_5MA-3_NoSvc8Bd8TNXRoZoutsRYCk,1317
311
- osbot_utils-1.67.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
312
- osbot_utils-1.67.0.dist-info/RECORD,,
308
+ osbot_utils/version,sha256=uFIGtf3R9DfyFN5OlM7YUkWOP1gOA1X0TI8thjX5L24,8
309
+ osbot_utils-1.69.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
310
+ osbot_utils-1.69.0.dist-info/METADATA,sha256=Anbjvy6tfA7jEncTOegpC9l05QWOsbiQxFtKm6gLJAg,1317
311
+ osbot_utils-1.69.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
312
+ osbot_utils-1.69.0.dist-info/RECORD,,