python-ulid 2.5.0__tar.gz → 2.6.0__tar.gz
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.5.0 → python_ulid-2.6.0}/CHANGELOG.rst +9 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/PKG-INFO +1 -1
- {python_ulid-2.5.0 → python_ulid-2.6.0}/tests/test_ulid.py +11 -9
- {python_ulid-2.5.0 → python_ulid-2.6.0}/ulid/__init__.py +14 -2
- {python_ulid-2.5.0 → python_ulid-2.6.0}/ulid/base32.py +2 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/.github/workflows/lint-and-test.yml +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/.github/workflows/publish.yml +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/.gitignore +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/.pre-commit-config.yaml +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/.readthedocs.yml +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/LICENSE +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/README.rst +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/docs/Makefile +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/docs/requirements.txt +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/docs/source/api.rst +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/docs/source/changelog.rst +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/docs/source/conf.py +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/docs/source/index.rst +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/hatch.toml +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/logo.png +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/pyproject.toml +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/tests/__init__.py +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/tests/test_base32.py +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/tests/test_cli.py +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/ulid/__main__.py +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/ulid/constants.py +0 -0
- {python_ulid-2.5.0 → python_ulid-2.6.0}/ulid/py.typed +0 -0
|
@@ -5,6 +5,14 @@ Changelog
|
|
|
5
5
|
|
|
6
6
|
Versions follow `Semantic Versioning <http://www.semver.org>`_
|
|
7
7
|
|
|
8
|
+
`2.6.0`_ - 2024-05-26
|
|
9
|
+
---------------------
|
|
10
|
+
Changed
|
|
11
|
+
~~~~~~~
|
|
12
|
+
* Provide more sophisticated validation when creating ``ULID``s from user input. When using
|
|
13
|
+
``ULID.from_str`` we will check if the characters match the base32 alphabet. In general, it is
|
|
14
|
+
ensured that the timestamp part of the ULID is not out of range.
|
|
15
|
+
|
|
8
16
|
`2.5.0`_ - 2024-04-26
|
|
9
17
|
---------------------
|
|
10
18
|
|
|
@@ -159,6 +167,7 @@ Changed
|
|
|
159
167
|
* The package now has no external dependencies.
|
|
160
168
|
* The test-coverage has been raised to 100%.
|
|
161
169
|
|
|
170
|
+
.. _2.6.0: https://github.com/mdomke/python-ulid/compare/2.5.0...2.6.0
|
|
162
171
|
.. _2.5.0: https://github.com/mdomke/python-ulid/compare/2.4.0...2.5.0
|
|
163
172
|
.. _2.4.0: https://github.com/mdomke/python-ulid/compare/2.3.0...2.4.0
|
|
164
173
|
.. _2.3.0: https://github.com/mdomke/python-ulid/compare/2.2.0...2.3.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
|
|
@@ -149,15 +149,17 @@ Params = Union[bytes, str, int, float]
|
|
|
149
149
|
@pytest.mark.parametrize(
|
|
150
150
|
("constructor", "value"),
|
|
151
151
|
[
|
|
152
|
-
(ULID, b"sdf"),
|
|
153
|
-
(ULID.from_timestamp, b"not-a-timestamp"),
|
|
154
|
-
(ULID.from_datetime, time.time()),
|
|
155
|
-
(ULID.from_bytes, b"not-enough"),
|
|
156
|
-
(ULID.from_bytes, 123),
|
|
157
|
-
(ULID.from_str, "not-enough"),
|
|
158
|
-
(ULID.from_str, 123),
|
|
159
|
-
(ULID.
|
|
160
|
-
(ULID.
|
|
152
|
+
(ULID, b"sdf"), # invalid length
|
|
153
|
+
(ULID.from_timestamp, b"not-a-timestamp"), # invalid type
|
|
154
|
+
(ULID.from_datetime, time.time()), # invalid type
|
|
155
|
+
(ULID.from_bytes, b"not-enough"), # invalid length
|
|
156
|
+
(ULID.from_bytes, 123), # invalid type
|
|
157
|
+
(ULID.from_str, "not-enough"), # invalid length
|
|
158
|
+
(ULID.from_str, 123), # inavlid type
|
|
159
|
+
(ULID.from_str, "notavalidulidnotavalidulid"), # invalid alphabet
|
|
160
|
+
(ULID.from_str, "Z" * 26), # invalid timestamp
|
|
161
|
+
(ULID.from_int, "not-an-int"), # invalid type
|
|
162
|
+
(ULID.from_uuid, "not-a-uuid"), # invalid type
|
|
161
163
|
],
|
|
162
164
|
)
|
|
163
165
|
def test_ulid_invalid_input(constructor: Callable[[Params], ULID], value: Params) -> None:
|
|
@@ -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)
|
|
@@ -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
|
)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|