mirror of
https://github.com/httpie/cli.git
synced 2025-02-01 12:57:57 +02:00
Split session JSON serialization and writing to file
To avoid writing invalid JSON in case of presence of unserializable data due to an internal bug.
This commit is contained in:
parent
9931747901
commit
0d480139e4
@ -49,7 +49,7 @@ def get_default_config_dir() -> Path:
|
|||||||
|
|
||||||
# 4. XDG
|
# 4. XDG
|
||||||
xdg_config_home_dir = os.environ.get(
|
xdg_config_home_dir = os.environ.get(
|
||||||
ENV_XDG_CONFIG_HOME, # 4.1. explicit
|
ENV_XDG_CONFIG_HOME, # 4.1. explicit
|
||||||
home_dir / DEFAULT_RELATIVE_XDG_CONFIG_HOME # 4.2. default
|
home_dir / DEFAULT_RELATIVE_XDG_CONFIG_HOME # 4.2. default
|
||||||
)
|
)
|
||||||
return Path(xdg_config_home_dir) / DEFAULT_CONFIG_DIRNAME
|
return Path(xdg_config_home_dir) / DEFAULT_CONFIG_DIRNAME
|
||||||
@ -108,16 +108,14 @@ class BaseConfigDict(dict):
|
|||||||
|
|
||||||
self.ensure_directory()
|
self.ensure_directory()
|
||||||
|
|
||||||
|
json_string = json.dumps(
|
||||||
|
obj=self,
|
||||||
|
indent=4,
|
||||||
|
sort_keys=True,
|
||||||
|
ensure_ascii=True,
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
with self.path.open('w') as f:
|
self.path.write_text(json_string + '\n')
|
||||||
json.dump(
|
|
||||||
obj=self,
|
|
||||||
fp=f,
|
|
||||||
indent=4,
|
|
||||||
sort_keys=True,
|
|
||||||
ensure_ascii=True,
|
|
||||||
)
|
|
||||||
f.write('\n')
|
|
||||||
except IOError:
|
except IOError:
|
||||||
if not fail_silently:
|
if not fail_silently:
|
||||||
raise
|
raise
|
||||||
|
Loading…
x
Reference in New Issue
Block a user