osbot-utils 2.34.0__py3-none-any.whl → 2.36.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/testing/performance/Performance_Measure__Session.py +1 -1
- osbot_utils/type_safe/Type_Safe__Base.py +27 -4
- osbot_utils/type_safe/Type_Safe__List.py +1 -1
- osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py +8 -0
- osbot_utils/type_safe/steps/Type_Safe__Step__Init.py +3 -1
- osbot_utils/version +1 -1
- {osbot_utils-2.34.0.dist-info → osbot_utils-2.36.0.dist-info}/METADATA +2 -2
- {osbot_utils-2.34.0.dist-info → osbot_utils-2.36.0.dist-info}/RECORD +10 -10
- {osbot_utils-2.34.0.dist-info → osbot_utils-2.36.0.dist-info}/LICENSE +0 -0
- {osbot_utils-2.34.0.dist-info → osbot_utils-2.36.0.dist-info}/WHEEL +0 -0
@@ -122,7 +122,7 @@ class Performance_Measure__Session(Type_Safe):
|
|
122
122
|
if self.assert_enabled is False:
|
123
123
|
return
|
124
124
|
if in_github_action():
|
125
|
-
max_time = max_time *
|
125
|
+
max_time = max_time * 6 # adjust for GitHub's slowness
|
126
126
|
|
127
127
|
assert self.result.final_score <= max_time, f"Performance changed for {self.result.name}: got {self.result.final_score:,d}ns, expected less than {max_time}ns"
|
128
128
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
import types
|
1
2
|
from typing import get_args, Union, Optional, Any, ForwardRef
|
2
3
|
from osbot_utils.helpers.Obj_Id import Obj_Id
|
3
4
|
from osbot_utils.type_safe.shared.Type_Safe__Cache import type_safe_cache
|
@@ -28,9 +29,9 @@ class Type_Safe__Base:
|
|
28
29
|
actual_type_name = type_str(type(item))
|
29
30
|
raise TypeError(f"Expected '{expected_type_name}', but got '{actual_type_name}'")
|
30
31
|
|
31
|
-
elif origin
|
32
|
+
elif origin in (list, set) and args: # Expected type is List[...]
|
32
33
|
(item_type,) = args
|
33
|
-
if not isinstance(item, list):
|
34
|
+
if not isinstance(item, (list,set)):
|
34
35
|
expected_type_name = type_str(expected_type)
|
35
36
|
actual_type_name = type_str(type(item))
|
36
37
|
raise TypeError(f"Expected '{expected_type_name}', but got '{actual_type_name}'")
|
@@ -82,9 +83,11 @@ class Type_Safe__Base:
|
|
82
83
|
actual_type_name = type_str(type(item))
|
83
84
|
raise TypeError(f"Expected '{expected_type_name}', but got '{actual_type_name}'")
|
84
85
|
elif origin is type: # Expected type is Type[T]
|
86
|
+
if type(item) is str:
|
87
|
+
item = deserialize_type__using_value(item)
|
85
88
|
if not isinstance(item, type): # First check if item is actually a type
|
86
89
|
expected_type_name = type_str(expected_type)
|
87
|
-
actual_type_name
|
90
|
+
actual_type_name = type_str(type(item))
|
88
91
|
raise TypeError(f"Expected {expected_type_name}, but got instance: {actual_type_name}")
|
89
92
|
|
90
93
|
args = get_args(expected_type)
|
@@ -115,4 +118,24 @@ def type_str(tp):
|
|
115
118
|
else:
|
116
119
|
args = get_args(tp)
|
117
120
|
args_str = ', '.join(type_str(arg) for arg in args)
|
118
|
-
return f"{origin.__name__}[{args_str}]"
|
121
|
+
return f"{origin.__name__}[{args_str}]"
|
122
|
+
|
123
|
+
# todo: this is duplicated from Type_Safe__Step__From_Json (review and figure out how to do this more centrally)
|
124
|
+
def deserialize_type__using_value(value): # TODO: Check the security implications of this deserialisation
|
125
|
+
from osbot_utils.type_safe.Type_Safe import Type_Safe
|
126
|
+
if value:
|
127
|
+
try:
|
128
|
+
module_name, type_name = value.rsplit('.', 1)
|
129
|
+
if module_name == 'builtins' and type_name == 'NoneType': # Special case for NoneType (which serialises as builtins.* , but it actually in types.* )
|
130
|
+
value = types.NoneType
|
131
|
+
else:
|
132
|
+
module = __import__(module_name, fromlist=[type_name])
|
133
|
+
value = getattr(module, type_name)
|
134
|
+
if isinstance(value, type) is False:
|
135
|
+
raise ValueError(f"Security alert, in deserialize_type__using_value only classes are allowed")
|
136
|
+
# todo: figure out a way to do this
|
137
|
+
# if issubclass(value, (Type_Safe, str, int)) is False:
|
138
|
+
# raise ValueError(f"Security alert, in deserialize_type__using_value only class of type Type_Safe, str, int are allowed")
|
139
|
+
except (ValueError, ImportError, AttributeError) as e:
|
140
|
+
raise ValueError(f"Could not reconstruct type from '{value}': {str(e)}")
|
141
|
+
return value
|
@@ -18,7 +18,7 @@ class Type_Safe__List(Type_Safe__Base, list):
|
|
18
18
|
try:
|
19
19
|
self.is_instance_of_type(item, self.expected_type)
|
20
20
|
except TypeError as e:
|
21
|
-
|
21
|
+
raise TypeError(f"In Type_Safe__List: Invalid type for item: {e}")
|
22
22
|
super().append(item)
|
23
23
|
|
24
24
|
|
@@ -127,6 +127,14 @@ class Type_Safe__Step__From_Json:
|
|
127
127
|
else:
|
128
128
|
module = __import__(module_name, fromlist=[type_name])
|
129
129
|
value = getattr(module, type_name)
|
130
|
+
if isinstance(value, type) is False:
|
131
|
+
raise ValueError(f"Security alert, in deserialize_type__using_value only classes are allowed")
|
132
|
+
|
133
|
+
# todo: figure out a way to do this
|
134
|
+
# supported_types = (Type_Safe, str, int, type, dict)
|
135
|
+
# if issubclass(value, supported_types) is False:
|
136
|
+
# raise ValueError(f"Security alert, in deserialize_type__using_value only class of {supported_types} are allowed and it was {value}")
|
137
|
+
|
130
138
|
except (ValueError, ImportError, AttributeError) as e:
|
131
139
|
raise ValueError(f"Could not reconstruct type from '{value}': {str(e)}")
|
132
140
|
return value
|
@@ -31,6 +31,8 @@ class Type_Safe__Step__Init:
|
|
31
31
|
annotation = type_safe_annotations.obj_attribute_annotation(__self, key)
|
32
32
|
if annotation:
|
33
33
|
if isinstance(annotation, EnumMeta) and type(value) is str:
|
34
|
+
if value not in annotation.__members__:
|
35
|
+
raise ValueError(f"Invalid value '{value}' for enum {annotation.__name__}")
|
34
36
|
value = annotation[value]
|
35
37
|
else:
|
36
38
|
|
@@ -69,7 +71,7 @@ class Type_Safe__Step__Init:
|
|
69
71
|
elif origin is dict and isinstance(value, dict):
|
70
72
|
from osbot_utils.type_safe.Type_Safe__Dict import Type_Safe__Dict
|
71
73
|
key_type, value_type = get_args(annotation)
|
72
|
-
type_safe_dict
|
74
|
+
type_safe_dict = Type_Safe__Dict(expected_key_type=key_type, expected_value_type=value_type)
|
73
75
|
for k, v in value.items():
|
74
76
|
type_safe_dict[k] = v
|
75
77
|
return type_safe_dict
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v2.
|
1
|
+
v2.36.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.36.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
|
|
@@ -332,15 +332,15 @@ osbot_utils/testing/Temp_Zip_In_Memory.py,sha256=ibDIWt3K4CX558PbkLbX3InHyWYZcwQ
|
|
332
332
|
osbot_utils/testing/Unit_Test.py,sha256=MReR_wDGbbXFDPz7cmuGflcTxRB6TBnO9mYqRpSq8Pk,1304
|
333
333
|
osbot_utils/testing/Unzip_File.py,sha256=V5H97XO9rlvG5EYOSzAH4kTtAH1ohZ8R8ImvJh46ZNg,1177
|
334
334
|
osbot_utils/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
335
|
-
osbot_utils/testing/performance/Performance_Measure__Session.py,sha256=
|
335
|
+
osbot_utils/testing/performance/Performance_Measure__Session.py,sha256=CWce0vJAZH_PDbIgK5bNcNFr1qsB37FQJKd05K-63kk,9108
|
336
336
|
osbot_utils/testing/performance/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
337
337
|
osbot_utils/testing/performance/models/Model__Performance_Measure__Measurement.py,sha256=xT_uKzbSYo9AGiJgNmCHSt3ApneNNyKh8vsMVN6IJQ0,1127
|
338
338
|
osbot_utils/testing/performance/models/Model__Performance_Measure__Result.py,sha256=k9HJYNLmW6sjRVsfpduSxHFiVANc1zmYtO_Oz9azpW8,755
|
339
339
|
osbot_utils/testing/performance/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
340
340
|
osbot_utils/type_safe/Type_Safe.py,sha256=LOWRGOGpnRU2iTRLP47vUoyalK0vjFrWlnaghBIogWg,6267
|
341
|
-
osbot_utils/type_safe/Type_Safe__Base.py,sha256=
|
341
|
+
osbot_utils/type_safe/Type_Safe__Base.py,sha256=9VfmZzY7aE5rNES7F38YYB7U4BqcUqXET1tABuZDsCk,7634
|
342
342
|
osbot_utils/type_safe/Type_Safe__Dict.py,sha256=9TExQtFHQNLdw_ASfQ49i1YhC7fSyCiGdVkK8n-hGlc,2407
|
343
|
-
osbot_utils/type_safe/Type_Safe__List.py,sha256=
|
343
|
+
osbot_utils/type_safe/Type_Safe__List.py,sha256=6PIo52QUBu83KhPlvlVOT8tpPpQQkDUGswKKhOxoymg,1707
|
344
344
|
osbot_utils/type_safe/Type_Safe__Method.py,sha256=PRV4enbwuD81QKP_5UtUA3OAp0m0xSiUhwkCoseZoq4,15687
|
345
345
|
osbot_utils/type_safe/Type_Safe__Set.py,sha256=j12fc8cbd9-s_a13ysaz723rNEW4Dt6hObCd0S-AjIg,1432
|
346
346
|
osbot_utils/type_safe/Type_Safe__Tuple.py,sha256=Kx7C4YfHybRbMmVMcmV6yFLi4T48pb592vEZfjjyLxo,1710
|
@@ -362,8 +362,8 @@ osbot_utils/type_safe/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
|
|
362
362
|
osbot_utils/type_safe/steps/Type_Safe__Step__Class_Kwargs.py,sha256=snoyJKvZ1crgF2fp0zexwNPnV_E63RfyRIsMAZdrKNY,6995
|
363
363
|
osbot_utils/type_safe/steps/Type_Safe__Step__Default_Kwargs.py,sha256=tzKXDUc0HVP5QvCWsmcPuuZodNvQZ9FeMDNI2x00Ngw,1943
|
364
364
|
osbot_utils/type_safe/steps/Type_Safe__Step__Default_Value.py,sha256=b5vsgM8eg9yq2KM0wRMntVHma6OhN_HnU76LxhEIpoA,4483
|
365
|
-
osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py,sha256=
|
366
|
-
osbot_utils/type_safe/steps/Type_Safe__Step__Init.py,sha256
|
365
|
+
osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py,sha256=y6iet08nQboMPZ1ymrPA61oaSVE3YB1EvPn8a8PiqOE,14133
|
366
|
+
osbot_utils/type_safe/steps/Type_Safe__Step__Init.py,sha256=dQRwFxEMdmoW2ogmYZ6ZxLOvt1XnALx41LPpIB6yp3s,4473
|
367
367
|
osbot_utils/type_safe/steps/Type_Safe__Step__Set_Attr.py,sha256=VuKHH9QEYlbAL9R4zwQ5dwexx2sFY6wMx52QmF7eqcg,5219
|
368
368
|
osbot_utils/type_safe/steps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
369
369
|
osbot_utils/type_safe/validators/Type_Safe__Validator.py,sha256=cJIPSBarjV716SZUOLvz7Mthjk-aUYKUQtRDtKUBmN4,779
|
@@ -398,8 +398,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
|
|
398
398
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
399
399
|
osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
|
400
400
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
401
|
-
osbot_utils/version,sha256=
|
402
|
-
osbot_utils-2.
|
403
|
-
osbot_utils-2.
|
404
|
-
osbot_utils-2.
|
405
|
-
osbot_utils-2.
|
401
|
+
osbot_utils/version,sha256=0wuMx2pp2iJlRaFRxv3KMCNynwS_XlqQIvYnQrKGDbw,8
|
402
|
+
osbot_utils-2.36.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
403
|
+
osbot_utils-2.36.0.dist-info/METADATA,sha256=yDtZSLfjqU_kaWUAJsFyHCNM9s3-EfZ7WkpQNk-Eyn0,1329
|
404
|
+
osbot_utils-2.36.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
405
|
+
osbot_utils-2.36.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|