Update ulid-transform to 0.10.1 (#121321)
This commit is contained in:
parent
94db251aea
commit
89ffee9ad5
7 changed files with 13 additions and 54 deletions
|
@ -7,33 +7,16 @@ from functools import lru_cache
|
|||
import logging
|
||||
from uuid import UUID
|
||||
|
||||
from homeassistant.util.ulid import bytes_to_ulid, ulid_to_bytes
|
||||
from homeassistant.util.ulid import ( # noqa: F401
|
||||
bytes_to_ulid,
|
||||
bytes_to_ulid_or_none,
|
||||
ulid_to_bytes,
|
||||
ulid_to_bytes_or_none,
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def ulid_to_bytes_or_none(ulid: str | None) -> bytes | None:
|
||||
"""Convert an ulid to bytes."""
|
||||
if ulid is None:
|
||||
return None
|
||||
try:
|
||||
return ulid_to_bytes(ulid)
|
||||
except ValueError:
|
||||
_LOGGER.exception("Error converting ulid %s to bytes", ulid)
|
||||
return None
|
||||
|
||||
|
||||
def bytes_to_ulid_or_none(_bytes: bytes | None) -> str | None:
|
||||
"""Convert bytes to a ulid."""
|
||||
if _bytes is None:
|
||||
return None
|
||||
try:
|
||||
return bytes_to_ulid(_bytes)
|
||||
except ValueError:
|
||||
_LOGGER.exception("Error converting bytes %s to ulid", _bytes)
|
||||
return None
|
||||
|
||||
|
||||
@lru_cache(maxsize=16)
|
||||
def uuid_hex_to_bytes_or_none(uuid_hex: str | None) -> bytes | None:
|
||||
"""Convert a uuid hex to bytes."""
|
||||
|
|
|
@ -56,7 +56,7 @@ PyYAML==6.0.1
|
|||
requests==2.32.3
|
||||
SQLAlchemy==2.0.31
|
||||
typing-extensions>=4.12.2,<5.0
|
||||
ulid-transform==0.9.0
|
||||
ulid-transform==0.10.1
|
||||
urllib3>=1.26.5,<2
|
||||
voluptuous-openapi==0.0.4
|
||||
voluptuous-serialize==2.6.0
|
||||
|
|
|
@ -4,10 +4,12 @@ from __future__ import annotations
|
|||
|
||||
from ulid_transform import (
|
||||
bytes_to_ulid,
|
||||
bytes_to_ulid_or_none,
|
||||
ulid_at_time,
|
||||
ulid_hex,
|
||||
ulid_now,
|
||||
ulid_to_bytes,
|
||||
ulid_to_bytes_or_none,
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
|
@ -17,6 +19,8 @@ __all__ = [
|
|||
"ulid_to_bytes",
|
||||
"bytes_to_ulid",
|
||||
"ulid_now",
|
||||
"ulid_to_bytes_or_none",
|
||||
"bytes_to_ulid_or_none",
|
||||
]
|
||||
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ dependencies = [
|
|||
"requests==2.32.3",
|
||||
"SQLAlchemy==2.0.31",
|
||||
"typing-extensions>=4.12.2,<5.0",
|
||||
"ulid-transform==0.9.0",
|
||||
"ulid-transform==0.10.1",
|
||||
# Constrain urllib3 to ensure we deal with CVE-2020-26137 and CVE-2021-33503
|
||||
# Temporary setting an upper bound, to prevent compat issues with urllib3>=2
|
||||
# https://github.com/home-assistant/core/issues/97248
|
||||
|
|
|
@ -37,7 +37,7 @@ PyYAML==6.0.1
|
|||
requests==2.32.3
|
||||
SQLAlchemy==2.0.31
|
||||
typing-extensions>=4.12.2,<5.0
|
||||
ulid-transform==0.9.0
|
||||
ulid-transform==0.10.1
|
||||
urllib3>=1.26.5,<2
|
||||
voluptuous==0.15.2
|
||||
voluptuous-serialize==2.6.0
|
||||
|
|
|
@ -944,8 +944,6 @@ async def test_saving_event_invalid_context_ulid(
|
|||
)
|
||||
}
|
||||
|
||||
assert "invalid" in caplog.text
|
||||
|
||||
assert len(events) == 1
|
||||
assert json_loads(events["test_event"]) == event_data
|
||||
|
||||
|
|
|
@ -15,11 +15,9 @@ from homeassistant.components.recorder.db_schema import (
|
|||
)
|
||||
from homeassistant.components.recorder.models import (
|
||||
LazyState,
|
||||
bytes_to_ulid_or_none,
|
||||
process_datetime_to_timestamp,
|
||||
process_timestamp,
|
||||
process_timestamp_to_utc_isoformat,
|
||||
ulid_to_bytes_or_none,
|
||||
)
|
||||
from homeassistant.const import EVENT_STATE_CHANGED
|
||||
import homeassistant.core as ha
|
||||
|
@ -428,27 +426,3 @@ async def test_process_datetime_to_timestamp_mirrors_utc_isoformat_behavior(
|
|||
process_datetime_to_timestamp(datetime_hst_timezone)
|
||||
== dt_util.parse_datetime("2016-07-09T21:00:00+00:00").timestamp()
|
||||
)
|
||||
|
||||
|
||||
def test_ulid_to_bytes_or_none(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test ulid_to_bytes_or_none."""
|
||||
|
||||
assert (
|
||||
ulid_to_bytes_or_none("01EYQZJXZ5Z1Z1Z1Z1Z1Z1Z1Z1")
|
||||
== b"\x01w\xaf\xf9w\xe5\xf8~\x1f\x87\xe1\xf8~\x1f\x87\xe1"
|
||||
)
|
||||
assert ulid_to_bytes_or_none("invalid") is None
|
||||
assert "invalid" in caplog.text
|
||||
assert ulid_to_bytes_or_none(None) is None
|
||||
|
||||
|
||||
def test_bytes_to_ulid_or_none(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test bytes_to_ulid_or_none."""
|
||||
|
||||
assert (
|
||||
bytes_to_ulid_or_none(b"\x01w\xaf\xf9w\xe5\xf8~\x1f\x87\xe1\xf8~\x1f\x87\xe1")
|
||||
== "01EYQZJXZ5Z1Z1Z1Z1Z1Z1Z1Z1"
|
||||
)
|
||||
assert bytes_to_ulid_or_none(b"invalid") is None
|
||||
assert "invalid" in caplog.text
|
||||
assert bytes_to_ulid_or_none(None) is None
|
||||
|
|
Loading…
Add table
Reference in a new issue