File tree Expand file tree Collapse file tree 2 files changed +5
-22
lines changed Expand file tree Collapse file tree 2 files changed +5
-22
lines changed Original file line number Diff line number Diff 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 (
Original file line number Diff line number Diff line change 11import json
22import hashlib
33from base64 import urlsafe_b64encode , urlsafe_b64decode
4- from dataclasses import asdict , is_dataclass
5- from datetime import datetime
64from pydantic import BaseModel
7- from rid_lib import RID
85
96
107def sha256_hash_json (data : dict | BaseModel ):
@@ -22,18 +19,4 @@ def b64_encode(string: str):
2219
2320def 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 ()
You can’t perform that action at this time.
0 commit comments