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

1from __future__ import annotations 

2 

3import json 

4from typing import Any 

5 

6 

7class BytesBlob: 

8 def __init__(self, blob: bytes) -> None: 

9 super().__init__() 

10 

11 self._blob_bytes: bytes = blob 

12 

13 def as_bytes(self) -> bytes: 

14 return self._blob_bytes 

15 

16 

17class StrBlob(BytesBlob): 

18 def __init__(self, blob: str) -> None: 

19 super().__init__(blob.encode()) 

20 

21 def as_str(self) -> str: 

22 return self._blob_bytes.decode() 

23 

24 

25class JsonDictBlob(StrBlob): 

26 def __init__(self, blob: dict[str, Any]) -> None: 

27 super().__init__(json.dumps(blob)) 

28 

29 def as_dict(self) -> dict[str, Any]: 

30 return json.loads(self._blob_bytes)