| 16 | # =========================== |
| 17 | |
| 18 | class 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 | |
| 40 | class JsonHandler(BaseFileHandler): |
| 41 |
nothing calls this directly
no outgoing calls
no test coverage detected