typeid-python 0.2.3__tar.gz → 0.3.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.
Potentially problematic release.
This version of typeid-python might be problematic. Click here for more details.
- {typeid_python-0.2.3 → typeid_python-0.3.0}/PKG-INFO +1 -1
- {typeid_python-0.2.3 → typeid_python-0.3.0}/pyproject.toml +1 -1
- {typeid_python-0.2.3 → typeid_python-0.3.0}/typeid/typeid.py +11 -11
- {typeid_python-0.2.3 → typeid_python-0.3.0}/typeid/validation.py +5 -2
- {typeid_python-0.2.3 → typeid_python-0.3.0}/LICENSE +0 -0
- {typeid_python-0.2.3 → typeid_python-0.3.0}/README.md +0 -0
- {typeid_python-0.2.3 → typeid_python-0.3.0}/typeid/__init__.py +0 -0
- {typeid_python-0.2.3 → typeid_python-0.3.0}/typeid/base32.py +0 -0
- {typeid_python-0.2.3 → typeid_python-0.3.0}/typeid/cli.py +0 -0
- {typeid_python-0.2.3 → typeid_python-0.3.0}/typeid/constants.py +0 -0
- {typeid_python-0.2.3 → typeid_python-0.3.0}/typeid/errors.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: typeid-python
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.3.0
|
|
4
4
|
Summary: Python implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs
|
|
5
5
|
Home-page: https://github.com/akhundMurad/typeid-python
|
|
6
6
|
License: MIT
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "typeid-python"
|
|
3
|
-
version = "0.
|
|
3
|
+
version = "0.3.0"
|
|
4
4
|
description = "Python implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs"
|
|
5
5
|
authors = ["Murad Akhundov <akhundov1murad@gmail.com>"]
|
|
6
6
|
license = "MIT"
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import warnings
|
|
2
2
|
from typing import Optional
|
|
3
|
-
from uuid import UUID
|
|
4
3
|
|
|
5
|
-
|
|
4
|
+
import uuid6
|
|
6
5
|
|
|
7
6
|
from typeid import base32
|
|
8
7
|
from typeid.errors import InvalidTypeIDStringException
|
|
@@ -11,7 +10,7 @@ from typeid.validation import validate_prefix, validate_suffix
|
|
|
11
10
|
|
|
12
11
|
class TypeID:
|
|
13
12
|
def __init__(self, prefix: Optional[str] = None, suffix: Optional[str] = None) -> None:
|
|
14
|
-
suffix = _convert_uuid_to_b32(uuid7()) if not suffix else suffix
|
|
13
|
+
suffix = _convert_uuid_to_b32(uuid6.uuid7()) if not suffix else suffix
|
|
15
14
|
validate_suffix(suffix=suffix)
|
|
16
15
|
if prefix:
|
|
17
16
|
validate_prefix(prefix=prefix)
|
|
@@ -25,9 +24,9 @@ class TypeID:
|
|
|
25
24
|
return cls(suffix=suffix, prefix=prefix)
|
|
26
25
|
|
|
27
26
|
@classmethod
|
|
28
|
-
def from_uuid(cls, suffix: UUID, prefix: Optional[str] = None):
|
|
27
|
+
def from_uuid(cls, suffix: uuid6.UUID, prefix: Optional[str] = None):
|
|
29
28
|
suffix_str = _convert_uuid_to_b32(suffix)
|
|
30
|
-
return
|
|
29
|
+
return cls(suffix=suffix_str, prefix=prefix)
|
|
31
30
|
|
|
32
31
|
@property
|
|
33
32
|
def suffix(self) -> str:
|
|
@@ -38,7 +37,7 @@ class TypeID:
|
|
|
38
37
|
return self._prefix
|
|
39
38
|
|
|
40
39
|
@property
|
|
41
|
-
def uuid(self) -> UUID:
|
|
40
|
+
def uuid(self) -> uuid6.UUID:
|
|
42
41
|
return _convert_b32_to_uuid(self.suffix)
|
|
43
42
|
|
|
44
43
|
def __str__(self) -> str:
|
|
@@ -75,14 +74,13 @@ def from_string(string: str) -> TypeID:
|
|
|
75
74
|
return TypeID.from_string(string=string)
|
|
76
75
|
|
|
77
76
|
|
|
78
|
-
def from_uuid(suffix: UUID, prefix: Optional[str] = None) -> TypeID:
|
|
77
|
+
def from_uuid(suffix: uuid6.UUID, prefix: Optional[str] = None) -> TypeID:
|
|
79
78
|
warnings.warn("Consider TypeID.from_uuid instead.", DeprecationWarning)
|
|
80
79
|
return TypeID.from_uuid(suffix=suffix, prefix=prefix)
|
|
81
80
|
|
|
82
81
|
|
|
83
82
|
def get_prefix_and_suffix(string: str) -> tuple:
|
|
84
83
|
parts = string.split("_")
|
|
85
|
-
suffix = None
|
|
86
84
|
prefix = None
|
|
87
85
|
if len(parts) == 1:
|
|
88
86
|
suffix = parts[0]
|
|
@@ -95,9 +93,11 @@ def get_prefix_and_suffix(string: str) -> tuple:
|
|
|
95
93
|
return prefix, suffix
|
|
96
94
|
|
|
97
95
|
|
|
98
|
-
def _convert_uuid_to_b32(uuid_instance: UUID) -> str:
|
|
96
|
+
def _convert_uuid_to_b32(uuid_instance: uuid6.UUID) -> str:
|
|
99
97
|
return base32.encode(list(uuid_instance.bytes))
|
|
100
98
|
|
|
101
99
|
|
|
102
|
-
def _convert_b32_to_uuid(b32: str) -> UUID:
|
|
103
|
-
|
|
100
|
+
def _convert_b32_to_uuid(b32: str) -> uuid6.UUID:
|
|
101
|
+
uuid_bytes = bytes(base32.decode(b32))
|
|
102
|
+
uuid_int = int.from_bytes(uuid_bytes, byteorder="big")
|
|
103
|
+
return uuid6.UUID(int=uuid_int, version=7)
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import re
|
|
2
|
+
|
|
1
3
|
from typeid import base32
|
|
2
|
-
from typeid.constants import
|
|
4
|
+
from typeid.constants import SUFFIX_LEN
|
|
3
5
|
from typeid.errors import PrefixValidationException, SuffixValidationException
|
|
4
6
|
|
|
5
7
|
|
|
6
8
|
def validate_prefix(prefix: str) -> None:
|
|
7
|
-
|
|
9
|
+
# See https://github.com/jetify-com/typeid/tree/main/spec
|
|
10
|
+
if not re.match("^([a-z]([a-z_]{0,61}[a-z])?)?$", prefix):
|
|
8
11
|
raise PrefixValidationException(f"Invalid prefix: {prefix}.")
|
|
9
12
|
|
|
10
13
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|