python-ulid 2.4.0.post0__py3-none-any.whl → 2.6.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.
- {python_ulid-2.4.0.post0.dist-info → python_ulid-2.6.0.dist-info}/METADATA +1 -1
- python_ulid-2.6.0.dist-info/RECORD +10 -0
- {python_ulid-2.4.0.post0.dist-info → python_ulid-2.6.0.dist-info}/WHEEL +1 -1
- ulid/__init__.py +16 -2
- ulid/base32.py +2 -0
- python_ulid-2.4.0.post0.dist-info/RECORD +0 -10
- {python_ulid-2.4.0.post0.dist-info → python_ulid-2.6.0.dist-info}/entry_points.txt +0 -0
- {python_ulid-2.4.0.post0.dist-info → python_ulid-2.6.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: python-ulid
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.6.0
|
|
4
4
|
Summary: Universally unique lexicographically sortable identifier
|
|
5
5
|
Project-URL: Homepage, https://github.com/mdomke/python-ulid
|
|
6
6
|
Project-URL: Documentation, https://python-ulid.readthedocs.io
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
ulid/__init__.py,sha256=BziBUk2I6PxKvymNA0ddyUcfF9b_Zv7PKsTPV_ojixI,9929
|
|
2
|
+
ulid/__main__.py,sha256=Cmg0NEz3GUZ2WhsZVpY3-Kq-JOkxJFaLsRNgj3Aosyw,5341
|
|
3
|
+
ulid/base32.py,sha256=aj8pfBmuvviEJtdcGGiGImdSN_UMdVsBvIXlFkiqD1o,5963
|
|
4
|
+
ulid/constants.py,sha256=N_nw4W2ciXO8C1IeuO3YK3j4_x9QW-0KyvrSQUuM-G4,241
|
|
5
|
+
ulid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
+
python_ulid-2.6.0.dist-info/METADATA,sha256=NxDvmvrp4DzyfibtLfBPh3D605fWHRY_p709_rxwwG0,5782
|
|
7
|
+
python_ulid-2.6.0.dist-info/WHEEL,sha256=zEMcRr9Kr03x1ozGwg5v9NQBKn3kndp6LSoSlVg-jhU,87
|
|
8
|
+
python_ulid-2.6.0.dist-info/entry_points.txt,sha256=9214ghzfSgS8a-TjjlWDF7bI7KSaeewOCBKn5uz7bdU,50
|
|
9
|
+
python_ulid-2.6.0.dist-info/licenses/LICENSE,sha256=DiDPNhW5yUHIqaKowvX0c1c9xWiI0xW4ji8R9N2NJbw,1056
|
|
10
|
+
python_ulid-2.6.0.dist-info/RECORD,,
|
ulid/__init__.py
CHANGED
|
@@ -71,14 +71,26 @@ class ULID:
|
|
|
71
71
|
>>> ulid = ULID()
|
|
72
72
|
>>> str(ulid)
|
|
73
73
|
'01E75PVKXA3GFABX1M1J9NZZNF'
|
|
74
|
+
|
|
75
|
+
Args:
|
|
76
|
+
value (bytes, None): A sequence of 16 bytes representing an encoded ULID.
|
|
77
|
+
validate (bool): If set to `True` validate if the timestamp part is valid.
|
|
78
|
+
|
|
79
|
+
Raises:
|
|
80
|
+
ValueError: If the provided value is not a valid encoded ULID.
|
|
74
81
|
"""
|
|
75
82
|
|
|
76
|
-
def __init__(self, value: bytes | None = None) -> None:
|
|
83
|
+
def __init__(self, value: bytes | None = None, validate: bool = True) -> None:
|
|
77
84
|
if value is not None and len(value) != constants.BYTES_LEN:
|
|
78
85
|
raise ValueError("ULID has to be exactly 16 bytes long.")
|
|
79
86
|
self.bytes: bytes = (
|
|
80
87
|
value or ULID.from_timestamp(time.time_ns() // constants.NANOSECS_IN_MILLISECS).bytes
|
|
81
88
|
)
|
|
89
|
+
if value is not None and validate:
|
|
90
|
+
try:
|
|
91
|
+
self.datetime # noqa: B018
|
|
92
|
+
except ValueError as err:
|
|
93
|
+
raise ValueError("ULID timestamp is out of range.") from err
|
|
82
94
|
|
|
83
95
|
@classmethod
|
|
84
96
|
@validate_type(datetime)
|
|
@@ -125,7 +137,7 @@ class ULID:
|
|
|
125
137
|
>>> ULID.from_uuid(uuid4())
|
|
126
138
|
ULID(27Q506DP7E9YNRXA0XVD8Z5YSG)
|
|
127
139
|
"""
|
|
128
|
-
return cls(value.bytes)
|
|
140
|
+
return cls(value.bytes, validate=False)
|
|
129
141
|
|
|
130
142
|
@classmethod
|
|
131
143
|
@validate_type(bytes)
|
|
@@ -259,6 +271,8 @@ class ULID:
|
|
|
259
271
|
[
|
|
260
272
|
core_schema.is_instance_schema(ULID),
|
|
261
273
|
core_schema.no_info_plain_validator_function(ULID),
|
|
274
|
+
core_schema.str_schema(pattern=r"[A-Z0-9]{26}", min_length=26, max_length=26),
|
|
275
|
+
core_schema.bytes_schema(min_length=16, max_length=16),
|
|
262
276
|
]
|
|
263
277
|
),
|
|
264
278
|
serialization=core_schema.to_string_ser_schema(
|
ulid/base32.py
CHANGED
|
@@ -198,6 +198,8 @@ def encode_randomness(binary: bytes) -> str:
|
|
|
198
198
|
def decode(encoded: str) -> bytes:
|
|
199
199
|
if len(encoded) != constants.REPR_LEN:
|
|
200
200
|
raise ValueError("Encoded ULID has to be exactly 26 characters long.")
|
|
201
|
+
if any((c not in ENCODE) for c in encoded):
|
|
202
|
+
raise ValueError(f"Encoded ULID can only consist of letters in {ENCODE}.")
|
|
201
203
|
return decode_timestamp(encoded[: constants.TIMESTAMP_REPR_LEN]) + decode_randomness(
|
|
202
204
|
encoded[constants.TIMESTAMP_REPR_LEN :]
|
|
203
205
|
)
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
ulid/__init__.py,sha256=7wY5wUQGwcUhreFESFX6MCrimPbaJOjXUY0XEZvU9Cg,9235
|
|
2
|
-
ulid/__main__.py,sha256=Cmg0NEz3GUZ2WhsZVpY3-Kq-JOkxJFaLsRNgj3Aosyw,5341
|
|
3
|
-
ulid/base32.py,sha256=OkU4FBqohJgV_ZRc3dTbjPlUTSSeC9ddFlPXD2vA8vc,5832
|
|
4
|
-
ulid/constants.py,sha256=N_nw4W2ciXO8C1IeuO3YK3j4_x9QW-0KyvrSQUuM-G4,241
|
|
5
|
-
ulid/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
6
|
-
python_ulid-2.4.0.post0.dist-info/METADATA,sha256=iJQ_CnQw7XF_zgFGDJH4ZZ-4LVO2tAsuy3CPQWLd2Qg,5788
|
|
7
|
-
python_ulid-2.4.0.post0.dist-info/WHEEL,sha256=uNdcs2TADwSd5pVaP0Z_kcjcvvTUklh2S7bxZMF8Uj0,87
|
|
8
|
-
python_ulid-2.4.0.post0.dist-info/entry_points.txt,sha256=9214ghzfSgS8a-TjjlWDF7bI7KSaeewOCBKn5uz7bdU,50
|
|
9
|
-
python_ulid-2.4.0.post0.dist-info/licenses/LICENSE,sha256=DiDPNhW5yUHIqaKowvX0c1c9xWiI0xW4ji8R9N2NJbw,1056
|
|
10
|
-
python_ulid-2.4.0.post0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|