python-ulid 4.0.1__tar.gz → 4.1.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-4.0.1 → python_ulid-4.1.0}/.github/workflows/lint-and-test.yml +4 -2
- {python_ulid-4.0.1 → python_ulid-4.1.0}/CHANGELOG.rst +21 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/CONTRIBUTING.md +1 -1
- {python_ulid-4.0.1 → python_ulid-4.1.0}/PKG-INFO +4 -5
- {python_ulid-4.0.1 → python_ulid-4.1.0}/README.rst +3 -3
- {python_ulid-4.0.1 → python_ulid-4.1.0}/docs/source/conf.py +2 -2
- {python_ulid-4.0.1 → python_ulid-4.1.0}/pyproject.toml +16 -15
- {python_ulid-4.0.1 → python_ulid-4.1.0}/tests/test_cli.py +50 -1
- {python_ulid-4.0.1 → python_ulid-4.1.0}/tests/test_ulid.py +10 -3
- {python_ulid-4.0.1 → python_ulid-4.1.0}/ulid/__init__.py +4 -13
- {python_ulid-4.0.1 → python_ulid-4.1.0}/ulid/__main__.py +8 -4
- {python_ulid-4.0.1 → python_ulid-4.1.0}/ulid/base32.py +3 -1
- python_ulid-4.1.0/uv.lock +1117 -0
- python_ulid-4.0.1/uv.lock +0 -1038
- {python_ulid-4.0.1 → python_ulid-4.1.0}/.envrc +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/.github/workflows/publish.yml +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/.gitignore +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/.pre-commit-config.yaml +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/.readthedocs.yml +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/.ruff_defaults.toml +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/AGENTS.md +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/CONTEXT.md +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/LICENSE +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/docs/Makefile +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/docs/requirements.txt +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/docs/source/api.rst +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/docs/source/changelog.rst +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/docs/source/index.rst +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/logo.png +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/tests/__init__.py +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/tests/test_base32.py +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/ulid/constants.py +0 -0
- {python_ulid-4.0.1 → python_ulid-4.1.0}/ulid/py.typed +0 -0
|
@@ -47,7 +47,7 @@ jobs:
|
|
|
47
47
|
name: Run tests
|
|
48
48
|
strategy:
|
|
49
49
|
matrix:
|
|
50
|
-
python-version: ["3.
|
|
50
|
+
python-version: ["3.11", "3.12", "3.13", "3.14"]
|
|
51
51
|
steps:
|
|
52
52
|
- uses: actions/checkout@v7
|
|
53
53
|
- name: Install uv
|
|
@@ -57,6 +57,8 @@ jobs:
|
|
|
57
57
|
|
|
58
58
|
- name: Test
|
|
59
59
|
run: uv run poe test
|
|
60
|
+
env:
|
|
61
|
+
COVERAGE_FILE: .coverage.${{ matrix.python-version }}
|
|
60
62
|
|
|
61
63
|
- name: Upload coverage data
|
|
62
64
|
uses: actions/upload-artifact@v7
|
|
@@ -98,4 +100,4 @@ jobs:
|
|
|
98
100
|
runs-on: ubuntu-latest
|
|
99
101
|
steps:
|
|
100
102
|
- uses: actions/checkout@v7
|
|
101
|
-
- uses: hynek/build-and-inspect-python-package@
|
|
103
|
+
- uses: hynek/build-and-inspect-python-package@67230f7b8410ae0052b39c1efc89d89fff43ff10 # v3.0.2
|
|
@@ -5,6 +5,25 @@ Changelog
|
|
|
5
5
|
|
|
6
6
|
Versions follow `Semantic Versioning <http://www.semver.org>`_
|
|
7
7
|
|
|
8
|
+
`Unreleased`_
|
|
9
|
+
-------------
|
|
10
|
+
|
|
11
|
+
`4.1.0`_ - 2026-10-27
|
|
12
|
+
---------------------
|
|
13
|
+
Changed
|
|
14
|
+
~~~~~~~
|
|
15
|
+
* Dropped support for Python 3.10.
|
|
16
|
+
|
|
17
|
+
Fixed
|
|
18
|
+
~~~~~
|
|
19
|
+
* The ``typing-extensions`` dependency is now also installed on Python 3.11, where it is required
|
|
20
|
+
for ``typing_extensions.override``.
|
|
21
|
+
* Print generated and converted values when using ``python -m ulid``, matching the
|
|
22
|
+
``ulid`` console command `@tongwentao <https://github.com/tongwentao>`_.
|
|
23
|
+
* :meth:`.ULID.from_str` accepts lower case strings again, as the ULID spec defines the string
|
|
24
|
+
representation as case insensitive. Lower case input has been rejected since 2.6.0
|
|
25
|
+
`@reyhaan07 <https://github.com/reyhaan07>`_.
|
|
26
|
+
|
|
8
27
|
`4.0.1`_ - 2026-07-20
|
|
9
28
|
---------------------
|
|
10
29
|
Changed
|
|
@@ -265,6 +284,8 @@ Changed
|
|
|
265
284
|
* The package now has no external dependencies.
|
|
266
285
|
* The test-coverage has been raised to 100%.
|
|
267
286
|
|
|
287
|
+
.. _Unreleased: https://github.com/mdomke/python-ulid/compare/4.1.0...HEAD
|
|
288
|
+
.. _4.1.0: https://github.com/mdomke/python-ulid/compare/4.0.1...4.1.0
|
|
268
289
|
.. _4.0.1: https://github.com/mdomke/python-ulid/compare/4.0.0...4.0.1
|
|
269
290
|
.. _4.0.0: https://github.com/mdomke/python-ulid/compare/3.2.1...4.0.0
|
|
270
291
|
.. _3.2.1: https://github.com/mdomke/python-ulid/compare/3.2.0...3.2.1
|
|
@@ -33,7 +33,7 @@ If you have [Flox](https://flox.dev/) installed, setting up your environment is
|
|
|
33
33
|
If Flox is not an option, you can set up your environment manually. We use [uv](https://github.com/astral-sh/uv) for fast, robust package and dependency management.
|
|
34
34
|
|
|
35
35
|
1. **Prerequisites**:
|
|
36
|
-
- **Python**: `>= 3.
|
|
36
|
+
- **Python**: `>= 3.11`
|
|
37
37
|
- **uv**: Install via `curl -LsSf https://astral.sh/uv/install.sh | sh` (or your preferred package manager)
|
|
38
38
|
|
|
39
39
|
2. **Fork and clone** the repository:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
2
|
Name: python-ulid
|
|
3
|
-
Version: 4.0
|
|
3
|
+
Version: 4.1.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
|
|
@@ -18,14 +18,13 @@ Classifier: License :: OSI Approved :: MIT License
|
|
|
18
18
|
Classifier: Operating System :: MacOS :: MacOS X
|
|
19
19
|
Classifier: Operating System :: POSIX :: Linux
|
|
20
20
|
Classifier: Programming Language :: Python
|
|
21
|
-
Classifier: Programming Language :: Python :: 3.10
|
|
22
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
23
22
|
Classifier: Programming Language :: Python :: 3.12
|
|
24
23
|
Classifier: Programming Language :: Python :: 3.13
|
|
25
24
|
Classifier: Programming Language :: Python :: 3.14
|
|
26
25
|
Classifier: Topic :: Software Development :: Libraries
|
|
27
|
-
Requires-Python: >=3.
|
|
28
|
-
Requires-Dist: typing-extensions; python_version < '3.
|
|
26
|
+
Requires-Python: >=3.11
|
|
27
|
+
Requires-Dist: typing-extensions; python_version < '3.12'
|
|
29
28
|
Provides-Extra: pydantic
|
|
30
29
|
Requires-Dist: pydantic>=2.0; extra == 'pydantic'
|
|
31
30
|
Description-Content-Type: text/x-rst
|
|
@@ -22,10 +22,10 @@
|
|
|
22
22
|
<img src="https://img.shields.io/github/actions/workflow/status/mdomke/python-ulid/lint-and-test.yml?style=flat-square&brach=main" />
|
|
23
23
|
</a>
|
|
24
24
|
<a href="https://python-ulid.readthedocs.io">
|
|
25
|
-
<img src="https://readthedocs.org/projects/python-ulid/badge/?version=latest&style=flat-square" />
|
|
25
|
+
<img src="https://app.readthedocs.org/projects/python-ulid/badge/?version=latest&style=flat-square" />
|
|
26
26
|
</a>
|
|
27
|
-
<a href="https://
|
|
28
|
-
<img src="https://img.shields.io/badge/
|
|
27
|
+
<a href="https://github.com/astral-sh/ruff">
|
|
28
|
+
<img src="https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json&style=flat-square" />
|
|
29
29
|
</a>
|
|
30
30
|
</p>
|
|
31
31
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import os
|
|
2
2
|
import sys
|
|
3
3
|
from datetime import datetime
|
|
4
|
-
from datetime import
|
|
4
|
+
from datetime import UTC
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
sys.path.insert(0, os.path.abspath("../.."))
|
|
@@ -9,7 +9,7 @@ sys.path.insert(0, os.path.abspath("../.."))
|
|
|
9
9
|
import ulid
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
copyright = f"{datetime.now(
|
|
12
|
+
copyright = f"{datetime.now(UTC).year}, Martin Domke"
|
|
13
13
|
author = "Martin Domke"
|
|
14
14
|
master_doc = "index"
|
|
15
15
|
source_suffix = {".rst": "restructuredtext", ".md": "restructuredtext"}
|
|
@@ -7,7 +7,7 @@ name = "python-ulid"
|
|
|
7
7
|
description = "Universally unique lexicographically sortable identifier"
|
|
8
8
|
dynamic = ["version", "readme"]
|
|
9
9
|
license = "MIT"
|
|
10
|
-
requires-python = ">=3.
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
11
|
authors = [
|
|
12
12
|
{ name = "Martin Domke", email = "mail@martindomke.net" },
|
|
13
13
|
]
|
|
@@ -19,7 +19,6 @@ classifiers = [
|
|
|
19
19
|
"Operating System :: POSIX :: Linux",
|
|
20
20
|
"Operating System :: MacOS :: MacOS X",
|
|
21
21
|
"Programming Language :: Python",
|
|
22
|
-
"Programming Language :: Python :: 3.10",
|
|
23
22
|
"Programming Language :: Python :: 3.11",
|
|
24
23
|
"Programming Language :: Python :: 3.12",
|
|
25
24
|
"Programming Language :: Python :: 3.13",
|
|
@@ -27,7 +26,7 @@ classifiers = [
|
|
|
27
26
|
"Topic :: Software Development :: Libraries",
|
|
28
27
|
]
|
|
29
28
|
dependencies = [
|
|
30
|
-
"typing-extensions; python_version < '3.
|
|
29
|
+
"typing-extensions; python_version < '3.12'",
|
|
31
30
|
]
|
|
32
31
|
|
|
33
32
|
[project.urls]
|
|
@@ -60,7 +59,7 @@ exclude = [
|
|
|
60
59
|
|
|
61
60
|
[tool.ruff]
|
|
62
61
|
extend = ".ruff_defaults.toml"
|
|
63
|
-
target-version = "
|
|
62
|
+
target-version = "py311"
|
|
64
63
|
line-length = 100
|
|
65
64
|
|
|
66
65
|
[tool.ruff.format]
|
|
@@ -112,12 +111,13 @@ preset = "strict"
|
|
|
112
111
|
project-excludes = ["docs"]
|
|
113
112
|
|
|
114
113
|
[tool.poe.tasks]
|
|
115
|
-
test = "uv run --extra pydantic
|
|
116
|
-
check-code = "ruff check"
|
|
117
|
-
check-fmt = "ruff format --check"
|
|
114
|
+
test = "uv run --extra pydantic pytest --cov --cov-report=term-missing"
|
|
115
|
+
check-code = "uv run ruff check"
|
|
116
|
+
check-fmt = "uv run ruff format --check"
|
|
118
117
|
check-types = "uv run --extra pydantic pyrefly check"
|
|
119
|
-
check-docs = "doc8 docs/source"
|
|
120
|
-
fmt = "ruff format"
|
|
118
|
+
check-docs = "uv run doc8 docs/source"
|
|
119
|
+
fmt = "uv run ruff format"
|
|
120
|
+
fix = "uv run ruff check --fix"
|
|
121
121
|
build = "uv build"
|
|
122
122
|
cov-combine = "coverage combine"
|
|
123
123
|
cov-xml = "coverage xml"
|
|
@@ -146,17 +146,18 @@ max-line-length = 100
|
|
|
146
146
|
|
|
147
147
|
[dependency-groups]
|
|
148
148
|
dev = [
|
|
149
|
-
"coverage==7.
|
|
149
|
+
"coverage==7.17.*",
|
|
150
150
|
"freezegun==1.5.*",
|
|
151
|
-
"poethepoet==0.
|
|
152
|
-
"prek==0.
|
|
153
|
-
"pyrefly==1.
|
|
151
|
+
"poethepoet==0.49.*",
|
|
152
|
+
"prek==0.5.*",
|
|
153
|
+
"pyrefly==1.4.*",
|
|
154
154
|
"pytest==9.1.*",
|
|
155
|
-
"
|
|
155
|
+
"pytest-cov==7.1.*",
|
|
156
|
+
"ruff==0.17.*",
|
|
156
157
|
]
|
|
157
158
|
doc = [
|
|
158
159
|
"doc8>=2.0.0",
|
|
159
|
-
"sphinx
|
|
160
|
+
"sphinx<9.0",
|
|
160
161
|
]
|
|
161
162
|
|
|
162
163
|
[tool.hatch.metadata.hooks.fancy-pypi-readme]
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import sys
|
|
3
|
+
|
|
1
4
|
import pytest
|
|
2
5
|
|
|
3
6
|
import ulid.__main__ as cli
|
|
@@ -30,7 +33,7 @@ def test_parse_show(option: str):
|
|
|
30
33
|
assert ulid.hex in output
|
|
31
34
|
assert str(int(ulid)) in output
|
|
32
35
|
assert str(ulid.timestamp) in output
|
|
33
|
-
assert
|
|
36
|
+
assert ulid.datetime.isoformat() in output
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
@pytest.mark.parametrize(
|
|
@@ -79,3 +82,49 @@ def test_build(option: str):
|
|
|
79
82
|
ulid_out = ULID.from_str(output)
|
|
80
83
|
if includes_timestamp:
|
|
81
84
|
assert ulid_out.datetime == ulid.datetime
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.mark.parametrize(
|
|
88
|
+
("args", "stdin", "expected"),
|
|
89
|
+
[
|
|
90
|
+
(["build", "--from-int", "0"], None, "00000000000000000000000000\n"),
|
|
91
|
+
(["build", "--from-int", "-"], "0\n", "00000000000000000000000000\n"),
|
|
92
|
+
(["show", "--int", "00000000000000000000000000"], None, "0\n"),
|
|
93
|
+
(["show", "--int", "-"], "00000000000000000000000000\n", "0\n"),
|
|
94
|
+
],
|
|
95
|
+
)
|
|
96
|
+
def test_module_outputs_result(args: list[str], stdin: str | None, expected: str) -> None:
|
|
97
|
+
result = subprocess.run(
|
|
98
|
+
[sys.executable, "-m", "ulid", *args],
|
|
99
|
+
input=stdin,
|
|
100
|
+
capture_output=True,
|
|
101
|
+
text=True,
|
|
102
|
+
check=True,
|
|
103
|
+
timeout=10,
|
|
104
|
+
)
|
|
105
|
+
assert result.stdout == expected
|
|
106
|
+
assert result.stderr == ""
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@pytest.mark.parametrize("args", [[], ["--help"]])
|
|
110
|
+
def test_module_help(args: list[str]) -> None:
|
|
111
|
+
result = subprocess.run(
|
|
112
|
+
[sys.executable, "-m", "ulid", *args],
|
|
113
|
+
capture_output=True,
|
|
114
|
+
text=True,
|
|
115
|
+
check=True,
|
|
116
|
+
timeout=10,
|
|
117
|
+
)
|
|
118
|
+
assert result.stdout.startswith("usage: python -m ulid")
|
|
119
|
+
assert not result.stdout.endswith("None\n")
|
|
120
|
+
assert result.stderr == ""
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_console_entrypoint(
|
|
124
|
+
monkeypatch: pytest.MonkeyPatch, capsys: pytest.CaptureFixture[str]
|
|
125
|
+
) -> None:
|
|
126
|
+
monkeypatch.setattr(sys, "argv", ["ulid", "build", "--from-int", "0"])
|
|
127
|
+
cli.entrypoint()
|
|
128
|
+
captured = capsys.readouterr()
|
|
129
|
+
assert captured.out == "00000000000000000000000000\n"
|
|
130
|
+
assert captured.err == ""
|
|
@@ -4,7 +4,7 @@ import uuid
|
|
|
4
4
|
from collections.abc import Callable
|
|
5
5
|
from datetime import datetime
|
|
6
6
|
from datetime import timedelta
|
|
7
|
-
from datetime import
|
|
7
|
+
from datetime import UTC
|
|
8
8
|
from typing import Any
|
|
9
9
|
|
|
10
10
|
import pytest
|
|
@@ -23,7 +23,7 @@ from ulid import ULIDGenerator
|
|
|
23
23
|
|
|
24
24
|
|
|
25
25
|
def utcnow() -> datetime:
|
|
26
|
-
return datetime.now(
|
|
26
|
+
return datetime.now(UTC)
|
|
27
27
|
|
|
28
28
|
|
|
29
29
|
def datetimes_almost_equal(a: datetime, b: datetime) -> None:
|
|
@@ -177,6 +177,12 @@ def test_idempotency() -> None:
|
|
|
177
177
|
assert ULID.parse(ulid.bytes) == ulid
|
|
178
178
|
|
|
179
179
|
|
|
180
|
+
def test_from_str_is_case_insensitive() -> None:
|
|
181
|
+
ulid = ULID()
|
|
182
|
+
assert ULID.from_str(str(ulid).lower()) == ulid
|
|
183
|
+
assert ULID.parse(str(ulid).lower()) == ulid
|
|
184
|
+
|
|
185
|
+
|
|
180
186
|
def test_to_uuid4() -> None:
|
|
181
187
|
ulid = ULID()
|
|
182
188
|
uuid = ulid.to_uuid4()
|
|
@@ -350,6 +356,7 @@ Params = bytes | str | int | float
|
|
|
350
356
|
(ULID.from_str, "not-enough"), # invalid length
|
|
351
357
|
(ULID.from_str, 123), # inavlid type
|
|
352
358
|
(ULID.from_str, "notavalidulidnotavalidulid"), # invalid alphabet
|
|
359
|
+
(ULID.from_str, "0" * 25 + "u"), # excluded letter in lower case
|
|
353
360
|
(ULID.from_str, "Z" * 26), # invalid timestamp
|
|
354
361
|
(ULID.from_int, "not-an-int"), # invalid type
|
|
355
362
|
(ULID.from_uuid, "not-a-uuid"), # invalid type
|
|
@@ -382,7 +389,7 @@ def test_ulid_min_input(constructor: Callable[[Params], ULID], value: Params) ->
|
|
|
382
389
|
[
|
|
383
390
|
(ULID, b"\xff" * 16),
|
|
384
391
|
(ULID.from_timestamp, 281474976710655),
|
|
385
|
-
(ULID.from_datetime, datetime.max.replace(tzinfo=
|
|
392
|
+
(ULID.from_datetime, datetime.max.replace(tzinfo=UTC)),
|
|
386
393
|
(ULID.from_bytes, b"\xff" * 16),
|
|
387
394
|
(ULID.from_str, "7" + "Z" * 25),
|
|
388
395
|
(ULID.from_hex, "f" * 32),
|
|
@@ -7,7 +7,8 @@ import time
|
|
|
7
7
|
import uuid
|
|
8
8
|
from collections.abc import Callable
|
|
9
9
|
from datetime import datetime
|
|
10
|
-
from datetime import
|
|
10
|
+
from datetime import UTC
|
|
11
|
+
from importlib.metadata import version
|
|
11
12
|
from threading import Lock
|
|
12
13
|
from typing import Any
|
|
13
14
|
from typing import cast
|
|
@@ -25,22 +26,12 @@ from ulid import constants
|
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
if TYPE_CHECKING: # pragma: no cover
|
|
28
|
-
import
|
|
29
|
+
from typing import Self
|
|
29
30
|
|
|
30
31
|
from pydantic import GetCoreSchemaHandler
|
|
31
32
|
from pydantic import ValidatorFunctionWrapHandler
|
|
32
33
|
from pydantic_core import CoreSchema
|
|
33
34
|
|
|
34
|
-
if sys.version_info >= (3, 11):
|
|
35
|
-
from typing import Self
|
|
36
|
-
else:
|
|
37
|
-
from typing_extensions import Self
|
|
38
|
-
|
|
39
|
-
try:
|
|
40
|
-
from importlib.metadata import version
|
|
41
|
-
except ImportError: # pragma: no cover
|
|
42
|
-
from importlib_metadata import version # type: ignore
|
|
43
|
-
|
|
44
35
|
|
|
45
36
|
__version__ = version("python-ulid")
|
|
46
37
|
|
|
@@ -413,7 +404,7 @@ class ULID:
|
|
|
413
404
|
>>> ulid.datetime
|
|
414
405
|
datetime.datetime(2020, 4, 30, 14, 33, 27, 560000, tzinfo=datetime.timezone.utc)
|
|
415
406
|
"""
|
|
416
|
-
return datetime.fromtimestamp(self.timestamp,
|
|
407
|
+
return datetime.fromtimestamp(self.timestamp, UTC)
|
|
417
408
|
|
|
418
409
|
@functools.cached_property
|
|
419
410
|
def hex(self) -> str:
|
|
@@ -45,7 +45,11 @@ def make_parser(prog: str | None = None) -> argparse.ArgumentParser:
|
|
|
45
45
|
width=min(shutil.get_terminal_size().columns - 2, 127),
|
|
46
46
|
),
|
|
47
47
|
)
|
|
48
|
-
|
|
48
|
+
|
|
49
|
+
def help(*_args: Any) -> None:
|
|
50
|
+
parser.print_help()
|
|
51
|
+
|
|
52
|
+
parser.set_defaults(func=help)
|
|
49
53
|
parser.add_argument("--version", "-V", action="version", version=ulid.__version__)
|
|
50
54
|
|
|
51
55
|
subparsers = parser.add_subparsers(title="subcommands")
|
|
@@ -163,10 +167,10 @@ def show(args: argparse.Namespace) -> str:
|
|
|
163
167
|
).strip()
|
|
164
168
|
|
|
165
169
|
|
|
166
|
-
def entrypoint() -> None: # pragma: no cover
|
|
167
|
-
if (value := main(sys.argv[1:])) is not None:
|
|
170
|
+
def entrypoint(prog: str | None = None) -> None: # pragma: no cover
|
|
171
|
+
if (value := main(sys.argv[1:], prog)) is not None:
|
|
168
172
|
print(value) # noqa: T201
|
|
169
173
|
|
|
170
174
|
|
|
171
175
|
if __name__ == "__main__": # pragma: no cover
|
|
172
|
-
|
|
176
|
+
entrypoint("python -m ulid")
|
|
@@ -7,6 +7,8 @@ from ulid import constants
|
|
|
7
7
|
# https://github.com/RobThree/NUlid/blob/89f5a9fc827d191ae5adafe42547575ed3a47723/NUlid/Ulid.cs#L168
|
|
8
8
|
|
|
9
9
|
ENCODE: str = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"
|
|
10
|
+
# The ULID spec defines the string representation as case insensitive.
|
|
11
|
+
DECODE_ALPHABET: str = ENCODE + ENCODE.lower()
|
|
10
12
|
DECODE: Sequence[int] = [
|
|
11
13
|
0xFF,
|
|
12
14
|
0xFF,
|
|
@@ -194,7 +196,7 @@ def encode_randomness(binary: bytes) -> str:
|
|
|
194
196
|
def decode(encoded: str) -> bytes:
|
|
195
197
|
if len(encoded) != constants.REPR_LEN:
|
|
196
198
|
raise ValueError("Encoded ULID has to be exactly 26 characters long.")
|
|
197
|
-
if any((c not in
|
|
199
|
+
if any((c not in DECODE_ALPHABET) for c in encoded):
|
|
198
200
|
raise ValueError(f"Encoded ULID can only consist of letters in {ENCODE}.")
|
|
199
201
|
return decode_timestamp(encoded[: constants.TIMESTAMP_REPR_LEN]) + decode_randomness(
|
|
200
202
|
encoded[constants.TIMESTAMP_REPR_LEN :]
|