Skip to content

Commit 5383d1e

Browse files
committed
fix: use safe_load for parsing yaml
(closes #464)
1 parent 77e7532 commit 5383d1e

File tree

13 files changed

+25
-23
lines changed

13 files changed

+25
-23
lines changed

renku/api/datasets.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def with_dataset(self, name=None):
7878

7979
if path.exists():
8080
with path.open('r') as f:
81-
source = yaml.load(f) or {}
81+
source = yaml.safe_load(f) or {}
8282
dataset = Dataset.from_jsonld(source, __reference__=path)
8383

8484
if dataset is None:

renku/api/repository.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright 2018 - Swiss Data Science Center (SDSC)
3+
# Copyright 2018-2019 - Swiss Data Science Center (SDSC)
44
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
55
# Eidgenössische Technische Hochschule Zürich (ETHZ).
66
#
@@ -191,7 +191,7 @@ def process_commit(self, commit=None, path=None):
191191
if path:
192192
data = (commit.tree / path).data_stream.read()
193193
process = CWLClass.from_cwl(
194-
yaml.load(data), __reference__=Path(path)
194+
yaml.safe_load(data), __reference__=Path(path)
195195
)
196196

197197
return process.create_run(
@@ -294,7 +294,7 @@ def with_metadata(self):
294294

295295
if self.renku_metadata_path.exists():
296296
with metadata_path.open('r') as f:
297-
source = yaml.load(f) or {}
297+
source = yaml.safe_load(f) or {}
298298
else:
299299
source = {}
300300

renku/cli/_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright 2017 - Swiss Data Science Center (SDSC)
3+
# Copyright 2017-2019 - Swiss Data Science Center (SDSC)
44
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
55
# Eidgenössische Technische Hochschule Zürich (ETHZ).
66
#
@@ -64,7 +64,7 @@ def read_config(path=None, final=False):
6464
"""Read Renku configuration."""
6565
try:
6666
with open(config_path(path, final=final), 'r') as configfile:
67-
return yaml.load(configfile) or {}
67+
return yaml.safe_load(configfile) or {}
6868
except FileNotFoundError:
6969
return {}
7070

renku/cli/migrate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def datasets(ctx, client):
4444
with client.lock:
4545
for old_path in _dataset_metadata_pre_0_3_4(client):
4646
with old_path.open('r') as fp:
47-
dataset = Dataset.from_jsonld(yaml.load(fp))
47+
dataset = Dataset.from_jsonld(yaml.safe_load(fp))
4848

4949
name = str(old_path.parent.relative_to(client.path / 'data'))
5050
new_path = (

renku/cli/runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# Copyright 2018 - Swiss Data Science Center (SDSC)
3+
# Copyright 2018-2019 - Swiss Data Science Center (SDSC)
44
# A partnership between École Polytechnique Fédérale de Lausanne (EPFL) and
55
# Eidgenössische Technische Hochschule Zürich (ETHZ).
66
#
@@ -92,7 +92,7 @@ def rerun(client, run, job):
9292
args.append(job_file.name)
9393

9494
with job_file as fp:
95-
yaml.dump(yaml.load(job), stream=fp, encoding='utf-8')
95+
yaml.dump(yaml.safe_load(job), stream=fp, encoding='utf-8')
9696

9797
if run:
9898
return call(args, cwd=os.getcwd())

renku/models/_jsonld.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,9 @@ def from_yaml(cls, path):
356356
import yaml
357357

358358
with path.open(mode='r') as fp:
359-
self = cls.from_jsonld(yaml.load(fp) or {}, __reference__=path)
359+
self = cls.from_jsonld(
360+
yaml.safe_load(fp) or {}, __reference__=path
361+
)
360362

361363
return self
362364

renku/models/cwl/_ascwl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ def from_yaml(cls, path):
6666
import yaml
6767

6868
with path.open(mode='r') as fp:
69-
self = cls.from_cwl(yaml.load(fp), __reference__=path)
69+
self = cls.from_cwl(yaml.safe_load(fp), __reference__=path)
7070

7171
return self
7272

renku/models/provenance/activities.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ def _load(step):
413413
import yaml
414414
data = (self.commit.tree / basedir /
415415
step.run).data_stream.read()
416-
return CWLClass.from_cwl(yaml.load(data))
416+
return CWLClass.from_cwl(yaml.safe_load(data))
417417

418418
return CWLClass.from_yaml(step.run)
419419

tests/cli/test_output_option.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def test_without_an_output_option(runner, client, run):
3535
cwls = []
3636
for tool_path in tools:
3737
with tool_path.open('r') as f:
38-
cwls.append(CWLClass.from_cwl(yaml.load(f)))
38+
cwls.append(CWLClass.from_cwl(yaml.safe_load(f)))
3939

4040
assert cwls[0].inputs != cwls[1].inputs
4141
assert cwls[0].outputs != cwls[1].outputs
@@ -55,7 +55,7 @@ def test_with_an_output_option(runner, client, run):
5555
cwls = []
5656
for tool_path in tools:
5757
with tool_path.open('r') as f:
58-
cwls.append(CWLClass.from_cwl(yaml.load(f)))
58+
cwls.append(CWLClass.from_cwl(yaml.safe_load(f)))
5959

6060
assert cwls[0].inputs == cwls[1].inputs
6161
assert cwls[0].outputs == cwls[1].outputs
@@ -79,7 +79,7 @@ def test_output_directory_with_output_option(runner, client, run):
7979
cwls = []
8080
for tool_path in tools:
8181
with tool_path.open('r') as f:
82-
cwls.append(CWLClass.from_cwl(yaml.load(f)))
82+
cwls.append(CWLClass.from_cwl(yaml.safe_load(f)))
8383

8484
assert cwls[0].inputs != cwls[1].inputs
8585
assert cwls[0].outputs != cwls[1].outputs
@@ -107,7 +107,7 @@ def test_output_directory_without_separate_outputs(runner, client, run):
107107
assert 1 == len(tools)
108108

109109
with tools[0].open('r') as f:
110-
cwl = CWLClass.from_cwl(yaml.load(f))
110+
cwl = CWLClass.from_cwl(yaml.safe_load(f))
111111

112112
assert 1 == len(cwl.outputs)
113113
assert 'Directory' == cwl.outputs[0].type

tests/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def test_workflow(runner, project):
173173
assert result.exit_code == 0
174174

175175
with open('workflow.cwl', 'r') as f:
176-
workflow = Workflow.from_cwl(yaml.load(f))
176+
workflow = Workflow.from_cwl(yaml.safe_load(f))
177177
assert workflow.steps[0].run.startswith('.renku/workflow/')
178178

179179
# Compare default log and log for a specific file.
@@ -627,7 +627,7 @@ def test_modified_tool(runner, project, run):
627627

628628
tool_path = tools[0]
629629
with tool_path.open('r') as f:
630-
command_line_tool = CWLClass.from_cwl(yaml.load(f))
630+
command_line_tool = CWLClass.from_cwl(yaml.safe_load(f))
631631

632632
# Simulate a manual edit.
633633
command_line_tool.inputs[0].default = 'ahoj'

0 commit comments

Comments
 (0)