Skip to content

Commit b55d734

Browse files
committed
updated cache_bundle -> bundle, removed unused json_serialize function (superceded by Pydantic)
1 parent 9309f61 commit b55d734

File tree

2 files changed

+5
-22
lines changed

2 files changed

+5
-22
lines changed

src/rid_lib/ext/cache.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ def file_path_to(self, rid: RID) -> str:
1313
encoded_rid_str = b64_encode(str(rid))
1414
return f"{self.directory_path}/{encoded_rid_str}.json"
1515

16-
def write(self, cache_bundle: Bundle) -> Bundle:
16+
def write(self, bundle: Bundle) -> Bundle:
1717
"""Writes bundle to cache, returns a Bundle."""
1818
if not os.path.exists(self.directory_path):
1919
os.makedirs(self.directory_path)
2020

2121
with open(
22-
file=self.file_path_to(cache_bundle.manifest.rid),
22+
file=self.file_path_to(bundle.manifest.rid),
2323
mode="w",
2424
encoding="utf-8"
2525
) as f:
26-
f.write(cache_bundle.model_dump_json(indent=2))
26+
f.write(bundle.model_dump_json(indent=2))
2727

28-
return cache_bundle
28+
return bundle
2929

3030
def exists(self, rid: RID) -> bool:
3131
return os.path.exists(

src/rid_lib/ext/utils.py

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import json
22
import hashlib
33
from base64 import urlsafe_b64encode, urlsafe_b64decode
4-
from dataclasses import asdict, is_dataclass
5-
from datetime import datetime
64
from pydantic import BaseModel
7-
from rid_lib import RID
85

96

107
def sha256_hash_json(data: dict | BaseModel):
@@ -22,18 +19,4 @@ def b64_encode(string: str):
2219

2320
def b64_decode(string: str):
2421
return urlsafe_b64decode(
25-
(string + "=" * (-len(string) % 4)).encode()).decode()
26-
27-
def json_serialize(obj):
28-
if isinstance(obj, RID):
29-
return str(obj)
30-
elif is_dataclass(obj) and not isinstance(obj, type):
31-
return json_serialize(asdict(obj))
32-
elif isinstance(obj, datetime):
33-
return obj.isoformat()
34-
elif isinstance(obj, (list, tuple)):
35-
return [json_serialize(item) for item in obj]
36-
elif isinstance(obj, dict):
37-
return {key: json_serialize(value) for key, value in obj.items()}
38-
else:
39-
return obj
22+
(string + "=" * (-len(string) % 4)).encode()).decode()

0 commit comments

Comments
 (0)