osbot-utils 2.28.0__py3-none-any.whl → 2.30.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__Dict.py +6 -0
- osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py +11 -4
- osbot_utils/utils/Objects.py +9 -1
- osbot_utils/version +1 -1
- {osbot_utils-2.28.0.dist-info → osbot_utils-2.30.0.dist-info}/METADATA +2 -2
- {osbot_utils-2.28.0.dist-info → osbot_utils-2.30.0.dist-info}/RECORD +8 -8
- {osbot_utils-2.28.0.dist-info → osbot_utils-2.30.0.dist-info}/LICENSE +0 -0
- {osbot_utils-2.28.0.dist-info → osbot_utils-2.30.0.dist-info}/WHEEL +0 -0
@@ -1,3 +1,5 @@
|
|
1
|
+
from typing import Type
|
2
|
+
|
1
3
|
from osbot_utils.type_safe.Type_Safe__Base import Type_Safe__Base
|
2
4
|
|
3
5
|
class Type_Safe__Dict(Type_Safe__Base, dict):
|
@@ -27,6 +29,10 @@ class Type_Safe__Dict(Type_Safe__Base, dict):
|
|
27
29
|
|
28
30
|
result = {}
|
29
31
|
for key, value in self.items():
|
32
|
+
|
33
|
+
if isinstance(key, (type, Type)): # Handle Type objects as keys
|
34
|
+
key = f"{key.__module__}.{key.__name__}"
|
35
|
+
|
30
36
|
if isinstance(value, Type_Safe): # Handle Type_Safe objects in values
|
31
37
|
result[key] = value.json()
|
32
38
|
elif isinstance(value, (list, tuple)): # Handle lists/tuples that might contain Type_Safe objects
|
@@ -110,7 +110,7 @@ class Type_Safe__Step__From_Json:
|
|
110
110
|
|
111
111
|
return _self
|
112
112
|
|
113
|
-
def deserialize_type__using_value(self, value):
|
113
|
+
def deserialize_type__using_value(self, value): # TODO: Check the security implications of this deserialisation
|
114
114
|
if value:
|
115
115
|
try:
|
116
116
|
module_name, type_name = value.rsplit('.', 1)
|
@@ -139,9 +139,16 @@ class Type_Safe__Step__From_Json:
|
|
139
139
|
for dict_key, dict_value in value.items():
|
140
140
|
key_origin = type_safe_cache.get_origin(key_class)
|
141
141
|
if key_origin is type:
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
if type(dict_key) is str:
|
143
|
+
dict_key = self.deserialize_type__using_value(dict_key)
|
144
|
+
key_class_args = get_args(key_class)
|
145
|
+
if key_class_args:
|
146
|
+
expected_dict_type = key_class_args[0]
|
147
|
+
if dict_key != expected_dict_type and not issubclass(dict_key,expected_dict_type):
|
148
|
+
raise TypeError(f"Expected {expected_dict_type} class for key but got instance: {dict_key}")
|
149
|
+
else:
|
150
|
+
if not isinstance(dict_key, key_class):
|
151
|
+
raise TypeError(f"Expected {key_class} class for key but got instance: {dict_key}")
|
145
152
|
new__dict_key = dict_key
|
146
153
|
elif issubclass(key_class, Type_Safe):
|
147
154
|
new__dict_key = self.deserialize_from_dict(key_class(), dict_key)
|
osbot_utils/utils/Objects.py
CHANGED
@@ -284,7 +284,15 @@ def serialize_to_dict(obj):
|
|
284
284
|
elif isinstance(obj, set):
|
285
285
|
return [serialize_to_dict(item) for item in obj]
|
286
286
|
elif isinstance(obj, dict):
|
287
|
-
|
287
|
+
serialized_dict = {} # todo: refactor to separate method
|
288
|
+
for key, value in obj.items():
|
289
|
+
if isinstance(key, type): # Handle type keys by converting to fully qualified string
|
290
|
+
serialized_key = f"{key.__module__}.{key.__name__}"
|
291
|
+
else:
|
292
|
+
serialized_key = key
|
293
|
+
serialized_dict[serialized_key] = serialize_to_dict(value) # Recursively serialize the value
|
294
|
+
return serialized_dict
|
295
|
+
#return {key: serialize_to_dict(value) for key, value in obj.items()}
|
288
296
|
elif hasattr(obj, "__dict__"):
|
289
297
|
data = {} # todo: look at a more advanced version which saved the type of the object, for example with {'__type__': type(obj).__name__}
|
290
298
|
for key, value in obj.__dict__.items():
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v2.
|
1
|
+
v2.30.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.30.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
|
|
@@ -296,7 +296,7 @@ osbot_utils/testing/performance/models/Model__Performance_Measure__Result.py,sha
|
|
296
296
|
osbot_utils/testing/performance/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
297
297
|
osbot_utils/type_safe/Type_Safe.py,sha256=LOWRGOGpnRU2iTRLP47vUoyalK0vjFrWlnaghBIogWg,6267
|
298
298
|
osbot_utils/type_safe/Type_Safe__Base.py,sha256=Bzrh8TxFglB0FEUAQTlgovlnFHnBN4lOX1Vu327r1Vc,5223
|
299
|
-
osbot_utils/type_safe/Type_Safe__Dict.py,sha256=
|
299
|
+
osbot_utils/type_safe/Type_Safe__Dict.py,sha256=yEswrqWcYoL97eeeSXRAdIqsz9MjLdC1F6nnuq7JS3s,2700
|
300
300
|
osbot_utils/type_safe/Type_Safe__List.py,sha256=SzSIBkwSOAEpW_V2qh4-f0YHzmgB0T8PczBLbDgZGvg,1340
|
301
301
|
osbot_utils/type_safe/Type_Safe__Method.py,sha256=LOG2sqQyKBNNEiJxk_jngH6IWvpyVueouAzNTlj-_pY,12676
|
302
302
|
osbot_utils/type_safe/Type_Safe__Set.py,sha256=j12fc8cbd9-s_a13ysaz723rNEW4Dt6hObCd0S-AjIg,1432
|
@@ -319,7 +319,7 @@ osbot_utils/type_safe/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NM
|
|
319
319
|
osbot_utils/type_safe/steps/Type_Safe__Step__Class_Kwargs.py,sha256=snoyJKvZ1crgF2fp0zexwNPnV_E63RfyRIsMAZdrKNY,6995
|
320
320
|
osbot_utils/type_safe/steps/Type_Safe__Step__Default_Kwargs.py,sha256=tzKXDUc0HVP5QvCWsmcPuuZodNvQZ9FeMDNI2x00Ngw,1943
|
321
321
|
osbot_utils/type_safe/steps/Type_Safe__Step__Default_Value.py,sha256=K_tkVQyLUbbWYzDnzoPLCgDBAFYyUjAG4VdLsvjzL1g,4485
|
322
|
-
osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py,sha256=
|
322
|
+
osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py,sha256=yy3QrfYd1WMakWvFfDYa-ECajv6hMPY7o0x4xTAHbZs,13042
|
323
323
|
osbot_utils/type_safe/steps/Type_Safe__Step__Init.py,sha256=v4FD7zxQiOFLiOF1Ma8wZMP8aLgRlXwJZnsIfBu2zeg,1266
|
324
324
|
osbot_utils/type_safe/steps/Type_Safe__Step__Set_Attr.py,sha256=VuKHH9QEYlbAL9R4zwQ5dwexx2sFY6wMx52QmF7eqcg,5219
|
325
325
|
osbot_utils/type_safe/steps/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -343,7 +343,7 @@ osbot_utils/utils/Json.py,sha256=TvfDoXwOkWzWH-9KMnme5C7iFsMZOleAeue92qmkH6g,883
|
|
343
343
|
osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
|
344
344
|
osbot_utils/utils/Lists.py,sha256=tPz5x5s3sRO97WZ_nsxREBPC5cwaHrhgaYBhsrffTT8,5599
|
345
345
|
osbot_utils/utils/Misc.py,sha256=H_xexJgiTxB3jDeDiW8efGQbO0Zuy8MM0iQ7qXC92JI,17363
|
346
|
-
osbot_utils/utils/Objects.py,sha256=
|
346
|
+
osbot_utils/utils/Objects.py,sha256=RqHzikmIDuqWUbnn7Lxd5ZkIa6smYJmRP6jM0Re5Awk,13471
|
347
347
|
osbot_utils/utils/Png.py,sha256=V1juGp6wkpPigMJ8HcxrPDIP4bSwu51oNkLI8YqP76Y,1172
|
348
348
|
osbot_utils/utils/Process.py,sha256=lr3CTiEkN3EiBx3ZmzYmTKlQoPdkgZBRjPulMxG-zdo,2357
|
349
349
|
osbot_utils/utils/Python_Logger.py,sha256=M9Oi62LxfnRSlCN8GhaiwiBINvcSdGy39FCWjyDD-Xg,12792
|
@@ -355,8 +355,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
|
|
355
355
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
356
356
|
osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
|
357
357
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
358
|
-
osbot_utils/version,sha256=
|
359
|
-
osbot_utils-2.
|
360
|
-
osbot_utils-2.
|
361
|
-
osbot_utils-2.
|
362
|
-
osbot_utils-2.
|
358
|
+
osbot_utils/version,sha256=yHbqsyTtzLh9SfdLRSqp3t4wKZmWSYYIo9w2bDpbXnw,8
|
359
|
+
osbot_utils-2.30.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
360
|
+
osbot_utils-2.30.0.dist-info/METADATA,sha256=LAH0B4WB2lteq-ABcbqfnZh5LvicUKyoCuVb1TAIz_4,1329
|
361
|
+
osbot_utils-2.30.0.dist-info/WHEEL,sha256=XbeZDeTWKc1w7CSIyre5aMDU_-PohRwTQceYnisIYYY,88
|
362
|
+
osbot_utils-2.30.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|