osbot-utils 2.12.0__py3-none-any.whl → 2.13.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/Obj_Id.py +29 -0
- osbot_utils/testing/performance/Performance_Measure__Session.py +23 -3
- osbot_utils/type_safe/shared/Type_Safe__Convert.py +2 -1
- osbot_utils/type_safe/steps/Type_Safe__Step__Class_Kwargs.py +6 -2
- osbot_utils/version +1 -1
- {osbot_utils-2.12.0.dist-info → osbot_utils-2.13.0.dist-info}/METADATA +2 -2
- {osbot_utils-2.12.0.dist-info → osbot_utils-2.13.0.dist-info}/RECORD +9 -8
- {osbot_utils-2.12.0.dist-info → osbot_utils-2.13.0.dist-info}/LICENSE +0 -0
- {osbot_utils-2.12.0.dist-info → osbot_utils-2.13.0.dist-info}/WHEEL +0 -0
@@ -0,0 +1,29 @@
|
|
1
|
+
import random
|
2
|
+
|
3
|
+
_hex_table = [f"{i:02x}" for i in range(256)]
|
4
|
+
|
5
|
+
def is_obj_id(value: str):
|
6
|
+
var_type = type(value)
|
7
|
+
if var_type is Obj_Id:
|
8
|
+
return True
|
9
|
+
if var_type is str:
|
10
|
+
if len(value) == 8: # todo: add efficient check if we only have hex values
|
11
|
+
return True
|
12
|
+
return False
|
13
|
+
|
14
|
+
def new_obj_id():
|
15
|
+
return hex(random.getrandbits(32))[2:].zfill(8) # slice off '0x' and pad
|
16
|
+
|
17
|
+
class Obj_Id(str):
|
18
|
+
def __new__(cls, value: str=None):
|
19
|
+
if value:
|
20
|
+
if is_obj_id(value):
|
21
|
+
obj_id = value
|
22
|
+
else:
|
23
|
+
raise ValueError(f'in Obj_Id: value provided was not a valid Obj_Id: {value}')
|
24
|
+
else:
|
25
|
+
obj_id = new_obj_id()
|
26
|
+
return super().__new__(cls, obj_id) # Return a new instance of Guid initialized with the string version of the UUID
|
27
|
+
|
28
|
+
def __str__(self):
|
29
|
+
return self
|
@@ -11,6 +11,7 @@ MEASURE__INVOCATION__LOOPS = [1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377,
|
|
11
11
|
class Performance_Measure__Session(Type_Safe):
|
12
12
|
result : Model__Performance_Measure__Result = None # Current measurement result
|
13
13
|
assert_enabled: bool = True
|
14
|
+
padding : int = 30
|
14
15
|
|
15
16
|
def calculate_raw_score(self, times: List[int]) -> int: # Calculate raw performance score
|
16
17
|
if len(times) < 3: # Need at least 3 values for stability
|
@@ -89,11 +90,11 @@ class Performance_Measure__Session(Type_Safe):
|
|
89
90
|
print(f"Median : {measurement.median_time:,}ns")
|
90
91
|
print(f"StdDev : {measurement.stddev_time:,.2f}ns")
|
91
92
|
|
92
|
-
def print(self
|
93
|
+
def print(self): # Print measurement results
|
93
94
|
if not self.result:
|
94
95
|
print("No measurements taken yet")
|
95
96
|
return
|
96
|
-
print(f"{self.result.name:{padding}} | score: {self.result.final_score:7,d} ns | raw: {self.result.raw_score:7,d} ns") # Print name and normalized score
|
97
|
+
print(f"{self.result.name:{self.padding}} | score: {self.result.final_score:7,d} ns | raw: {self.result.raw_score:7,d} ns") # Print name and normalized score
|
97
98
|
|
98
99
|
return self
|
99
100
|
|
@@ -105,4 +106,23 @@ class Performance_Measure__Session(Type_Safe):
|
|
105
106
|
new_expected_time = last_expected_time * 5 # using last_expected_time * 5 as the upper limit (since these tests are significantly slowed in GitHUb Actions)
|
106
107
|
assert last_expected_time <= self.result.final_score <= new_expected_time, f"Performance changed for {self.result.name}: expected {last_expected_time} < {self.result.final_score:,d}ns, expected {new_expected_time}"
|
107
108
|
else:
|
108
|
-
assert self.result.final_score in expected_time, f"Performance changed for {self.result.name}: got {self.result.final_score:,d}ns, expected {expected_time}"
|
109
|
+
assert self.result.final_score in expected_time, f"Performance changed for {self.result.name}: got {self.result.final_score:,d}ns, expected {expected_time}"
|
110
|
+
|
111
|
+
def assert_time(self, *expected_time: int): # Assert that the final score matches the expected normalized time"""
|
112
|
+
if self.assert_enabled is False:
|
113
|
+
return
|
114
|
+
if in_github_action():
|
115
|
+
last_expected_time = expected_time[-1] + 100 # +100 in case it is 0
|
116
|
+
new_expected_time = last_expected_time * 5 # using last_expected_time * 5 as the upper limit (since these tests are significantly slowed in GitHUb Actions)
|
117
|
+
assert last_expected_time <= self.result.final_score <= new_expected_time, f"Performance changed for {self.result.name}: expected {last_expected_time} < {self.result.final_score:,d}ns, expected {new_expected_time}"
|
118
|
+
else:
|
119
|
+
assert self.result.final_score in expected_time, f"Performance changed for {self.result.name}: got {self.result.final_score:,d}ns, expected {expected_time}"
|
120
|
+
|
121
|
+
def assert_time__less_than(self, max_time: int): # Assert that the final score matches the expected normalized time"""
|
122
|
+
if self.assert_enabled is False:
|
123
|
+
return
|
124
|
+
if in_github_action():
|
125
|
+
max_time = max_time * 5 # adjust for GitHub's slowness
|
126
|
+
|
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
|
+
|
@@ -20,8 +20,9 @@ class Type_Safe__Convert:
|
|
20
20
|
from osbot_utils.helpers.Random_Guid import Random_Guid
|
21
21
|
from osbot_utils.helpers.Safe_Id import Safe_Id
|
22
22
|
from osbot_utils.helpers.Str_ASCII import Str_ASCII
|
23
|
+
from osbot_utils.helpers.Obj_Id import Obj_Id
|
23
24
|
|
24
|
-
TYPE_SAFE__CONVERT_VALUE__SUPPORTED_TYPES = [Guid, Random_Guid, Safe_Id, Str_ASCII, Timestamp_Now]
|
25
|
+
TYPE_SAFE__CONVERT_VALUE__SUPPORTED_TYPES = [Guid, Random_Guid, Safe_Id, Str_ASCII, Timestamp_Now, Obj_Id]
|
25
26
|
|
26
27
|
if target is not None and attr_name is not None:
|
27
28
|
if hasattr(target, '__annotations__'):
|
@@ -1,4 +1,6 @@
|
|
1
1
|
from typing import Dict, Any, Type
|
2
|
+
|
3
|
+
from osbot_utils.helpers.Obj_Id import Obj_Id
|
2
4
|
from osbot_utils.helpers.Random_Guid import Random_Guid
|
3
5
|
from osbot_utils.type_safe.shared.Type_Safe__Cache import Type_Safe__Cache, type_safe_cache
|
4
6
|
from osbot_utils.type_safe.shared.Type_Safe__Shared__Variables import IMMUTABLE_TYPES
|
@@ -43,8 +45,10 @@ class Type_Safe__Step__Class_Kwargs:
|
|
43
45
|
match = all(isinstance(value, IMMUTABLE_TYPES) for value in kwargs.values())
|
44
46
|
|
45
47
|
if match: # check for special cases that we can't cache (like Random_Guid)
|
46
|
-
|
47
|
-
|
48
|
+
annotations_types = list(dict(annotations).values())
|
49
|
+
if Random_Guid in annotations_types: # todo: need to add the other special cases (like Timestamp_Now)
|
50
|
+
return False
|
51
|
+
if Obj_Id in annotations_types: # we can't cache Obj_id, since this would give us the same ID everutime
|
48
52
|
return False
|
49
53
|
return match
|
50
54
|
|
osbot_utils/version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
v2.
|
1
|
+
v2.13.0
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.3
|
2
2
|
Name: osbot_utils
|
3
|
-
Version: 2.
|
3
|
+
Version: 2.13.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
|
|
@@ -40,6 +40,7 @@ osbot_utils/helpers/Guid.py,sha256=0Ay3TYYk2nPr-JRVRCMFxbr8OvoQomv5HjT7o5B7cos,8
|
|
40
40
|
osbot_utils/helpers/Hashicorp_Secrets.py,sha256=e2fWWHK6bubpAm1sw5y8X5kh2Hk5d4JyZCnUovZip5A,4232
|
41
41
|
osbot_utils/helpers/Local_Cache.py,sha256=0JZZX3fFImcwtbBvxAQl-EbBegSNJRhRMYF6ovTH6zY,3141
|
42
42
|
osbot_utils/helpers/Local_Caches.py,sha256=aQmi1HSM0TH6WQPedG2fbz4KCCJ3DQTU9d18rB1jR0M,1885
|
43
|
+
osbot_utils/helpers/Obj_Id.py,sha256=sdKlSmEUpie0kn9X4pnM0MjUr6sLu4WZLSNqsD8ynBg,926
|
43
44
|
osbot_utils/helpers/Print_Table.py,sha256=LEXbyqGg_6WSraI4cob4bNNSu18ddqvALp1zGK7bPhs,19126
|
44
45
|
osbot_utils/helpers/Python_Audit.py,sha256=shpZlluJwqJBAlad6xN01FkgC1TsQ48RLvR5ZjmrKa4,1539
|
45
46
|
osbot_utils/helpers/Random_Guid.py,sha256=COu9hcP51vzjk-ErECTFFaOWuOmW0eGJyMu8HXhaRXQ,382
|
@@ -277,7 +278,7 @@ osbot_utils/testing/Temp_Zip_In_Memory.py,sha256=ibDIWt3K4CX558PbkLbX3InHyWYZcwQ
|
|
277
278
|
osbot_utils/testing/Unit_Test.py,sha256=MReR_wDGbbXFDPz7cmuGflcTxRB6TBnO9mYqRpSq8Pk,1304
|
278
279
|
osbot_utils/testing/Unzip_File.py,sha256=V5H97XO9rlvG5EYOSzAH4kTtAH1ohZ8R8ImvJh46ZNg,1177
|
279
280
|
osbot_utils/testing/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
280
|
-
osbot_utils/testing/performance/Performance_Measure__Session.py,sha256=
|
281
|
+
osbot_utils/testing/performance/Performance_Measure__Session.py,sha256=_Nq9oVilWaFn-tjvakCw7ojYVzRas9XmQY66DJT1clk,9108
|
281
282
|
osbot_utils/testing/performance/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
282
283
|
osbot_utils/testing/performance/models/Model__Performance_Measure__Measurement.py,sha256=xT_uKzbSYo9AGiJgNmCHSt3ApneNNyKh8vsMVN6IJQ0,1127
|
283
284
|
osbot_utils/testing/performance/models/Model__Performance_Measure__Result.py,sha256=k9HJYNLmW6sjRVsfpduSxHFiVANc1zmYtO_Oz9azpW8,755
|
@@ -294,13 +295,13 @@ osbot_utils/type_safe/methods/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5N
|
|
294
295
|
osbot_utils/type_safe/methods/type_safe_property.py,sha256=DcJkOIs6swJtkglsZVKLyFSczCGSJISOVwAmvjCOQvo,1425
|
295
296
|
osbot_utils/type_safe/shared/Type_Safe__Annotations.py,sha256=nmVqCbhk4kUYrw_mdYqugxQlv4gM3NUUH89FYTHUg-c,1133
|
296
297
|
osbot_utils/type_safe/shared/Type_Safe__Cache.py,sha256=G03pmpds9sTwU5z5pNLssD_GTvVSIR11nGYbkV5KaiY,7913
|
297
|
-
osbot_utils/type_safe/shared/Type_Safe__Convert.py,sha256=
|
298
|
+
osbot_utils/type_safe/shared/Type_Safe__Convert.py,sha256=QtO6gEGjQ5EKJOE3bsy4EiVmUGmFbMnMHxZUJh18k2s,3015
|
298
299
|
osbot_utils/type_safe/shared/Type_Safe__Not_Cached.py,sha256=25FAl6SOLxdStco_rm9tgOYLfuKyBWheGdl7vVa56UU,800
|
299
300
|
osbot_utils/type_safe/shared/Type_Safe__Raise_Exception.py,sha256=pbru8k8CTQMNUfmFBndiJhg2KkqEYzFvJAPcNZHeHfQ,829
|
300
301
|
osbot_utils/type_safe/shared/Type_Safe__Shared__Variables.py,sha256=SuZGl9LryQX6IpOE0I_lbzClT-h17UNylC__-M8ltTY,129
|
301
302
|
osbot_utils/type_safe/shared/Type_Safe__Validation.py,sha256=h-PwDpJ6SX8y1b7VIXB0rCY3p2nJRpeNBAvJRO8xJQQ,15960
|
302
303
|
osbot_utils/type_safe/shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
303
|
-
osbot_utils/type_safe/steps/Type_Safe__Step__Class_Kwargs.py,sha256=
|
304
|
+
osbot_utils/type_safe/steps/Type_Safe__Step__Class_Kwargs.py,sha256=bDA2hcOYsmcYwFDwNCvj5GTrLGqU78DhWtrrvDEQ2hE,6987
|
304
305
|
osbot_utils/type_safe/steps/Type_Safe__Step__Default_Kwargs.py,sha256=tzKXDUc0HVP5QvCWsmcPuuZodNvQZ9FeMDNI2x00Ngw,1943
|
305
306
|
osbot_utils/type_safe/steps/Type_Safe__Step__Default_Value.py,sha256=48-kGfkPZvhjBIEfFumigUIWWGxXe6skHgFtCCGa0LY,3987
|
306
307
|
osbot_utils/type_safe/steps/Type_Safe__Step__From_Json.py,sha256=vVi98VZ4Xz82Lp10SIBxSgqWuF4FM3EzrbQORMg_WWc,9347
|
@@ -339,8 +340,8 @@ osbot_utils/utils/Toml.py,sha256=Rxl8gx7mni5CvBAK-Ai02EKw-GwtJdd3yeHT2kMloik,166
|
|
339
340
|
osbot_utils/utils/Version.py,sha256=Ww6ChwTxqp1QAcxOnztkTicShlcx6fbNsWX5xausHrg,422
|
340
341
|
osbot_utils/utils/Zip.py,sha256=pR6sKliUY0KZXmqNzKY2frfW-YVQEVbLKiyqQX_lc-8,14052
|
341
342
|
osbot_utils/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
342
|
-
osbot_utils/version,sha256=
|
343
|
-
osbot_utils-2.
|
344
|
-
osbot_utils-2.
|
345
|
-
osbot_utils-2.
|
346
|
-
osbot_utils-2.
|
343
|
+
osbot_utils/version,sha256=YGrSykHz7B3et_Lt-lk1a1Wwox5GwG1-AyQ7FOE7dfw,8
|
344
|
+
osbot_utils-2.13.0.dist-info/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
345
|
+
osbot_utils-2.13.0.dist-info/METADATA,sha256=vcJ_Y_Ij0NGdMApJS1oNxQnUq-fnaheoTLJoE-U-Nes,1329
|
346
|
+
osbot_utils-2.13.0.dist-info/WHEEL,sha256=IYZQI976HJqqOpQU6PHkJ8fb3tMNBFjg-Cn-pwAbaFM,88
|
347
|
+
osbot_utils-2.13.0.dist-info/RECORD,,
|
File without changes
|
File without changes
|