osbot-utils 1.63.0__py3-none-any.whl → 1.65.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.
@@ -16,10 +16,10 @@ from osbot_utils.helpers.Timestamp_Now import Timestamp_Now
16
16
  from osbot_utils.utils.Dev import pprint
17
17
  from osbot_utils.utils.Json import json_parse
18
18
  from osbot_utils.utils.Misc import list_set
19
- from osbot_utils.utils.Objects import default_value, value_type_matches_obj_annotation_for_attr, \
19
+ from osbot_utils.utils.Objects import default_value, value_type_matches_obj_annotation_for_attr, \
20
20
  raise_exception_on_obj_type_annotation_mismatch, obj_is_attribute_annotation_of_type, enum_from_value, \
21
21
  obj_is_type_union_compatible, value_type_matches_obj_annotation_for_union_attr, \
22
- convert_dict_to_value_from_obj_annotation, dict_to_obj
22
+ convert_dict_to_value_from_obj_annotation, dict_to_obj, convert_str_to_value_from_obj_annotation
23
23
 
24
24
  # Backport implementations of get_origin and get_args for Python 3.7
25
25
  if sys.version_info < (3, 8): # pragma: no cover
@@ -99,6 +99,8 @@ class Type_Safe:
99
99
  if value is not None:
100
100
  if type(value) is dict:
101
101
  value = convert_dict_to_value_from_obj_annotation(self, name, value)
102
+ if type(value) is str:
103
+ value = convert_str_to_value_from_obj_annotation (self, name, value)
102
104
  check_1 = value_type_matches_obj_annotation_for_attr (self, name, value)
103
105
  check_2 = value_type_matches_obj_annotation_for_union_attr(self, name, value)
104
106
  if (check_1 is False and check_2 is None or
@@ -1,14 +1,14 @@
1
1
  # todo add to osbot utils
2
- from osbot_utils.utils.Misc import random_guid
2
+ from osbot_utils.utils.Misc import random_guid, is_guid
3
+
3
4
 
4
5
  class Random_Guid(str):
5
6
  def __new__(cls, value=None):
6
7
  if value is None:
7
8
  value = random_guid()
8
- return str.__new__(cls, value)
9
-
10
- def __init__(self, value=None):
11
- self.value = value if value is not None else random_guid()
9
+ if is_guid(value):
10
+ return str.__new__(cls, value)
11
+ raise ValueError(f'in Random_Guid: value provided was not a Guid: {value}')
12
12
 
13
13
  def __str__(self):
14
14
  return self
@@ -5,12 +5,12 @@ import pickle
5
5
  import sys
6
6
  import types
7
7
  import typing
8
- from collections.abc import Mapping
9
-
10
- from typing import Union
11
- from types import SimpleNamespace
12
- from osbot_utils.utils.Misc import list_set
13
- from osbot_utils.utils.Str import str_unicode_escape, str_max_width
8
+ from collections.abc import Mapping
9
+ from typing import Union
10
+ from types import SimpleNamespace
11
+ from osbot_utils.helpers.Random_Guid import Random_Guid
12
+ from osbot_utils.utils.Misc import list_set
13
+ from osbot_utils.utils.Str import str_unicode_escape, str_max_width
14
14
 
15
15
  # Backport implementations of get_origin and get_args for Python 3.7
16
16
  if sys.version_info < (3, 8):
@@ -95,7 +95,7 @@ def class_full_name(target):
95
95
  type_name = type_target.__name__
96
96
  return f'{type_module}.{type_name}'
97
97
 
98
- def convert_dict_to_value_from_obj_annotation(target, attr_name, value):
98
+ def convert_dict_to_value_from_obj_annotation(target, attr_name, value): # todo: refactor this with code from convert_str_to_value_from_obj_annotation since it is mostly the same
99
99
  if target is not None and attr_name is not None:
100
100
  if hasattr(target, '__annotations__'):
101
101
  obj_annotations = target.__annotations__
@@ -105,6 +105,17 @@ def convert_dict_to_value_from_obj_annotation(target, attr_name, value):
105
105
  return attribute_annotation(**value)
106
106
  return value
107
107
 
108
+ def convert_str_to_value_from_obj_annotation(target, attr_name, value): # todo: see the side effects of doing this for all strings
109
+ if target is not None and attr_name is not None:
110
+ if hasattr(target, '__annotations__'):
111
+ obj_annotations = target.__annotations__
112
+ if hasattr(obj_annotations,'get'):
113
+ attribute_annotation = obj_annotations.get(attr_name)
114
+ if 'str' in base_classes_names(attribute_annotation): # todo: figure out a better way to handle these special type casting (used for example by Random_Guid)
115
+ if attribute_annotation == Random_Guid: # and add support for other types like int (which is used my Timestamp_Now)
116
+ return attribute_annotation(value)
117
+ return value
118
+
108
119
 
109
120
  def default_value(target : type):
110
121
  try:
@@ -382,7 +393,6 @@ def value_type_matches_obj_annotation_for_attr(target, attr_name, value):
382
393
  return True
383
394
  if are_types_magic_mock(source_type=value_type, target_type=attr_type):
384
395
  return True
385
-
386
396
  return value_type is attr_type
387
397
  return None
388
398
 
osbot_utils/version CHANGED
@@ -1 +1 @@
1
- v1.63.0
1
+ v1.65.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: osbot_utils
3
- Version: 1.63.0
3
+ Version: 1.65.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
- ![Current Release](https://img.shields.io/badge/release-v1.63.0-blue)
26
+ ![Current Release](https://img.shields.io/badge/release-v1.65.0-blue)
27
27
  [![codecov](https://codecov.io/gh/owasp-sbot/OSBot-Utils/graph/badge.svg?token=GNVW0COX1N)](https://codecov.io/gh/owasp-sbot/OSBot-Utils)
28
28
 
29
29
 
@@ -2,7 +2,7 @@ osbot_utils/__init__.py,sha256=DdJDmQc9zbQUlPVyTJOww6Ixrn9n4bD3ami5ItQfzJI,16
2
2
  osbot_utils/base_classes/Cache_Pickle.py,sha256=kPCwrgUbf_dEdxUz7vW1GuvIPwlNXxuRhb-H3AbSpII,5884
3
3
  osbot_utils/base_classes/Kwargs_To_Disk.py,sha256=HHoy05NC_w35WcT-OnSKoSIV_cLqaU9rdjH0_KNTM0E,1096
4
4
  osbot_utils/base_classes/Kwargs_To_Self.py,sha256=weFNsBfBNV9W_qBkN-IdBD4yYcJV_zgTxBRO-ZlcPS4,141
5
- osbot_utils/base_classes/Type_Safe.py,sha256=eWdLnt-vRqr6bX1TR3tINSqm2KeVXQSzQs6pxq0Ep5I,18476
5
+ osbot_utils/base_classes/Type_Safe.py,sha256=FH_q3PJb_Fa4FAjG1fzuaEAt-lv7Ila-2ZNPd_Ohors,18621
6
6
  osbot_utils/base_classes/Type_Safe__List.py,sha256=-80C9OhsK6iDR2dAG8yNLAZV0qg5x3faqvSUigFCMJw,517
7
7
  osbot_utils/base_classes/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
8
  osbot_utils/context_managers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -65,7 +65,7 @@ osbot_utils/helpers/Local_Cache.py,sha256=0JZZX3fFImcwtbBvxAQl-EbBegSNJRhRMYF6ov
65
65
  osbot_utils/helpers/Local_Caches.py,sha256=aQmi1HSM0TH6WQPedG2fbz4KCCJ3DQTU9d18rB1jR0M,1885
66
66
  osbot_utils/helpers/Print_Table.py,sha256=LEXbyqGg_6WSraI4cob4bNNSu18ddqvALp1zGK7bPhs,19126
67
67
  osbot_utils/helpers/Python_Audit.py,sha256=shpZlluJwqJBAlad6xN01FkgC1TsQ48RLvR5ZjmrKa4,1539
68
- osbot_utils/helpers/Random_Guid.py,sha256=_wlyM17SIr-FeYESwnVt4cfkEtRRf-dbYh_lTnrKVG0,379
68
+ osbot_utils/helpers/Random_Guid.py,sha256=JvAFxbF8XUE0l1Jg6CmdaKxuYFIfYJGd49cOZJdmZ4Y,400
69
69
  osbot_utils/helpers/Random_Guid_Short.py,sha256=YP_k5OLuYvXWGU2OEnQHk_OGViBQofTWKm3pUdQaJao,404
70
70
  osbot_utils/helpers/Random_Seed.py,sha256=14btja8LDN9cMGWaz4fCNcMRU_eyx49gas-_PQvHgy4,634
71
71
  osbot_utils/helpers/Timestamp_Now.py,sha256=Vmdsm-pgvxkkQ_Qj_9Watr8rXXSvc-aBxWMPFGQx8Z0,371
@@ -293,7 +293,7 @@ osbot_utils/utils/Json.py,sha256=yIT2hUI23gYd24Uf3LCjqPNV67zS46rYZftcCM3jw-Q,649
293
293
  osbot_utils/utils/Json_Cache.py,sha256=mLPkkDZN-3ZVJiDvV1KBJXILtKkTZ4OepzOsDoBPhWg,2006
294
294
  osbot_utils/utils/Lists.py,sha256=tPz5x5s3sRO97WZ_nsxREBPC5cwaHrhgaYBhsrffTT8,5599
295
295
  osbot_utils/utils/Misc.py,sha256=4MkG2BE1VzZfV4KPzYZ4jVAoUwoA3pTTVPi609ldLGA,16961
296
- osbot_utils/utils/Objects.py,sha256=_BWr7KA8Xzzxu6fyxHSqDqDM1Pkyr5IZUFo_hMf7oTo,17612
296
+ osbot_utils/utils/Objects.py,sha256=vPJdfpzwSRykcVkVT-ztaCC_52AWPVey9uWrJ9rAvZ8,18722
297
297
  osbot_utils/utils/Png.py,sha256=V1juGp6wkpPigMJ8HcxrPDIP4bSwu51oNkLI8YqP76Y,1172
298
298
  osbot_utils/utils/Process.py,sha256=lr3CTiEkN3EiBx3ZmzYmTKlQoPdkgZBRjPulMxG-zdo,2357
299
299
  osbot_utils/utils/Python_Logger.py,sha256=tx8N6wRKL3RDHboDRKZn8SirSJdSAE9cACyJkxrThZ8,12792
@@ -305,8 +305,8 @@ osbot_utils/utils/Toml.py,sha256=SD6IA4-mrtoBXcI0dIGKV9POMQNd6WYKvmDQq7GQ6ZQ,143
305
305
  osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
306
306
  osbot_utils/utils/Zip.py,sha256=G6Hk_hDcm9yvWzhTKzhT0R_6f0NBIAchHqMxGb3kfh4,14037
307
307
  osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
308
- osbot_utils/version,sha256=2IflaXKoRpTJA1_I8a84R90o-JFwLcsc7YlBVt7zn4o,8
309
- osbot_utils-1.63.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
310
- osbot_utils-1.63.0.dist-info/METADATA,sha256=ow3SezUF70n12L-FywN1kJe8qAJy4c3u7kHT4HZVBp0,1317
311
- osbot_utils-1.63.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
312
- osbot_utils-1.63.0.dist-info/RECORD,,
308
+ osbot_utils/version,sha256=6rsAH6KPsBZcwclONfSWT6iY8kMQH684ZSqdZ73t7m0,8
309
+ osbot_utils-1.65.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
310
+ osbot_utils-1.65.0.dist-info/METADATA,sha256=DdYjLZWifnhmxlOX4Bl9jcJqZg4qY82E-7km6kF279g,1317
311
+ osbot_utils-1.65.0.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
312
+ osbot_utils-1.65.0.dist-info/RECORD,,