mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 00:01:36 +00:00
[web] Update OptManager.save() to suit the need of mitmweb.
This commit is contained in:
parent
93cd1562de
commit
6c4dbcc7a7
@ -512,13 +512,15 @@ def serialize(opts, text, defaults=False):
|
||||
return ruamel.yaml.round_trip_dump(data)
|
||||
|
||||
|
||||
def save(opts, path, defaults=False):
|
||||
def save(opts, path=None, defaults=False):
|
||||
"""
|
||||
Save to path. If the destination file exists, modify it in-place.
|
||||
If the path is given, save to path, otherwise return the serialized data.
|
||||
|
||||
If the destination file exists, modify it in-place.
|
||||
|
||||
Raises OptionsError if the existing data is corrupt.
|
||||
"""
|
||||
if os.path.exists(path) and os.path.isfile(path):
|
||||
if path and os.path.exists(path) and os.path.isfile(path):
|
||||
with open(path, "rt", encoding="utf8") as f:
|
||||
try:
|
||||
data = f.read()
|
||||
@ -529,5 +531,9 @@ def save(opts, path, defaults=False):
|
||||
else:
|
||||
data = ""
|
||||
data = serialize(opts, data, defaults)
|
||||
|
||||
if path:
|
||||
with open(path, "wt", encoding="utf8") as f:
|
||||
f.write(data)
|
||||
else:
|
||||
return data
|
||||
|
Loading…
Reference in New Issue
Block a user