typeid-python 0.2.2__py3-none-any.whl → 0.3.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.

Potentially problematic release.


This version of typeid-python might be problematic. Click here for more details.

typeid/typeid.py CHANGED
@@ -1,7 +1,7 @@
1
+ import warnings
1
2
  from typing import Optional
2
- from uuid import UUID
3
3
 
4
- from uuid6 import uuid7
4
+ import uuid6
5
5
 
6
6
  from typeid import base32
7
7
  from typeid.errors import InvalidTypeIDStringException
@@ -10,7 +10,7 @@ from typeid.validation import validate_prefix, validate_suffix
10
10
 
11
11
  class TypeID:
12
12
  def __init__(self, prefix: Optional[str] = None, suffix: Optional[str] = None) -> None:
13
- suffix = _convert_uuid_to_b32(uuid7()) if not suffix else suffix
13
+ suffix = _convert_uuid_to_b32(uuid6.uuid7()) if not suffix else suffix
14
14
  validate_suffix(suffix=suffix)
15
15
  if prefix:
16
16
  validate_prefix(prefix=prefix)
@@ -24,9 +24,9 @@ class TypeID:
24
24
  return cls(suffix=suffix, prefix=prefix)
25
25
 
26
26
  @classmethod
27
- def from_uuid(cls, suffix: UUID, prefix: Optional[str] = None):
27
+ def from_uuid(cls, suffix: uuid6.UUID, prefix: Optional[str] = None):
28
28
  suffix_str = _convert_uuid_to_b32(suffix)
29
- return TypeID(suffix=suffix_str, prefix=prefix)
29
+ return cls(suffix=suffix_str, prefix=prefix)
30
30
 
31
31
  @property
32
32
  def suffix(self) -> str:
@@ -37,7 +37,7 @@ class TypeID:
37
37
  return self._prefix
38
38
 
39
39
  @property
40
- def uuid(self) -> UUID:
40
+ def uuid(self) -> uuid6.UUID:
41
41
  return _convert_b32_to_uuid(self.suffix)
42
42
 
43
43
  def __str__(self) -> str:
@@ -47,28 +47,40 @@ class TypeID:
47
47
  value += self.suffix
48
48
  return value
49
49
 
50
+ def __repr__(self):
51
+ return "%s(%r)" % (self.__class__.__name__, str(self))
52
+
50
53
  def __eq__(self, value: object) -> bool:
51
54
  if not isinstance(value, TypeID):
52
55
  return False
53
56
  return value.prefix == self.prefix and value.suffix == self.suffix
54
57
 
58
+ def __gt__(self, other):
59
+ if isinstance(other, TypeID):
60
+ return str(self) > str(other)
61
+ return NotImplemented
62
+
63
+ def __ge__(self, other):
64
+ if isinstance(other, TypeID):
65
+ return str(self) >= str(other)
66
+ return NotImplemented
67
+
55
68
  def __hash__(self) -> int:
56
69
  return hash((self.prefix, self.suffix))
57
70
 
58
71
 
59
72
  def from_string(string: str) -> TypeID:
60
- """Consider TypeID.from_string instead."""
73
+ warnings.warn("Consider TypeID.from_string instead.", DeprecationWarning)
61
74
  return TypeID.from_string(string=string)
62
75
 
63
76
 
64
- def from_uuid(suffix: UUID, prefix: Optional[str] = None) -> TypeID:
65
- """Consider TypeID.from_uuid instead."""
77
+ def from_uuid(suffix: uuid6.UUID, prefix: Optional[str] = None) -> TypeID:
78
+ warnings.warn("Consider TypeID.from_uuid instead.", DeprecationWarning)
66
79
  return TypeID.from_uuid(suffix=suffix, prefix=prefix)
67
80
 
68
81
 
69
82
  def get_prefix_and_suffix(string: str) -> tuple:
70
83
  parts = string.split("_")
71
- suffix = None
72
84
  prefix = None
73
85
  if len(parts) == 1:
74
86
  suffix = parts[0]
@@ -81,9 +93,11 @@ def get_prefix_and_suffix(string: str) -> tuple:
81
93
  return prefix, suffix
82
94
 
83
95
 
84
- def _convert_uuid_to_b32(uuid_instance: UUID) -> str:
96
+ def _convert_uuid_to_b32(uuid_instance: uuid6.UUID) -> str:
85
97
  return base32.encode(list(uuid_instance.bytes))
86
98
 
87
99
 
88
- def _convert_b32_to_uuid(b32: str) -> UUID:
89
- return UUID(bytes=bytes(base32.decode(b32)))
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)
typeid/validation.py CHANGED
@@ -1,10 +1,13 @@
1
+ import re
2
+
1
3
  from typeid import base32
2
- from typeid.constants import PREFIX_MAX_LEN, SUFFIX_LEN
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
- if not prefix.islower() or not prefix.isascii() or len(prefix) > PREFIX_MAX_LEN or not prefix.isalpha():
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
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: typeid-python
3
- Version: 0.2.2
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
@@ -16,6 +16,7 @@ Classifier: Programming Language :: Python :: 3.8
16
16
  Classifier: Programming Language :: Python :: 3.9
17
17
  Classifier: Programming Language :: Python :: 3.10
18
18
  Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
19
20
  Provides-Extra: cli
20
21
  Requires-Dist: uuid6 (>=2023.5.2,<2024.0.0)
21
22
  Project-URL: Repository, https://github.com/akhundMurad/typeid-python
@@ -0,0 +1,11 @@
1
+ typeid/__init__.py,sha256=bS8J12-a6sOcTIHBumVs9qLRxCX5P-KWVLeMw6m1e_U,149
2
+ typeid/base32.py,sha256=UTYXJjb95_nn-vYIpw7nquguBac4GZ0TL0oE6BuujPg,6504
3
+ typeid/cli.py,sha256=h93_EAOzWO3bqubgL83Q-smHp11lvxMjgAunwyTWwFM,872
4
+ typeid/constants.py,sha256=2ApV0agNys2yI9NM8oQZbyTR2rgP-VtxXGrM6glBB2Q,37
5
+ typeid/errors.py,sha256=QPHZ-DJg5OpPOHtuetsqMCYu-E_aHMJZTTeFqx9Gz_4,207
6
+ typeid/typeid.py,sha256=clwA9ADePwO9bXclAk1G6_-ASGchRLaFbOvaBIyeyMU,3009
7
+ typeid/validation.py,sha256=Cb9IkHrK1-HFukFYpSzyNGhllaF3MIZDcD5RnmsfrK8,910
8
+ typeid_python-0.3.0.dist-info/LICENSE,sha256=f98oZ9FId4i3835UJYGw066BU8PSc57L1utGWS1ypcs,1070
9
+ typeid_python-0.3.0.dist-info/METADATA,sha256=7kPAUATsQLMCKm5A1-fH49MrNh6qRyIuj8Frpl8_HTo,4124
10
+ typeid_python-0.3.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
11
+ typeid_python-0.3.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: poetry-core 1.7.0
2
+ Generator: poetry-core 1.9.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -1,11 +0,0 @@
1
- typeid/__init__.py,sha256=bS8J12-a6sOcTIHBumVs9qLRxCX5P-KWVLeMw6m1e_U,149
2
- typeid/base32.py,sha256=UTYXJjb95_nn-vYIpw7nquguBac4GZ0TL0oE6BuujPg,6504
3
- typeid/cli.py,sha256=h93_EAOzWO3bqubgL83Q-smHp11lvxMjgAunwyTWwFM,872
4
- typeid/constants.py,sha256=2ApV0agNys2yI9NM8oQZbyTR2rgP-VtxXGrM6glBB2Q,37
5
- typeid/errors.py,sha256=QPHZ-DJg5OpPOHtuetsqMCYu-E_aHMJZTTeFqx9Gz_4,207
6
- typeid/typeid.py,sha256=_hu8bHjFVcwe2QklrFmYZOj2ycltuL8p_XjAq2ncviY,2480
7
- typeid/validation.py,sha256=yvLO5lfMkJpduZzql_FJlj4hW6HcWURWYLRQvR92SSM,899
8
- typeid_python-0.2.2.dist-info/LICENSE,sha256=f98oZ9FId4i3835UJYGw066BU8PSc57L1utGWS1ypcs,1070
9
- typeid_python-0.2.2.dist-info/METADATA,sha256=RDsPvAGyBmrLMR0cCxu0-6ZvuOjKSJ_ndX227zSftcY,4073
10
- typeid_python-0.2.2.dist-info/WHEEL,sha256=d2fvjOD7sXsVzChCqf0Ty0JbHKBaLYwDbGQDwQTnJ50,88
11
- typeid_python-0.2.2.dist-info/RECORD,,