osbot-utils 2.74.0__py3-none-any.whl → 2.76.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/primitives/safe_str/text/Safe_Str__Text.py +1 -1
- osbot_utils/type_safe/type_safe_core/collections/Type_Safe__List.py +26 -10
- osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Class_Kwargs.py +30 -6
- osbot_utils/version +1 -1
- {osbot_utils-2.74.0.dist-info → osbot_utils-2.76.0.dist-info}/METADATA +2 -2
- {osbot_utils-2.74.0.dist-info → osbot_utils-2.76.0.dist-info}/RECORD +8 -8
- {osbot_utils-2.74.0.dist-info → osbot_utils-2.76.0.dist-info}/LICENSE +0 -0
- {osbot_utils-2.74.0.dist-info → osbot_utils-2.76.0.dist-info}/WHEEL +0 -0
@@ -2,7 +2,7 @@ import re
|
|
2
2
|
from osbot_utils.type_safe.primitives.safe_str.Safe_Str import Safe_Str
|
3
3
|
|
4
4
|
TYPE_SAFE_STR__TEXT__MAX_LENGTH = 4096
|
5
|
-
TYPE_SAFE_STR__TEXT__REGEX = r'[^a-zA-Z0-9_ ()\[\]
|
5
|
+
TYPE_SAFE_STR__TEXT__REGEX = r'[^a-zA-Z0-9_ ()\[\]\-+=:;,.?*]'
|
6
6
|
|
7
7
|
class Safe_Str__Text(Safe_Str):
|
8
8
|
regex = re.compile(TYPE_SAFE_STR__TEXT__REGEX)
|
@@ -1,5 +1,8 @@
|
|
1
|
-
from typing
|
2
|
-
from osbot_utils.type_safe.
|
1
|
+
from typing import Type
|
2
|
+
from osbot_utils.type_safe.Type_Safe__Primitive import Type_Safe__Primitive
|
3
|
+
from osbot_utils.type_safe.Type_Safe__Base import Type_Safe__Base, type_str
|
4
|
+
|
5
|
+
|
3
6
|
|
4
7
|
class Type_Safe__List(Type_Safe__Base, list):
|
5
8
|
expected_type : Type
|
@@ -16,14 +19,27 @@ class Type_Safe__List(Type_Safe__Base, list):
|
|
16
19
|
def __exit__ (self, type, value, traceback): pass
|
17
20
|
|
18
21
|
def append(self, item):
|
19
|
-
from osbot_utils.type_safe.Type_Safe
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
from osbot_utils.type_safe.Type_Safe import Type_Safe # to prevent circular imports
|
23
|
+
|
24
|
+
# Handle Type_Safe objects from dicts
|
25
|
+
if type(self.expected_type) is type and issubclass(self.expected_type, Type_Safe) and type(item) is dict:
|
26
|
+
item = self.expected_type.from_json(item)
|
27
|
+
# Handle Type_Safe__Primitive conversions (str -> Safe_Str, etc.)
|
28
|
+
elif type(self.expected_type) is type and issubclass(self.expected_type, Type_Safe__Primitive):
|
29
|
+
if not isinstance(item, self.expected_type):
|
30
|
+
try:
|
31
|
+
item = self.expected_type(item)
|
32
|
+
except (ValueError, TypeError) as e:
|
33
|
+
# Re-raise with more context about what failed
|
34
|
+
raise TypeError(f"In Type_Safe__List: Could not convert {type(item).__name__} to {self.expected_type.__name__}: {e}") from None
|
35
|
+
|
36
|
+
|
37
|
+
# Now validate the (possibly converted) item
|
38
|
+
try:
|
39
|
+
self.is_instance_of_type(item, self.expected_type)
|
40
|
+
except TypeError as e:
|
41
|
+
raise TypeError(f"In Type_Safe__List: Invalid type for item: {e}") from None
|
42
|
+
|
27
43
|
super().append(item)
|
28
44
|
|
29
45
|
|
@@ -65,15 +65,39 @@ class Type_Safe__Step__Class_Kwargs:
|
|
65
65
|
var_name : str ,
|
66
66
|
var_type : Type )\
|
67
67
|
-> None:
|
68
|
-
var_value = getattr(base_cls, var_name) # Get current value
|
69
|
-
if var_value is None: # Allow None assignments
|
68
|
+
# var_value = getattr(base_cls, var_name) # Get current value
|
69
|
+
# if var_value is None: # Allow None assignments
|
70
|
+
# return
|
71
|
+
#
|
72
|
+
# if type_safe_validation.should_skip_type_check(var_type): # Skip validation if needed
|
73
|
+
# return
|
74
|
+
#
|
75
|
+
# type_safe_validation.validate_variable_type (var_name, var_type, var_value) # Validate type
|
76
|
+
# type_safe_validation.validate_type_immutability(var_name, var_type) # Validate immutability
|
77
|
+
|
78
|
+
var_value = getattr(base_cls, var_name)
|
79
|
+
if var_value is None:
|
70
80
|
return
|
71
|
-
|
72
|
-
if type_safe_validation.should_skip_type_check(var_type): # Skip validation if needed
|
81
|
+
if type_safe_validation.should_skip_type_check(var_type):
|
73
82
|
return
|
74
83
|
|
75
|
-
|
76
|
-
|
84
|
+
# NEW: Try to convert primitive values to Type_Safe__Primitive types
|
85
|
+
from osbot_utils.type_safe.Type_Safe__Primitive import Type_Safe__Primitive
|
86
|
+
if (isinstance(var_type, type) and
|
87
|
+
issubclass(var_type, Type_Safe__Primitive) and
|
88
|
+
type(var_value) in (str, int, float)):
|
89
|
+
try:
|
90
|
+
# Attempt conversion and validate the converted value
|
91
|
+
converted_value = var_type(var_value)
|
92
|
+
# Set the converted value back on the class
|
93
|
+
setattr(base_cls, var_name, converted_value)
|
94
|
+
var_value = converted_value
|
95
|
+
except (ValueError, TypeError):
|
96
|
+
# If conversion fails, let the original validation handle it
|
97
|
+
pass
|
98
|
+
|
99
|
+
type_safe_validation.validate_variable_type(var_name, var_type, var_value)
|
100
|
+
type_safe_validation.validate_type_immutability(var_name, var_type)
|
77
101
|
|
78
102
|
def process_annotation(self, cls : Type , # Process single annotation
|
79
103
|
base_cls : Type ,
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v2.
|
1
|
+
v2.76.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.76.0
|
4
4
|
Summary: OWASP Security Bot - Utils
|
5
5
|
License: MIT
|
6
6
|
Author: Dinis Cruz
|
@@ -21,7 +21,7 @@ Description-Content-Type: text/markdown
|
|
21
21
|
|
22
22
|
# OSBot-Utils
|
23
23
|
|
24
|
-

|
25
25
|

|
26
26
|

|
27
27
|

|
@@ -389,7 +389,7 @@ osbot_utils/type_safe/primitives/safe_str/identifiers/Random_Guid.py,sha256=86xn
|
|
389
389
|
osbot_utils/type_safe/primitives/safe_str/identifiers/Random_Guid_Short.py,sha256=YP_k5OLuYvXWGU2OEnQHk_OGViBQofTWKm3pUdQaJao,404
|
390
390
|
osbot_utils/type_safe/primitives/safe_str/identifiers/Safe_Id.py,sha256=Mj66QVcEHqUKDFb0cdl7cbMOlQKxfFuRxnupmKo6UG8,696
|
391
391
|
osbot_utils/type_safe/primitives/safe_str/identifiers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
392
|
-
osbot_utils/type_safe/primitives/safe_str/text/Safe_Str__Text.py,sha256=
|
392
|
+
osbot_utils/type_safe/primitives/safe_str/text/Safe_Str__Text.py,sha256=95E4ALhah2AEfL-m5JB7XpUOkyxQ0lJQM139RPQJjv4,327
|
393
393
|
osbot_utils/type_safe/primitives/safe_str/text/Safe_Str__Text__Dangerous.py,sha256=WrEvoXeHWuevzgbfUkm2xisGUMIlDS39Nte3P2_hyHg,401
|
394
394
|
osbot_utils/type_safe/primitives/safe_str/text/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
395
395
|
osbot_utils/type_safe/primitives/safe_str/web/Safe_Str__Html.py,sha256=HnCnKUBPB0IfEXSoeK4XFB08qjnAaOYyd-s1smvI2pQ,675
|
@@ -404,7 +404,7 @@ osbot_utils/type_safe/primitives/safe_uint/Safe_UInt__Port.py,sha256=gcqi3UaWaFN
|
|
404
404
|
osbot_utils/type_safe/primitives/safe_uint/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
405
405
|
osbot_utils/type_safe/type_safe_core/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
406
406
|
osbot_utils/type_safe/type_safe_core/collections/Type_Safe__Dict.py,sha256=TYb1nXbVqn4bGoagGqr4U__LofpjDllKxiVJCL705PI,3159
|
407
|
-
osbot_utils/type_safe/type_safe_core/collections/Type_Safe__List.py,sha256=
|
407
|
+
osbot_utils/type_safe/type_safe_core/collections/Type_Safe__List.py,sha256=VYlTzDXnreb5s6Ue5AIq-ehxg3jHppOVES0CppjhCsg,2607
|
408
408
|
osbot_utils/type_safe/type_safe_core/collections/Type_Safe__Set.py,sha256=j12fc8cbd9-s_a13ysaz723rNEW4Dt6hObCd0S-AjIg,1432
|
409
409
|
osbot_utils/type_safe/type_safe_core/collections/Type_Safe__Tuple.py,sha256=Kx7C4YfHybRbMmVMcmV6yFLi4T48pb592vEZfjjyLxo,1710
|
410
410
|
osbot_utils/type_safe/type_safe_core/collections/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -423,7 +423,7 @@ osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Raise_Exception.py,sha256
|
|
423
423
|
osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Shared__Variables.py,sha256=SuZGl9LryQX6IpOE0I_lbzClT-h17UNylC__-M8ltTY,129
|
424
424
|
osbot_utils/type_safe/type_safe_core/shared/Type_Safe__Validation.py,sha256=aKtlqYU5uaobgpoOnzU4kKqR7mzVLeG8YcUUbWp7n-g,19648
|
425
425
|
osbot_utils/type_safe/type_safe_core/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
426
|
-
osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Class_Kwargs.py,sha256=
|
426
|
+
osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Class_Kwargs.py,sha256=BbMPfCv5-RUZzh-TbyLBvykXZkdkR91jCGJoZ4R697g,8237
|
427
427
|
osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Default_Kwargs.py,sha256=tzKXDUc0HVP5QvCWsmcPuuZodNvQZ9FeMDNI2x00Ngw,1943
|
428
428
|
osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__Default_Value.py,sha256=mRu0yV3w7Ch1H8SOfXMRqMBp3ooY95yR_oni7JafJBc,4603
|
429
429
|
osbot_utils/type_safe/type_safe_core/steps/Type_Safe__Step__From_Json.py,sha256=GTZnGC7DvEBA_LxgLw_KZZ1iVUV0EwyIgcZzoh14Bro,15453
|
@@ -462,8 +462,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
|
|
462
462
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
463
463
|
osbot_utils/utils/Zip.py,sha256=mG42lgTY0tnm14T3P1-DSAIZKkTiYoO3odZ1aOUdc1I,14394
|
464
464
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
465
|
-
osbot_utils/version,sha256=
|
466
|
-
osbot_utils-2.
|
467
|
-
osbot_utils-2.
|
468
|
-
osbot_utils-2.
|
469
|
-
osbot_utils-2.
|
465
|
+
osbot_utils/version,sha256=8BoOt5kr4AI3hSggK9uXi2EyaXnLCCJ0Se4muuaz9wM,8
|
466
|
+
osbot_utils-2.76.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
467
|
+
osbot_utils-2.76.0.dist-info/METADATA,sha256=Nn_qbZC6Qnw6TRHIqJ-oQ_7hH0f67dL4dtcvAeZr8R4,7905
|
468
|
+
osbot_utils-2.76.0.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
469
|
+
osbot_utils-2.76.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|