ulid-transform 0.9.0__cp312-cp312-win_amd64.whl → 0.10.1__cp312-cp312-win_amd64.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.
@@ -2,6 +2,7 @@
2
2
  from libcpp.string cimport string
3
3
 
4
4
  from time import time
5
+ from typing import Optional
5
6
 
6
7
  import cython
7
8
 
@@ -28,3 +29,13 @@ def _bytes_to_ulid(ulid_bytes: bytes) -> str:
28
29
  if len(ulid_bytes) != 16:
29
30
  raise ValueError(f"ULID bytes be 16 bytes: {ulid_bytes}")
30
31
  return _cpp_bytes_to_ulid(ulid_bytes).decode("ascii")
32
+
33
+ def _ulid_to_bytes_or_none(ulid_str: Optional[str]) -> Optional[bytes]:
34
+ if ulid_str is None or len(ulid_str) != 26:
35
+ return None
36
+ return _cpp_ulid_to_bytes(ulid_str.encode("ascii"))
37
+
38
+ def _bytes_to_ulid_or_none(ulid_bytes: Optional[bytes]) -> Optional[str]:
39
+ if ulid_bytes is None or len(ulid_bytes) != 16:
40
+ return None
41
+ return _cpp_bytes_to_ulid(ulid_bytes).decode("ascii")
@@ -410,10 +410,33 @@ def bytes_to_ulid(value: bytes) -> str:
410
410
  return _encode(value)
411
411
 
412
412
 
413
+ def ulid_to_bytes_or_none(ulid: str | None) -> bytes | None:
414
+ """Convert an ulid to bytes."""
415
+ if ulid is None:
416
+ return None
417
+ try:
418
+ return ulid_to_bytes(ulid)
419
+ except ValueError:
420
+ return None
421
+
422
+
423
+ def bytes_to_ulid_or_none(_bytes: bytes | None) -> str | None:
424
+ """Convert bytes to a ulid."""
425
+ if _bytes is None:
426
+ return None
427
+ try:
428
+ return bytes_to_ulid(_bytes)
429
+ except ValueError:
430
+ return None
431
+
432
+
413
433
  try:
414
434
  from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
415
435
  _bytes_to_ulid as bytes_to_ulid,
416
436
  )
437
+ from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
438
+ _bytes_to_ulid_or_none as bytes_to_ulid_or_none,
439
+ )
417
440
  from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
418
441
  _ulid_at_time as ulid_at_time,
419
442
  )
@@ -423,5 +446,8 @@ try:
423
446
  from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
424
447
  _ulid_to_bytes as ulid_to_bytes,
425
448
  )
449
+ from ._ulid_impl import ( # type: ignore[no-redef] # noqa: F811 F401 # pragma: no cover
450
+ _ulid_to_bytes_or_none as ulid_to_bytes_or_none,
451
+ )
426
452
  except ImportError: # pragma: no cover
427
453
  pass # pragma: no cover
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: ulid-transform
3
- Version: 0.9.0
3
+ Version: 0.10.1
4
4
  Summary: Create and transform ULIDs
5
5
  Home-page: https://github.com/bdraco/ulid-transform
6
6
  License: MIT
@@ -15,6 +15,7 @@ Classifier: Operating System :: OS Independent
15
15
  Classifier: Programming Language :: Python :: 3
16
16
  Classifier: Programming Language :: Python :: 3.10
17
17
  Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
18
19
  Classifier: Topic :: Software Development :: Libraries
19
20
  Project-URL: Bug Tracker, https://github.com/bdraco/ulid-transform/issues
20
21
  Project-URL: Changelog, https://github.com/bdraco/ulid-transform/blob/main/CHANGELOG.md
@@ -68,6 +69,12 @@ This library will use the CPP implementation from https://github.com/suyash/ulid
68
69
  b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee'
69
70
  >> ulid_transform.bytes_to_ulid(b"\x01\x86\x99?\xe8\xf3\x11\xbc\xed\xef\x86U.9\x03z")
70
71
  '01GTCKZT7K26YEVVW6AMQ3J0VT'
72
+ >>> ulid_transform.ulid_to_bytes_or_none('0001HZX0NW00GW0X476W5TVBFE')
73
+ b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee'
74
+ >>> ulid_transform.ulid_to_bytes_or_none(None)
75
+ >>> ulid_transform.bytes_to_ulid_or_none(b'\x00\x00c\xfe\x82\xbc\x00!\xc0t\x877\x0b\xad\xad\xee')
76
+ '0001HZX0NW00GW0X476W5TVBFE'
77
+ >>> ulid_transform.bytes_to_ulid_or_none(None)
71
78
  ```
72
79
 
73
80
  ## Installation
@@ -0,0 +1,15 @@
1
+ ulid_transform/__init__.py,sha256=p3JHoB6geHaG050xbrrcyDbWg6c1S7lz_mZ8RKaUHoc,377
2
+ ulid_transform/_ulid_impl.cpp,sha256=EcAHAHy5VWDBoSRW84p7gW1n356Pq_U-TgUn-Y4qLdQ,330260
3
+ ulid_transform/_ulid_impl.pyx,sha256=Qlhh9TuB5JyxNHhr370W5pgYx5AdZpkvANbBYVLCmWY,1347
4
+ ulid_transform/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ ulid_transform/ulid.hh,sha256=RwGduPUOt5AEfAaAkafGaHyhr2yd7vfHJeY0lOXlTPw,312
6
+ ulid_transform/ulid_impl.py,sha256=-OqxT7yi7tloT6EnRMmxLMgSLmGSb-hPhO4kn99vDiU,10934
7
+ ulid_transform/ulid_struct.hh,sha256=Jh326iAyOkEaEpBZr4CY6xOOSXqO_hcsBS37qUcUCeM,20025
8
+ ulid_transform/ulid_uint128.hh,sha256=ibwgd8Qksjc0oG52h8kb7ClJruJe9CyfMQra4B3fk1E,15370
9
+ ulid_transform/ulid_wrapper.cpp,sha256=-S7Eq1ae0bHeEOaY1uWHRn2RA9MQG2PrFcIJSl_37Rg,933
10
+ ulid_transform/ulid_wrapper.h,sha256=H_AaGGLSS3ymjaRh4uUhG-lvFUrwJhnLL0irzDoqgZM,275
11
+ ulid_transform/_ulid_impl.cp312-win_amd64.pyd,sha256=pDT9jy5_mRCBoVK3ZvkfQTpYq3vhZ57JhKTDTc15eR4,55808
12
+ ulid_transform-0.10.1.dist-info/LICENSE,sha256=glXAnenXQvBuN4WzZ8ikikOHF6v3qq4_z8fCZobbgxs,1094
13
+ ulid_transform-0.10.1.dist-info/METADATA,sha256=ydvpOxvAknjpYdK-nYRIh4MinZg1R5YeM21If61j25I,5389
14
+ ulid_transform-0.10.1.dist-info/WHEEL,sha256=4N0hGcnWMI_Ty6ATf4qJqqSl-UNI-Ln828iTWGIywmU,98
15
+ ulid_transform-0.10.1.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: false
4
4
  Tag: cp312-cp312-win_amd64
@@ -1,15 +0,0 @@
1
- ulid_transform/__init__.py,sha256=Ygji_LvT3WDRjCkum56ZATKaKBDuPVOobFdvnjgKuR8,200
2
- ulid_transform/_ulid_impl.cpp,sha256=3S94mB3X0qP1yur8Sfq-Z0xX3d89ncInKSMAexb9e34,303727
3
- ulid_transform/_ulid_impl.pyx,sha256=YpiQyHY-1L3n0WZMnfLV2iKxX_UdvdcukunYmb2sfco,906
4
- ulid_transform/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
- ulid_transform/ulid.hh,sha256=RwGduPUOt5AEfAaAkafGaHyhr2yd7vfHJeY0lOXlTPw,312
6
- ulid_transform/ulid_impl.py,sha256=axxu_OzIg2IbRwomlwJWzUOhkfSqSlSFq4PwwljvG3o,10137
7
- ulid_transform/ulid_struct.hh,sha256=Jh326iAyOkEaEpBZr4CY6xOOSXqO_hcsBS37qUcUCeM,20025
8
- ulid_transform/ulid_uint128.hh,sha256=ibwgd8Qksjc0oG52h8kb7ClJruJe9CyfMQra4B3fk1E,15370
9
- ulid_transform/ulid_wrapper.cpp,sha256=-S7Eq1ae0bHeEOaY1uWHRn2RA9MQG2PrFcIJSl_37Rg,933
10
- ulid_transform/ulid_wrapper.h,sha256=H_AaGGLSS3ymjaRh4uUhG-lvFUrwJhnLL0irzDoqgZM,275
11
- ulid_transform/_ulid_impl.cp310-win_amd64.pyd,sha256=-aa1Sf_SMQiegSgB8lgEdLb-PhqDD120Mgg2IuB5xSQ,50688
12
- ulid_transform-0.9.0.dist-info/LICENSE,sha256=glXAnenXQvBuN4WzZ8ikikOHF6v3qq4_z8fCZobbgxs,1094
13
- ulid_transform-0.9.0.dist-info/METADATA,sha256=u-O1V_V9o2imsx2LvthvkmxuhyYXzpcVcSg8LCWiJBo,4989
14
- ulid_transform-0.9.0.dist-info/WHEEL,sha256=5DKf19SL3e8kWNQgvt4aTi-7Oob2_ZHN7ZCmqB-PupE,98
15
- ulid_transform-0.9.0.dist-info/RECORD,,