typeid-python
Advanced tools
+1
-1
| Metadata-Version: 2.1 | ||
| Name: typeid-python | ||
| Version: 0.2.3 | ||
| Version: 0.3.0 | ||
| Summary: Python implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs | ||
@@ -5,0 +5,0 @@ Home-page: https://github.com/akhundMurad/typeid-python |
+1
-1
| [tool.poetry] | ||
| name = "typeid-python" | ||
| version = "0.2.3" | ||
| version = "0.3.0" | ||
| description = "Python implementation of TypeIDs: type-safe, K-sortable, and globally unique identifiers inspired by Stripe IDs" | ||
@@ -5,0 +5,0 @@ authors = ["Murad Akhundov <akhundov1murad@gmail.com>"] |
+11
-11
| import warnings | ||
| from typing import Optional | ||
| from uuid import UUID | ||
| from uuid6 import uuid7 | ||
| import uuid6 | ||
@@ -14,3 +13,3 @@ from typeid import base32 | ||
| def __init__(self, prefix: Optional[str] = None, suffix: Optional[str] = None) -> None: | ||
| suffix = _convert_uuid_to_b32(uuid7()) if not suffix else suffix | ||
| suffix = _convert_uuid_to_b32(uuid6.uuid7()) if not suffix else suffix | ||
| validate_suffix(suffix=suffix) | ||
@@ -29,5 +28,5 @@ if prefix: | ||
| @classmethod | ||
| def from_uuid(cls, suffix: UUID, prefix: Optional[str] = None): | ||
| def from_uuid(cls, suffix: uuid6.UUID, prefix: Optional[str] = None): | ||
| suffix_str = _convert_uuid_to_b32(suffix) | ||
| return TypeID(suffix=suffix_str, prefix=prefix) | ||
| return cls(suffix=suffix_str, prefix=prefix) | ||
@@ -43,3 +42,3 @@ @property | ||
| @property | ||
| def uuid(self) -> UUID: | ||
| def uuid(self) -> uuid6.UUID: | ||
| return _convert_b32_to_uuid(self.suffix) | ||
@@ -81,3 +80,3 @@ | ||
| def from_uuid(suffix: UUID, prefix: Optional[str] = None) -> TypeID: | ||
| def from_uuid(suffix: uuid6.UUID, prefix: Optional[str] = None) -> TypeID: | ||
| warnings.warn("Consider TypeID.from_uuid instead.", DeprecationWarning) | ||
@@ -89,3 +88,2 @@ return TypeID.from_uuid(suffix=suffix, prefix=prefix) | ||
| parts = string.split("_") | ||
| suffix = None | ||
| prefix = None | ||
@@ -103,7 +101,9 @@ if len(parts) == 1: | ||
| def _convert_uuid_to_b32(uuid_instance: UUID) -> str: | ||
| def _convert_uuid_to_b32(uuid_instance: uuid6.UUID) -> str: | ||
| return base32.encode(list(uuid_instance.bytes)) | ||
| def _convert_b32_to_uuid(b32: str) -> UUID: | ||
| return UUID(bytes=bytes(base32.decode(b32))) | ||
| def _convert_b32_to_uuid(b32: str) -> uuid6.UUID: | ||
| uuid_bytes = bytes(base32.decode(b32)) | ||
| uuid_int = int.from_bytes(uuid_bytes, byteorder="big") | ||
| return uuid6.UUID(int=uuid_int, version=7) |
@@ -0,3 +1,5 @@ | ||
| import re | ||
| from typeid import base32 | ||
| from typeid.constants import PREFIX_MAX_LEN, SUFFIX_LEN | ||
| from typeid.constants import SUFFIX_LEN | ||
| from typeid.errors import PrefixValidationException, SuffixValidationException | ||
@@ -7,3 +9,4 @@ | ||
| def validate_prefix(prefix: str) -> None: | ||
| if not prefix.islower() or not prefix.isascii() or len(prefix) > PREFIX_MAX_LEN or not prefix.isalpha(): | ||
| # See https://github.com/jetify-com/typeid/tree/main/spec | ||
| if not re.match("^([a-z]([a-z_]{0,61}[a-z])?)?$", prefix): | ||
| raise PrefixValidationException(f"Invalid prefix: {prefix}.") | ||
@@ -10,0 +13,0 @@ |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
21552
0.43%483
0.42%