Coverage for src/blob_dict/blob.py: 0%
19 statements
« prev ^ index » next coverage.py v7.7.0, created at 2025-03-18 23:01 -0700
« prev ^ index » next coverage.py v7.7.0, created at 2025-03-18 23:01 -0700
1from __future__ import annotations
3import json
4from typing import Any
7class BytesBlob:
8 def __init__(self, blob: bytes) -> None:
9 super().__init__()
11 self._blob_bytes: bytes = blob
13 def as_bytes(self) -> bytes:
14 return self._blob_bytes
17class StrBlob(BytesBlob):
18 def __init__(self, blob: str) -> None:
19 super().__init__(blob.encode())
21 def as_str(self) -> str:
22 return self._blob_bytes.decode()
25class JsonDictBlob(StrBlob):
26 def __init__(self, blob: dict[str, Any]) -> None:
27 super().__init__(json.dumps(blob))
29 def as_dict(self) -> dict[str, Any]:
30 return json.loads(self._blob_bytes)