mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
[fix] Avoid warning and use safeloader
This commit is contained in:
parent
f0590907c9
commit
ccb6dc54b1
10 changed files with 13 additions and 13 deletions
|
@ -32,7 +32,7 @@ def get_dict_actions(OPTION_SUBTREE, category):
|
||||||
with open(ACTIONSMAP_FILE, "r") as stream:
|
with open(ACTIONSMAP_FILE, "r") as stream:
|
||||||
|
|
||||||
# Getting the dictionary containning what actions are possible per category
|
# Getting the dictionary containning what actions are possible per category
|
||||||
OPTION_TREE = yaml.load(stream)
|
OPTION_TREE = yaml.safe_load(stream)
|
||||||
|
|
||||||
CATEGORY = [
|
CATEGORY = [
|
||||||
category for category in OPTION_TREE.keys() if not category.startswith("_")
|
category for category in OPTION_TREE.keys() if not category.startswith("_")
|
||||||
|
|
|
@ -86,7 +86,7 @@ key, value = os.environ['KEY'], os.environ.get('VALUE', None)
|
||||||
setting_file = "/etc/yunohost/apps/%s/settings.yml" % app
|
setting_file = "/etc/yunohost/apps/%s/settings.yml" % app
|
||||||
assert os.path.exists(setting_file), "Setting file %s does not exists ?" % setting_file
|
assert os.path.exists(setting_file), "Setting file %s does not exists ?" % setting_file
|
||||||
with open(setting_file) as f:
|
with open(setting_file) as f:
|
||||||
settings = yaml.load(f)
|
settings = yaml.safe_load(f)
|
||||||
if action == "get":
|
if action == "get":
|
||||||
if key in settings:
|
if key in settings:
|
||||||
print(settings[key])
|
print(settings[key])
|
||||||
|
@ -96,7 +96,7 @@ else:
|
||||||
del settings[key]
|
del settings[key]
|
||||||
elif action == "set":
|
elif action == "set":
|
||||||
if key in ['redirected_urls', 'redirected_regex']:
|
if key in ['redirected_urls', 'redirected_regex']:
|
||||||
value = yaml.load(value)
|
value = yaml.safe_load(value)
|
||||||
settings[key] = value
|
settings[key] = value
|
||||||
else:
|
else:
|
||||||
raise ValueError("action should either be get, set or delete")
|
raise ValueError("action should either be get, set or delete")
|
||||||
|
|
|
@ -212,10 +212,10 @@ import yaml
|
||||||
|
|
||||||
|
|
||||||
with open('services.yml') as f:
|
with open('services.yml') as f:
|
||||||
new_services = yaml.load(f)
|
new_services = yaml.safe_load(f)
|
||||||
|
|
||||||
with open('/etc/yunohost/services.yml') as f:
|
with open('/etc/yunohost/services.yml') as f:
|
||||||
services = yaml.load(f) or {}
|
services = yaml.safe_load(f) or {}
|
||||||
|
|
||||||
updated = False
|
updated = False
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ def ordered_yaml_load(stream):
|
||||||
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
|
yaml.resolver.BaseResolver.DEFAULT_MAPPING_TAG,
|
||||||
lambda loader, node: OrderedDict(loader.construct_pairs(node)),
|
lambda loader, node: OrderedDict(loader.construct_pairs(node)),
|
||||||
)
|
)
|
||||||
return yaml.load(stream, OrderedLoader)
|
return yaml.safe_load(stream, OrderedLoader)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
|
|
@ -1518,7 +1518,7 @@ def app_setting(app, key, value=None, delete=False):
|
||||||
# SET
|
# SET
|
||||||
else:
|
else:
|
||||||
if key in ["redirected_urls", "redirected_regex"]:
|
if key in ["redirected_urls", "redirected_regex"]:
|
||||||
value = yaml.load(value)
|
value = yaml.safe_load(value)
|
||||||
app_settings[key] = value
|
app_settings[key] = value
|
||||||
|
|
||||||
_set_app_settings(app, app_settings)
|
_set_app_settings(app, app_settings)
|
||||||
|
@ -2175,7 +2175,7 @@ def _get_app_settings(app_id):
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(APPS_SETTING_PATH, app_id, "settings.yml")) as f:
|
with open(os.path.join(APPS_SETTING_PATH, app_id, "settings.yml")) as f:
|
||||||
settings = yaml.load(f)
|
settings = yaml.safe_load(f)
|
||||||
# If label contains unicode char, this may later trigger issues when building strings...
|
# If label contains unicode char, this may later trigger issues when building strings...
|
||||||
# FIXME: this should be propagated to read_yaml so that this fix applies everywhere I think...
|
# FIXME: this should be propagated to read_yaml so that this fix applies everywhere I think...
|
||||||
settings = {k: v for k, v in settings.items()}
|
settings = {k: v for k, v in settings.items()}
|
||||||
|
|
|
@ -179,7 +179,7 @@ def firewall_list(raw=False, by_ip_version=False, list_forwarded=False):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
with open(FIREWALL_FILE) as f:
|
with open(FIREWALL_FILE) as f:
|
||||||
firewall = yaml.load(f)
|
firewall = yaml.safe_load(f)
|
||||||
if raw:
|
if raw:
|
||||||
return firewall
|
return firewall
|
||||||
|
|
||||||
|
|
|
@ -444,7 +444,7 @@ def _get_regenconf_infos():
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open(REGEN_CONF_FILE, "r") as f:
|
with open(REGEN_CONF_FILE, "r") as f:
|
||||||
return yaml.load(f)
|
return yaml.safe_load(f)
|
||||||
except Exception:
|
except Exception:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
|
@ -670,7 +670,7 @@ def _get_services():
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
with open("/etc/yunohost/services.yml", "r") as f:
|
with open("/etc/yunohost/services.yml", "r") as f:
|
||||||
services = yaml.load(f) or {}
|
services = yaml.safe_load(f) or {}
|
||||||
except Exception:
|
except Exception:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
|
|
|
@ -2,4 +2,4 @@ import yaml
|
||||||
|
|
||||||
|
|
||||||
def test_yaml_syntax():
|
def test_yaml_syntax():
|
||||||
yaml.load(open("data/actionsmap/yunohost.yml"))
|
yaml.safe_load(open("data/actionsmap/yunohost.yml"))
|
||||||
|
|
|
@ -108,7 +108,7 @@ def find_expected_string_keys():
|
||||||
yield m
|
yield m
|
||||||
|
|
||||||
# Keys for the actionmap ...
|
# Keys for the actionmap ...
|
||||||
for category in yaml.load(open("data/actionsmap/yunohost.yml")).values():
|
for category in yaml.safe_load(open("data/actionsmap/yunohost.yml")).values():
|
||||||
if "actions" not in category.keys():
|
if "actions" not in category.keys():
|
||||||
continue
|
continue
|
||||||
for action in category["actions"].values():
|
for action in category["actions"].values():
|
||||||
|
|
Loading…
Add table
Reference in a new issue