osbot-utils 2.1.0__py3-none-any.whl → 2.2.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/helpers/sqlite/Sqlite__Table__Create.py +3 -4
- osbot_utils/helpers/sqlite/sample_data/Sqlite__Sample_Data__Chinook.py +7 -13
- osbot_utils/helpers/xml/rss/RSS__Channel.py +1 -1
- osbot_utils/type_safe/Type_Safe.py +21 -10
- osbot_utils/version +1 -1
- {osbot_utils-2.1.0.dist-info → osbot_utils-2.2.0.dist-info}/METADATA +3 -3
- {osbot_utils-2.1.0.dist-info → osbot_utils-2.2.0.dist-info}/RECORD +9 -9
- {osbot_utils-2.1.0.dist-info → osbot_utils-2.2.0.dist-info}/WHEEL +1 -1
- {osbot_utils-2.1.0.dist-info → osbot_utils-2.2.0.dist-info}/LICENSE +0 -0
@@ -1,6 +1,5 @@
|
|
1
1
|
import inspect
|
2
|
-
from typing
|
3
|
-
|
2
|
+
from typing import List
|
4
3
|
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
|
5
4
|
from osbot_utils.decorators.lists.filter_list import filter_list
|
6
5
|
from osbot_utils.helpers.sqlite.Sqlite__Field import Sqlite__Field
|
@@ -17,8 +16,8 @@ class Sqlite__Table__Create(Kwargs_To_Self):
|
|
17
16
|
self.set_default_fields()
|
18
17
|
|
19
18
|
def add_field(self, field_data: dict):
|
20
|
-
|
21
|
-
|
19
|
+
if field_data and isinstance(field_data, dict):
|
20
|
+
sqlite_field = Sqlite__Field.from_json(field_data)
|
22
21
|
self.fields.append(sqlite_field)
|
23
22
|
return True
|
24
23
|
return False
|
@@ -1,16 +1,10 @@
|
|
1
|
-
from osbot_utils.base_classes.Kwargs_To_Self
|
2
|
-
from osbot_utils.decorators.methods.cache_on_self
|
3
|
-
from osbot_utils.helpers.sqlite.Sqlite__Database
|
4
|
-
from osbot_utils.helpers.sqlite.
|
5
|
-
from osbot_utils.
|
6
|
-
from osbot_utils.
|
7
|
-
from osbot_utils.
|
8
|
-
from osbot_utils.utils.Dev import pprint
|
9
|
-
from osbot_utils.utils.Files import current_temp_folder, path_combine, folder_create, file_exists, file_not_exists, \
|
10
|
-
file_contents
|
11
|
-
from osbot_utils.utils.Http import GET, GET_to_file
|
12
|
-
from osbot_utils.utils.Json import json_loads, json_from_file, json_dump, json_file_create, json_file_load
|
13
|
-
from osbot_utils.utils.Objects import obj_info
|
1
|
+
from osbot_utils.base_classes.Kwargs_To_Self import Kwargs_To_Self
|
2
|
+
from osbot_utils.decorators.methods.cache_on_self import cache_on_self
|
3
|
+
from osbot_utils.helpers.sqlite.Sqlite__Database import Sqlite__Database
|
4
|
+
from osbot_utils.helpers.sqlite.domains.Sqlite__DB__Json import Sqlite__DB__Json
|
5
|
+
from osbot_utils.utils.Files import current_temp_folder, path_combine, folder_create, file_not_exists
|
6
|
+
from osbot_utils.utils.Http import GET_to_file
|
7
|
+
from osbot_utils.utils.Json import json_from_file, json_file_create, json_file_load
|
14
8
|
|
15
9
|
URL__CHINOOK_JSON = 'https://github.com/lerocha/chinook-database/releases/download/v1.4.5/ChinookData.json'
|
16
10
|
FILE_NAME__CHINOOK_DATA_JSON = 'ChinookData.json'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
from typing import Any, Dict, List
|
2
|
-
from osbot_utils.type_safe.Type_Safe
|
2
|
+
from osbot_utils.type_safe.Type_Safe import Type_Safe
|
3
3
|
from osbot_utils.helpers.xml.rss.RSS__Image import RSS__Image
|
4
4
|
from osbot_utils.helpers.xml.rss.RSS__Item import RSS__Item
|
5
5
|
|
@@ -24,7 +24,7 @@ if sys.version_info < (3, 8): # pragma
|
|
24
24
|
else:
|
25
25
|
return ()
|
26
26
|
else:
|
27
|
-
from typing import get_origin, get_args, ForwardRef
|
27
|
+
from typing import get_origin, get_args, ForwardRef, Any
|
28
28
|
from osbot_utils.helpers.python_compatibility.python_3_8 import Annotated
|
29
29
|
|
30
30
|
if sys.version_info >= (3, 10):
|
@@ -117,12 +117,16 @@ class Type_Safe:
|
|
117
117
|
# todo: refactor this to separate method
|
118
118
|
if hasattr(annotations, 'get'):
|
119
119
|
annotation = annotations.get(name)
|
120
|
-
if annotation
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
120
|
+
if annotation:
|
121
|
+
annotation_origin = get_origin(annotation)
|
122
|
+
if annotation_origin is Annotated:
|
123
|
+
annotation_args = get_args(annotation)
|
124
|
+
target_type = annotation_args[0]
|
125
|
+
for attribute in annotation_args[1:]:
|
126
|
+
if isinstance(attribute, Type_Safe__Validator):
|
127
|
+
attribute.validate(value=value, field_name=name, target_type=target_type)
|
128
|
+
elif annotation_origin is dict:
|
129
|
+
value = self.deserialize_dict__using_key_value_annotations(name, value)
|
126
130
|
|
127
131
|
super().__setattr__(name, value)
|
128
132
|
|
@@ -341,8 +345,12 @@ class Type_Safe:
|
|
341
345
|
else:
|
342
346
|
new__dict_key = key_class(dict_key)
|
343
347
|
|
344
|
-
if
|
348
|
+
if type(dict_value) == value_class: # if the value is already the target, then just use it
|
349
|
+
new__dict_value = dict_value
|
350
|
+
elif issubclass(value_class, Type_Safe):
|
345
351
|
new__dict_value = value_class().deserialize_from_dict(dict_value)
|
352
|
+
elif value_class is Any:
|
353
|
+
new__dict_value = dict_value
|
346
354
|
else:
|
347
355
|
new__dict_value = value_class(dict_value)
|
348
356
|
new_value[new__dict_key] = new__dict_value
|
@@ -353,7 +361,7 @@ class Type_Safe:
|
|
353
361
|
def deserialize_from_dict(self, data, raise_on_not_found=False):
|
354
362
|
from decimal import Decimal
|
355
363
|
from enum import EnumMeta
|
356
|
-
from osbot_utils.type_safe.Type_Safe__List
|
364
|
+
from osbot_utils.type_safe.Type_Safe__List import Type_Safe__List
|
357
365
|
from osbot_utils.helpers.Random_Guid import Random_Guid
|
358
366
|
from osbot_utils.helpers.Random_Guid_Short import Random_Guid_Short
|
359
367
|
from osbot_utils.utils.Objects import obj_is_attribute_annotation_of_type
|
@@ -362,6 +370,9 @@ class Type_Safe:
|
|
362
370
|
from osbot_utils.helpers.Safe_Id import Safe_Id
|
363
371
|
from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
|
364
372
|
|
373
|
+
if hasattr(data, 'items') is False:
|
374
|
+
raise ValueError(f"Expected a dictionary, but got '{type(data)}'")
|
375
|
+
|
365
376
|
for key, value in data.items():
|
366
377
|
if hasattr(self, key) and isinstance(getattr(self, key), Type_Safe):
|
367
378
|
getattr(self, key).deserialize_from_dict(value) # if the attribute is a Type_Safe object, then also deserialize it
|
@@ -432,7 +443,7 @@ class Type_Safe:
|
|
432
443
|
json_data = json_parse(json_data)
|
433
444
|
if json_data: # if there is no data or is {} then don't create an object (since this could be caused by bad data being provided)
|
434
445
|
return cls().deserialize_from_dict(json_data,raise_on_not_found=raise_on_not_found)
|
435
|
-
return
|
446
|
+
return cls()
|
436
447
|
|
437
448
|
# todo: see if it is possible to add recursive protection to this logic
|
438
449
|
def serialize_to_dict(obj):
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v2.
|
1
|
+
v2.2.0
|
@@ -1,6 +1,6 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.3
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.2.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
|
|
@@ -191,7 +191,7 @@ osbot_utils/helpers/sqlite/Sqlite__Database.py,sha256=Ts0qM3Nakot5o9wbFaaW3iq2pD
|
|
191
191
|
osbot_utils/helpers/sqlite/Sqlite__Field.py,sha256=oBWglAOKN0EWVtaRwiQFxmR1FQ61lQ35yKkWXjSiihs,2911
|
192
192
|
osbot_utils/helpers/sqlite/Sqlite__Globals.py,sha256=aP6uIy_y4xzl2soTUCFIJRjsb8JyfxfL6qIEZKIWy_4,230
|
193
193
|
osbot_utils/helpers/sqlite/Sqlite__Table.py,sha256=FsFSolFN2N5V8DfZPp4gZL9xmCXaOhmG38wQmgRrvp8,15145
|
194
|
-
osbot_utils/helpers/sqlite/Sqlite__Table__Create.py,sha256=
|
194
|
+
osbot_utils/helpers/sqlite/Sqlite__Table__Create.py,sha256=Kkp0KbAF9mYOMz6LCmo10aa1n3rci0fFDlV7DPA-gxs,3932
|
195
195
|
osbot_utils/helpers/sqlite/Temp_Sqlite__Database__Disk.py,sha256=-BhK0_3lSJPWDt-QS8IQDfrw2K_drjtn-yXyf9GbER4,520
|
196
196
|
osbot_utils/helpers/sqlite/Temp_Sqlite__Table.py,sha256=Na2dOHlYSVUKK7STHwdzBYbQgvW2a6cEhUnlC0-T8wk,729
|
197
197
|
osbot_utils/helpers/sqlite/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
@@ -212,7 +212,7 @@ osbot_utils/helpers/sqlite/domains/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQe
|
|
212
212
|
osbot_utils/helpers/sqlite/domains/schemas/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
213
213
|
osbot_utils/helpers/sqlite/models/Sqlite__Field__Type.py,sha256=4xsnRLrU13ZT1GisVQZYFn3m7sw6DbY6pg3cg3Ug2cI,1114
|
214
214
|
osbot_utils/helpers/sqlite/models/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
215
|
-
osbot_utils/helpers/sqlite/sample_data/Sqlite__Sample_Data__Chinook.py,sha256=
|
215
|
+
osbot_utils/helpers/sqlite/sample_data/Sqlite__Sample_Data__Chinook.py,sha256=ouymaJaaWLP6ZVWOj-OmkeSyDQQadsPQT0B_S9fodD4,5190
|
216
216
|
osbot_utils/helpers/sqlite/sample_data/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
217
217
|
osbot_utils/helpers/sqlite/sql_builder/SQL_Builder.py,sha256=VPI1Fu3RjVJoXhwcVI3_fa9IiWY4b2uTjKx6yw4pfQM,10782
|
218
218
|
osbot_utils/helpers/sqlite/sql_builder/SQL_Builder__Select.py,sha256=_5fszoWTknE0r93hS4zuqikbB0L4bnYKRxSFNVSxx2s,360
|
@@ -250,7 +250,7 @@ osbot_utils/helpers/xml/Xml__File__Load.py,sha256=zvs5yGLk5wf16zadWcTD97R4ltn_Hl
|
|
250
250
|
osbot_utils/helpers/xml/Xml__File__To_Dict.py,sha256=YqOOZ_YYSFteCG-oJu3V2Sg9Rr4w2cARv52G3BnfbIY,2058
|
251
251
|
osbot_utils/helpers/xml/Xml__File__To_Xml.py,sha256=j_JyEsjKGp1TUxAKECHKRo_mlyO0wjR3x_rGb_dn52M,2881
|
252
252
|
osbot_utils/helpers/xml/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
253
|
-
osbot_utils/helpers/xml/rss/RSS__Channel.py,sha256=
|
253
|
+
osbot_utils/helpers/xml/rss/RSS__Channel.py,sha256=BpkP4OMV_H6usvXhdQ8ahJFxYbtwfkRuoP37_gcIP-A,605
|
254
254
|
osbot_utils/helpers/xml/rss/RSS__Enclosure.py,sha256=9lUsIVJ4TkR_mBFDc6-ISMg7fPXe8FiKFSWjpnlWIMY,139
|
255
255
|
osbot_utils/helpers/xml/rss/RSS__Feed.py,sha256=W4T2rmJoZr4kfOPSkZXkkKPnOk5bPlZfLzOf7pah9LQ,422
|
256
256
|
osbot_utils/helpers/xml/rss/RSS__Feed__Parser.py,sha256=7sub6zcWqGz8FORXFYRyopTswboUkCU5uGEXAZ6BZDw,5380
|
@@ -278,7 +278,7 @@ osbot_utils/testing/Temp_Zip_In_Memory.py,sha256=ibDIWt3K4CX558PbkLbX3InHyWYZcwQ
|
|
278
278
|
osbot_utils/testing/Unit_Test.py,sha256=MReR_wDGbbXFDPz7cmuGflcTxRB6TBnO9mYqRpSq8Pk,1304
|
279
279
|
osbot_utils/testing/Unzip_File.py,sha256=V5H97XO9rlvG5EYOSzAH4kTtAH1ohZ8R8ImvJh46ZNg,1177
|
280
280
|
osbot_utils/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
281
|
-
osbot_utils/type_safe/Type_Safe.py,sha256=
|
281
|
+
osbot_utils/type_safe/Type_Safe.py,sha256=irrNiwWQHV4eP2dq9aKYDIETsG375U9U055YPZX1uQw,29658
|
282
282
|
osbot_utils/type_safe/Type_Safe_Method.py,sha256=8E88of__An9_ZhJKz6Kp22C1mb9WLED0jWNLOII3fJs,10489
|
283
283
|
osbot_utils/type_safe/Type_Safe__Base.py,sha256=mL8GMaR9tsaUfwk8d-8zp2g-A8kNKiN6kroEFaNvMOk,5518
|
284
284
|
osbot_utils/type_safe/Type_Safe__Dict.py,sha256=I_Ac0JH-ahmQrkADFVyiobTlH1JI31MKHaNszQW4PBo,2396
|
@@ -316,8 +316,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
|
|
316
316
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
317
317
|
osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
|
318
318
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
319
|
-
osbot_utils/version,sha256
|
320
|
-
osbot_utils-2.
|
321
|
-
osbot_utils-2.
|
322
|
-
osbot_utils-2.
|
323
|
-
osbot_utils-2.
|
319
|
+
osbot_utils/version,sha256=uVurYQGLXTbYEagaxFAAZWDtcu72lhVJSfloDcK8tAU,7
|
320
|
+
osbot_utils-2.2.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
321
|
+
osbot_utils-2.2.0.dist-info/METADATA,sha256=k3jcHtdqYaJdLQDq7UJ_l2cIy0O3V6yj7rDUwkz54KE,1315
|
322
|
+
osbot_utils-2.2.0.dist-info/WHEEL,sha256=RaoafKOydTQ7I_I3JTrPCg6kUmTgtm4BornzOqyEfJ8,88
|
323
|
+
osbot_utils-2.2.0.dist-info/RECORD,,
|
File without changes
|