osbot-utils 2.5.0__py3-none-any.whl → 2.7.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/type_safe/Type_Safe.py +2 -2
- osbot_utils/type_safe/Type_Safe__Method.py +40 -11
- osbot_utils/version +1 -1
- {osbot_utils-2.5.0.dist-info → osbot_utils-2.7.0.dist-info}/METADATA +2 -2
- {osbot_utils-2.5.0.dist-info → osbot_utils-2.7.0.dist-info}/RECORD +7 -7
- {osbot_utils-2.5.0.dist-info → osbot_utils-2.7.0.dist-info}/LICENSE +0 -0
- {osbot_utils-2.5.0.dist-info → osbot_utils-2.7.0.dist-info}/WHEEL +0 -0
@@ -337,8 +337,8 @@ class Type_Safe:
|
|
337
337
|
|
338
338
|
def deserialize_dict__using_key_value_annotations(self, key, value):
|
339
339
|
from osbot_utils.type_safe.Type_Safe__Dict import Type_Safe__Dict
|
340
|
-
|
341
|
-
dict_annotations_tuple =
|
340
|
+
annotations = all_annotations(self)
|
341
|
+
dict_annotations_tuple = get_args(annotations.get(key))
|
342
342
|
if not dict_annotations_tuple: # happens when the value is a dict/Dict with no annotations
|
343
343
|
return value
|
344
344
|
if not type(value) is dict:
|
@@ -1,9 +1,9 @@
|
|
1
1
|
import inspect # For function introspection
|
2
|
-
from enum
|
3
|
-
from typing
|
2
|
+
from enum import Enum
|
3
|
+
from typing import get_args, get_origin, Union, List, Any, Dict # For type hinting utilities
|
4
4
|
|
5
5
|
|
6
|
-
class Type_Safe__Method:
|
6
|
+
class Type_Safe__Method: # Class to handle method type safety validation
|
7
7
|
def __init__(self, func): # Initialize with function
|
8
8
|
self.func = func # Store original function
|
9
9
|
self.sig = inspect.signature(func) # Get function signature
|
@@ -88,8 +88,10 @@ class Type_Safe__Method:
|
|
88
88
|
def is_union_type(self, origin_type: Any, is_optional: bool) -> bool: # Check if type is a Union
|
89
89
|
return origin_type is Union and not is_optional # Must be Union but not Optional
|
90
90
|
|
91
|
-
def validate_union_type(self, param_name: str,
|
92
|
-
|
91
|
+
def validate_union_type(self, param_name : str,
|
92
|
+
param_value : Any,
|
93
|
+
expected_type: Any): # validate Union type parameters
|
94
|
+
|
93
95
|
args_types = get_args(expected_type) # Get allowed types
|
94
96
|
if not any(isinstance(param_value, arg_type) for arg_type in args_types): # Check if value matches any type
|
95
97
|
raise ValueError(f"Parameter '{param_name}' expected one of types {args_types}, but got {type(param_value)}") # Raise error if no match
|
@@ -110,10 +112,37 @@ class Type_Safe__Method:
|
|
110
112
|
except Exception: # Handle conversion failure
|
111
113
|
pass # Continue without conversion
|
112
114
|
return False # Return failure
|
113
|
-
|
115
|
+
# Return failure
|
116
|
+
|
117
|
+
def validate_direct_type(self, param_name: str, param_value: Any, expected_type: Any):
|
118
|
+
if expected_type is Any: # Handle typing.Any which accepts everything
|
119
|
+
return True
|
120
|
+
|
121
|
+
if param_value is None: # Handle None value case
|
122
|
+
is_optional = self.is_optional_type(expected_type) # Check if type is optional
|
123
|
+
has_default = self.has_default_value(param_name) # Check if has default value
|
124
|
+
self.validate_none_value(param_name, is_optional, has_default) # Validate None value
|
114
125
|
|
115
|
-
|
116
|
-
|
117
|
-
if
|
118
|
-
|
119
|
-
|
126
|
+
origin = get_origin(expected_type)
|
127
|
+
|
128
|
+
if origin is Union: # If it's a Union type
|
129
|
+
return True # there is another check that confirms it: todo: confirm this
|
130
|
+
|
131
|
+
if origin is not None: # If it's a generic type (like Dict, List, etc)
|
132
|
+
if origin in (dict, Dict): # Special handling for Dict
|
133
|
+
if not isinstance(param_value, dict):
|
134
|
+
raise ValueError(f"Parameter '{param_name}' expected dict but got {type(param_value)}")
|
135
|
+
key_type, value_type = get_args(expected_type)
|
136
|
+
for k, v in param_value.items():
|
137
|
+
if not isinstance(k, key_type):
|
138
|
+
raise ValueError(f"Dict key '{k}' expected type {key_type}, but got {type(k)}")
|
139
|
+
if not isinstance(v, value_type):
|
140
|
+
raise ValueError(f"Dict value for key '{k}' expected type {value_type}, but got {type(v)}")
|
141
|
+
return True
|
142
|
+
base_type = origin
|
143
|
+
else:
|
144
|
+
base_type = expected_type
|
145
|
+
|
146
|
+
if not isinstance(param_value, base_type):
|
147
|
+
raise ValueError(f"Parameter '{param_name}' expected type {expected_type}, but got {type(param_value)}")
|
148
|
+
return True
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v2.
|
1
|
+
v2.7.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.7.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
|
-

|
27
27
|
[](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
|
28
28
|
|
29
29
|
|
@@ -277,11 +277,11 @@ osbot_utils/testing/Temp_Zip_In_Memory.py,sha256=ibDIWt3K4CX558PbkLbX3InHyWYZcwQ
|
|
277
277
|
osbot_utils/testing/Unit_Test.py,sha256=MReR_wDGbbXFDPz7cmuGflcTxRB6TBnO9mYqRpSq8Pk,1304
|
278
278
|
osbot_utils/testing/Unzip_File.py,sha256=V5H97XO9rlvG5EYOSzAH4kTtAH1ohZ8R8ImvJh46ZNg,1177
|
279
279
|
osbot_utils/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
280
|
-
osbot_utils/type_safe/Type_Safe.py,sha256=
|
280
|
+
osbot_utils/type_safe/Type_Safe.py,sha256=NwniGTMB9La3Sbo08FkPn01ka9h70n8jTRcqtqSrmi4,30467
|
281
281
|
osbot_utils/type_safe/Type_Safe__Base.py,sha256=mL8GMaR9tsaUfwk8d-8zp2g-A8kNKiN6kroEFaNvMOk,5518
|
282
282
|
osbot_utils/type_safe/Type_Safe__Dict.py,sha256=I_Ac0JH-ahmQrkADFVyiobTlH1JI31MKHaNszQW4PBo,2396
|
283
283
|
osbot_utils/type_safe/Type_Safe__List.py,sha256=SzSIBkwSOAEpW_V2qh4-f0YHzmgB0T8PczBLbDgZGvg,1340
|
284
|
-
osbot_utils/type_safe/Type_Safe__Method.py,sha256=
|
284
|
+
osbot_utils/type_safe/Type_Safe__Method.py,sha256=LOG2sqQyKBNNEiJxk_jngH6IWvpyVueouAzNTlj-_pY,12676
|
285
285
|
osbot_utils/type_safe/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
286
286
|
osbot_utils/type_safe/decorators/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
287
287
|
osbot_utils/type_safe/decorators/type_safe.py,sha256=ERFfJuAIo5qLp03YEDu2zu5wxu65OhR7hOybwuTfLlc,1006
|
@@ -317,8 +317,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
|
|
317
317
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
318
318
|
osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
|
319
319
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
320
|
-
osbot_utils/version,sha256=
|
321
|
-
osbot_utils-2.
|
322
|
-
osbot_utils-2.
|
323
|
-
osbot_utils-2.
|
324
|
-
osbot_utils-2.
|
320
|
+
osbot_utils/version,sha256=EtyVXU03AffYJg9oYhRGCGg4FoQy8uTssAJDNu9cIQY,7
|
321
|
+
osbot_utils-2.7.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
322
|
+
osbot_utils-2.7.0.dist-info/METADATA,sha256=EwDB5K1xIrl97T8tWVAoGIdK8XOKdyQ4uqe9ZR_qI6Y,1315
|
323
|
+
osbot_utils-2.7.0.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
324
|
+
osbot_utils-2.7.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|