osbot-utils 2.65.0__py3-none-any.whl → 2.67.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/base_classes/Kwargs_To_Disk.py +1 -1
- osbot_utils/helpers/pubsub/PubSub__Sqlite.py +1 -1
- osbot_utils/helpers/safe_str/Safe_Str__Hash.py +10 -3
- osbot_utils/helpers/sqlite/cache/Sqlite__DB__Requests.py +1 -1
- osbot_utils/type_safe/Type_Safe__Method.py +2 -1
- osbot_utils/type_safe/decorators/type_safe.py +2 -0
- osbot_utils/type_safe/steps/Type_Safe__Step__Set_Attr.py +20 -0
- osbot_utils/version +1 -1
- {osbot_utils-2.65.0.dist-info → osbot_utils-2.67.0.dist-info}/METADATA +2 -2
- {osbot_utils-2.65.0.dist-info → osbot_utils-2.67.0.dist-info}/RECORD +12 -12
- {osbot_utils-2.65.0.dist-info → osbot_utils-2.67.0.dist-info}/LICENSE +0 -0
- {osbot_utils-2.65.0.dist-info → osbot_utils-2.67.0.dist-info}/WHEEL +0 -0
@@ -20,7 +20,7 @@ class Kwargs_To_Disk:
|
|
20
20
|
else:
|
21
21
|
self._local_cache.set(key, value)
|
22
22
|
|
23
|
-
def _cache_create (self): return self._local_cache.create
|
23
|
+
def _cache_create (self): return self._local_cache.create()
|
24
24
|
def _cache_delete (self): return self._local_cache.cache_delete ()
|
25
25
|
def _cache_data (self): return self._local_cache.data ()
|
26
26
|
def _cache_exists (self): return self._local_cache.cache_exists ()
|
@@ -15,7 +15,7 @@ class PubSub__Sqlite(Sqlite__Database):
|
|
15
15
|
with self.table_clients() as _:
|
16
16
|
_.row_schema = TABLE_SCHEMA__PUB_SUB__CLIENTS
|
17
17
|
if _.exists() is False:
|
18
|
-
_.create()
|
18
|
+
_.create() # create if it doesn't exist
|
19
19
|
return True
|
20
20
|
return False
|
21
21
|
|
@@ -1,6 +1,7 @@
|
|
1
1
|
import re
|
2
|
+
from typing import Any
|
2
3
|
from osbot_utils.helpers.safe_str.Safe_Str import Safe_Str
|
3
|
-
from osbot_utils.utils.Misc import
|
4
|
+
from osbot_utils.utils.Misc import bytes_md5
|
4
5
|
|
5
6
|
# Constants for hash validation
|
6
7
|
SIZE__VALUE_HASH = 10
|
@@ -14,5 +15,11 @@ class Safe_Str__Hash(Safe_Str):
|
|
14
15
|
strict_validation = True # Enable strict validation - new attribute
|
15
16
|
exact_length = True # Require exact length match - new attribute
|
16
17
|
|
17
|
-
def safe_str_hash(value
|
18
|
-
|
18
|
+
def safe_str_hash(value: Any) -> Safe_Str__Hash:
|
19
|
+
if isinstance(value, str):
|
20
|
+
value = value.encode()
|
21
|
+
elif not isinstance(value, bytes):
|
22
|
+
raise ValueError('In safe_str_hash, value must be a string or bytes')
|
23
|
+
|
24
|
+
hash_value = bytes_md5(value)[0:SIZE__VALUE_HASH]
|
25
|
+
return Safe_Str__Hash(hash_value)
|
@@ -26,7 +26,7 @@ class Sqlite__DB__Requests(Sqlite__DB__Local):
|
|
26
26
|
with self.table_requests() as _:
|
27
27
|
_.row_schema = self.table_schema # set the table_class
|
28
28
|
if _.exists() is False:
|
29
|
-
_.create()
|
29
|
+
_.create() # create if it doesn't exist
|
30
30
|
_.index_create('request_hash') # add index to the request_hash field
|
31
31
|
return True
|
32
32
|
return False
|
@@ -93,7 +93,8 @@ class Type_Safe__Method:
|
|
93
93
|
self.sig.parameters[param_name].default is not inspect._empty) # Check has non-empty default
|
94
94
|
|
95
95
|
def validate_none_value(self, param_name: str, # Validate None value
|
96
|
-
|
96
|
+
is_optional: bool,
|
97
|
+
has_default: bool):
|
97
98
|
if not (is_optional or has_default): # If neither optional nor default
|
98
99
|
raise ValueError(f"Parameter '{param_name}' is not optional but got None") # Raise error for None value
|
99
100
|
|
@@ -7,6 +7,8 @@ def type_safe(func):
|
|
7
7
|
has_only_self = len(type_checker.params) == 1 and type_checker.params[0] == 'self' # Check if method has only 'self' parameter or no parameters
|
8
8
|
has_no_params = len(type_checker.params) == 0
|
9
9
|
direct_execution = has_no_params or has_only_self # these are major performance optimisation where this @type_safe had an overhead of 250x (even on methods with no params) to now having an over head of ~5x
|
10
|
+
if direct_execution: # todo: review if we really need to do this, since although it is an optimisation, the idea of the type_safe attribute is to check when there are params
|
11
|
+
return func
|
10
12
|
|
11
13
|
@functools.wraps(func) # Preserve function metadata
|
12
14
|
def wrapper(*args, **kwargs): # Wrapper function
|
@@ -1,4 +1,5 @@
|
|
1
1
|
from typing import get_origin, Annotated, get_args
|
2
|
+
from osbot_utils.type_safe.Type_Safe__List import Type_Safe__List
|
2
3
|
from osbot_utils.type_safe.Type_Safe__Primitive import Type_Safe__Primitive
|
3
4
|
from osbot_utils.type_safe.shared.Type_Safe__Cache import type_safe_cache
|
4
5
|
from osbot_utils.type_safe.shared.Type_Safe__Convert import type_safe_convert
|
@@ -10,6 +11,8 @@ class Type_Safe__Step__Set_Attr:
|
|
10
11
|
def resolve_value(self, _self, annotations, name, value):
|
11
12
|
if type(value) is dict:
|
12
13
|
value = self.resolve_value__dict(_self, name, value)
|
14
|
+
elif type(value) is list:
|
15
|
+
value = self.resolve_value__list(_self, name, value)
|
13
16
|
elif isinstance(annotations.get(name), type) and issubclass(annotations.get(name), Type_Safe__Primitive) and type(value) in (int, str, float):
|
14
17
|
return annotations.get(name)(value)
|
15
18
|
elif type(value) in (int, str): # for now only a small number of str and int classes are supported (until we understand the full implications of this)
|
@@ -31,6 +34,23 @@ class Type_Safe__Step__Set_Attr:
|
|
31
34
|
|
32
35
|
return type_safe_convert.convert_to_value_from_obj_annotation(_self, name, value)
|
33
36
|
|
37
|
+
def resolve_value__list(self, _self, name, value): # Convert regular lists to Type_Safe__List instances
|
38
|
+
annotations = type_safe_cache.get_obj_annotations(_self)
|
39
|
+
annotation = annotations.get(name)
|
40
|
+
|
41
|
+
if annotation:
|
42
|
+
origin = type_safe_cache.get_origin(annotation)
|
43
|
+
if origin is list:
|
44
|
+
args = get_args(annotation) # Get the list element type
|
45
|
+
if args:
|
46
|
+
element_type = args[0]
|
47
|
+
|
48
|
+
type_safe_list = Type_Safe__List(element_type) # Create a Type_Safe__List with the expected type
|
49
|
+
for item in value: # Validate and add each element
|
50
|
+
type_safe_list.append(item) # This will validate the type
|
51
|
+
return type_safe_list
|
52
|
+
|
53
|
+
return value
|
34
54
|
def resolve_value__from_origin(self, value):
|
35
55
|
#origin = type_safe_cache.get_origin(value) # todo: figure out why this is the only place that the type_safe_cache.get_origin doesn't work (due to WeakKeyDictionary key error on value)
|
36
56
|
origin = get_origin(value)
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v2.
|
1
|
+
v2.67.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.67.0
|
4
4
|
Summary: OWASP Security Bot - Utils
|
5
5
|
License: MIT
|
6
6
|
Author: Dinis Cruz
|
@@ -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
|
-

|
27
27
|
[](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
|
28
28
|
|
29
29
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
osbot_utils/__init__.py,sha256=DdJDmQc9zbQUlPVyTJOww6Ixrn9n4bD3ami5ItQfzJI,16
|
2
2
|
osbot_utils/base_classes/Cache_Pickle.py,sha256=kPCwrgUbf_dEdxUz7vW1GuvIPwlNXxuRhb-H3AbSpII,5884
|
3
|
-
osbot_utils/base_classes/Kwargs_To_Disk.py,sha256=
|
3
|
+
osbot_utils/base_classes/Kwargs_To_Disk.py,sha256=jrm_L3xgh7bfKmDyxCcUJ9-DLzZ6n6YZlmCtHqmd0aY,1087
|
4
4
|
osbot_utils/base_classes/Kwargs_To_Self.py,sha256=3LRFpxdg9RBuUlIacF1Bwq014NXtJmB4U2dy9a69uY8,138
|
5
5
|
osbot_utils/base_classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
6
6
|
osbot_utils/context_managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -234,7 +234,7 @@ osbot_utils/helpers/pubsub/Event__Queue.py,sha256=bCtIdVlAuG-jvFEnz14oNhgRScEUrd
|
|
234
234
|
osbot_utils/helpers/pubsub/PubSub__Client.py,sha256=6K3l4H-Tc0DhktrxpYzLVur1uZ532pQsHWprLNRXFJE,2316
|
235
235
|
osbot_utils/helpers/pubsub/PubSub__Room.py,sha256=3drJIAVSAzXB_0Q9dXxwhYWxNaEUaMiWiXLY9Mh02DM,481
|
236
236
|
osbot_utils/helpers/pubsub/PubSub__Server.py,sha256=DjQ6PsNGmULdFodspdNktADcoIN3FbdvAitE52m89-w,3548
|
237
|
-
osbot_utils/helpers/pubsub/PubSub__Sqlite.py,sha256=
|
237
|
+
osbot_utils/helpers/pubsub/PubSub__Sqlite.py,sha256=BXDZEz0r7NO1PLt8Y7Wa6Yok0iKNp5bnegCMxm_2xMg,848
|
238
238
|
osbot_utils/helpers/pubsub/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
239
239
|
osbot_utils/helpers/pubsub/schemas/Schema__Event.py,sha256=si12mqRRROI3HYGvjQvzPZ_NGw3TpmVZxGhzuWq5cus,402
|
240
240
|
osbot_utils/helpers/pubsub/schemas/Schema__Event__Connect.py,sha256=fgq0G3_zx3UFk5knsotmEXvP1YvZwOLBtT9gow1U-qM,269
|
@@ -262,7 +262,7 @@ osbot_utils/helpers/safe_int/__init__.py,sha256=kMU2WMsdQmayBEZugxnJV_wRW3O90bc1
|
|
262
262
|
osbot_utils/helpers/safe_str/Safe_Str.py,sha256=qR2RDh5cehP_wDDeV5TQahNBwmfcizPFyStALBKD5dw,3509
|
263
263
|
osbot_utils/helpers/safe_str/Safe_Str__File__Name.py,sha256=ncjkQ2hAhw0a3UulrCuQsA9ytrFwg5CT1XRJIGChMpY,289
|
264
264
|
osbot_utils/helpers/safe_str/Safe_Str__File__Path.py,sha256=K0yBcvH_Ncqiw7tMqjGqaNyWQh1Zs9qxZ-TR8nEIAow,550
|
265
|
-
osbot_utils/helpers/safe_str/Safe_Str__Hash.py,sha256=
|
265
|
+
osbot_utils/helpers/safe_str/Safe_Str__Hash.py,sha256=IpYdYwXey5WZWa6QfysmsiDP-4L-wP-_EKbkeXhFRH4,1252
|
266
266
|
osbot_utils/helpers/safe_str/Safe_Str__Text.py,sha256=QxuWqF8hNYdOPDn3Yac86h_1ZaX-THbTBDakberiJcs,313
|
267
267
|
osbot_utils/helpers/safe_str/Safe_Str__Text__Dangerous.py,sha256=6-fkXBuWgjz70eQicD07f38eEuKqNzJzaFFY6hozhNQ,388
|
268
268
|
osbot_utils/helpers/safe_str/Safe_Str__Url.py,sha256=4l46AAe5Dy_P_W6d-_3pwtXuehG_Wczq1dC5sOOzg_g,549
|
@@ -288,7 +288,7 @@ osbot_utils/helpers/sqlite/cache/Sqlite__Cache__Requests.py,sha256=SC-NBsj-wsAcv
|
|
288
288
|
osbot_utils/helpers/sqlite/cache/Sqlite__Cache__Requests__Patch.py,sha256=HB-LbZQ0VHi9cJm0647WJKUZIjesMppKQ3ZbTOsMgCI,2474
|
289
289
|
osbot_utils/helpers/sqlite/cache/Sqlite__Cache__Requests__Sqlite.py,sha256=vaijPsoQU2_2uQEBa_ukeA6o-EhJkn2KmhKJ3_hse3o,779
|
290
290
|
osbot_utils/helpers/sqlite/cache/Sqlite__Cache__Requests__Table.py,sha256=77uO-8WLmzBh5A4Y2VVclKlp2kn1aZ6iJVCtOr4zYFo,2830
|
291
|
-
osbot_utils/helpers/sqlite/cache/Sqlite__DB__Requests.py,sha256=
|
291
|
+
osbot_utils/helpers/sqlite/cache/Sqlite__DB__Requests.py,sha256=VWprEbbSWTy5VPBe0XVHdZ3yD9-Zlb-344-QfzDD_wA,1603
|
292
292
|
osbot_utils/helpers/sqlite/cache/TestCase__Sqlite__Cache__Requests.py,sha256=TLUdQC6vsf5BcDP15CCeoYkipVG30bzqFcqEJpH4dWg,1645
|
293
293
|
osbot_utils/helpers/sqlite/cache/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
294
294
|
osbot_utils/helpers/sqlite/domains/Sqlite__DB.py,sha256=xyXnt4-GLYqMEPBZrNPI0dZnkl61KwLEIuYjebO20Jc,1210
|
@@ -374,13 +374,13 @@ osbot_utils/type_safe/Type_Safe.py,sha256=LOWRGOGpnRU2iTRLP47vUoyalK0vjFrWlnaghB
|
|
374
374
|
osbot_utils/type_safe/Type_Safe__Base.py,sha256=UTMipTL6mXoetAEUCI5hs8RqXp4NDYOvoAiYoFOt5jg,8807
|
375
375
|
osbot_utils/type_safe/Type_Safe__Dict.py,sha256=QB200L5eNWT3FnUv8sm5kncj1wXJsJ9uRycNFl9xb6Y,3077
|
376
376
|
osbot_utils/type_safe/Type_Safe__List.py,sha256=y_lp7Ai0HfQCqC8Bxn0g6_M9MP5lPOXy5Dhkuj2fJvQ,1891
|
377
|
-
osbot_utils/type_safe/Type_Safe__Method.py,sha256=
|
377
|
+
osbot_utils/type_safe/Type_Safe__Method.py,sha256=K100jAq1wmskuXcTd_9vt-XodSKJkDowJselmnDFCN8,16643
|
378
378
|
osbot_utils/type_safe/Type_Safe__Primitive.py,sha256=CJ4LP2W5i9utSSzuiiJrwqvwdMv1DeQ6dIZICtYfLTY,3635
|
379
379
|
osbot_utils/type_safe/Type_Safe__Set.py,sha256=j12fc8cbd9-s_a13ysaz723rNEW4Dt6hObCd0S-AjIg,1432
|
380
380
|
osbot_utils/type_safe/Type_Safe__Tuple.py,sha256=Kx7C4YfHybRbMmVMcmV6yFLi4T48pb592vEZfjjyLxo,1710
|
381
381
|
osbot_utils/type_safe/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
382
382
|
osbot_utils/type_safe/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
383
|
-
osbot_utils/type_safe/decorators/type_safe.py,sha256=
|
383
|
+
osbot_utils/type_safe/decorators/type_safe.py,sha256=3jVwrO46s6xpS1Uc4gTrbWc2TnrHCfWJUZ8FIS8mwEo,1772
|
384
384
|
osbot_utils/type_safe/methods/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
385
385
|
osbot_utils/type_safe/methods/type_safe_property.py,sha256=DcJkOIs6swJtkglsZVKLyFSczCGSJISOVwAmvjCOQvo,1425
|
386
386
|
osbot_utils/type_safe/shared/Type_Safe__Annotations.py,sha256=nmVqCbhk4kUYrw_mdYqugxQlv4gM3NUUH89FYTHUg-c,1133
|
@@ -398,7 +398,7 @@ osbot_utils/type_safe/steps/Type_Safe__Step__Default_Kwargs.py,sha256=tzKXDUc0HV
|
|
398
398
|
osbot_utils/type_safe/steps/Type_Safe__Step__Default_Value.py,sha256=b5vsgM8eg9yq2KM0wRMntVHma6OhN_HnU76LxhEIpoA,4483
|
399
399
|
osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py,sha256=AguNcZwKKnyNY87bSAF1xLwYW5h_IDfUad70QqIiK3I,14622
|
400
400
|
osbot_utils/type_safe/steps/Type_Safe__Step__Init.py,sha256=wBdShMavx8Ja5IACyW8dP3_fq_iqrMp8HHziOqjgxqU,4483
|
401
|
-
osbot_utils/type_safe/steps/Type_Safe__Step__Set_Attr.py,sha256=
|
401
|
+
osbot_utils/type_safe/steps/Type_Safe__Step__Set_Attr.py,sha256=k7GX3q0ps4R1Z3w5JMFHB0w19zVXtO1VS11wpFVI19o,6680
|
402
402
|
osbot_utils/type_safe/steps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
403
403
|
osbot_utils/type_safe/validators/Type_Safe__Validator.py,sha256=cJIPSBarjV716SZUOLvz7Mthjk-aUYKUQtRDtKUBmN4,779
|
404
404
|
osbot_utils/type_safe/validators/Validator__Max.py,sha256=pCvYF5Jb_cBgn1ArGhf6FNUB-NGCXPq3D36oYDCyAzg,1275
|
@@ -432,8 +432,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
|
|
432
432
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
433
433
|
osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
|
434
434
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
435
|
-
osbot_utils/version,sha256=
|
436
|
-
osbot_utils-2.
|
437
|
-
osbot_utils-2.
|
438
|
-
osbot_utils-2.
|
439
|
-
osbot_utils-2.
|
435
|
+
osbot_utils/version,sha256=c6L9xxoyMql0emsdEbUgj7ng8gzCDcVgYkJG0iDe484,8
|
436
|
+
osbot_utils-2.67.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
437
|
+
osbot_utils-2.67.0.dist-info/METADATA,sha256=bemaemZYec52lrfkkWRpf9HbtcwERuynDCoY6TFH-Vw,1329
|
438
|
+
osbot_utils-2.67.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
439
|
+
osbot_utils-2.67.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|