MCPcopy Create free account
hub / github.com/IDEA-Research/DINO / BaseFileHandler

Class BaseFileHandler

util/slio.py:18–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

16# ===========================
17
18class BaseFileHandler(metaclass=ABCMeta):
19
20 @abstractmethod
21 def load_from_fileobj(self, file, **kwargs):
22 pass
23
24 @abstractmethod
25 def dump_to_fileobj(self, obj, file, **kwargs):
26 pass
27
28 @abstractmethod
29 def dump_to_str(self, obj, **kwargs):
30 pass
31
32 def load_from_path(self, filepath, mode='r', **kwargs):
33 with open(filepath, mode) as f:
34 return self.load_from_fileobj(f, **kwargs)
35
36 def dump_to_path(self, obj, filepath, mode='w', **kwargs):
37 with open(filepath, mode) as f:
38 self.dump_to_fileobj(obj, f, **kwargs)
39
40class JsonHandler(BaseFileHandler):
41

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected