move json loading and saving to DotDict
This commit is contained in:
parent
bdbd1f4621
commit
2dafcbcc05
|
@ -14,11 +14,11 @@ from . import logging
|
|||
|
||||
izzylog = logging.logger['IzzyLib']
|
||||
|
||||
from .path import Path
|
||||
from .dotdict import DotDict, LowerDotDict, DefaultDotDict, MultiDotDict, JsonEncoder
|
||||
from .misc import *
|
||||
from .cache import LruCache, TtlCache
|
||||
from .connection import Connection
|
||||
from .path import Path
|
||||
|
||||
from .http_urllib_client import HttpUrllibClient, HttpUrllibResponse
|
||||
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import json
|
||||
|
||||
from . import Path
|
||||
|
||||
|
||||
class DotDict(dict):
|
||||
dict_ignore_types = ['basecache', 'lrucache', 'ttlcache']
|
||||
|
@ -71,13 +73,14 @@ class DotDict(dict):
|
|||
self.update(data)
|
||||
|
||||
|
||||
def load_json(self, path: str=None):
|
||||
self.update(Path(path).load_json())
|
||||
def load_json(self, path):
|
||||
with open(path) as fd:
|
||||
self.update(json.load(fd))
|
||||
|
||||
|
||||
def save_json(self, path: str, **kwargs):
|
||||
with Path(path).open(w) as fd:
|
||||
write(self.toJson(*kwargs))
|
||||
def save_json(self, path, indent=None):
|
||||
with open(path, 'w') as fp:
|
||||
fp.write(self.to_json(indent=indent))
|
||||
|
||||
|
||||
## This has to be reworked tbh
|
||||
|
|
|
@ -3,11 +3,9 @@ import os, shutil
|
|||
from datetime import datetime
|
||||
from functools import cached_property
|
||||
|
||||
from . import DotDict, JsonEncoder
|
||||
|
||||
|
||||
class Path(str):
|
||||
def __init__(self, path, exist=True, missing=True, parents=True):
|
||||
def __init__(self, path=os.getcwd(), exist=True, missing=True, parents=True):
|
||||
if str(path).startswith('~'):
|
||||
str.__new__(Path, os.path.expanduser(path))
|
||||
|
||||
|
@ -73,15 +71,6 @@ class Path(str):
|
|||
return Path(os.path.join(self, new_path))
|
||||
|
||||
|
||||
def json_load(self):
|
||||
return DotDict(read(self))
|
||||
|
||||
|
||||
def json_save(self, data, indent=None):
|
||||
with open(self, 'w') as fp:
|
||||
fp.write(json.dumps(data, indent=indent, cls=JsonEncoder))
|
||||
|
||||
|
||||
def link(self, path):
|
||||
target = Path(path)
|
||||
|
||||
|
|
Loading…
Reference in a new issue