Skip to content

Commit 6e0c04f

Browse files
committed
switch to ruamel.yaml, use C loader if available, only load safely (#63)
1 parent c22c762 commit 6e0c04f

File tree

7 files changed

+21
-12
lines changed

7 files changed

+21
-12
lines changed

cwltool/cwltest.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
import sys
88
import shutil
99
import tempfile
10-
import yaml
11-
import yaml.scanner
10+
import ruamel.yaml as yaml
11+
try:
12+
from ruamel.yaml import CSafeLoader as SafeLoader
13+
except ImportError:
14+
from ruamel.yaml import SafeLoader
15+
1216
import pipes
1317
import logging
1418
import schema_salad.ref_resolver
@@ -86,7 +90,7 @@ def run_test(args, i, t): # type: (argparse.Namespace, Any, Dict[str,str]) -> i
8690
t["job"]]
8791

8892
outstr = subprocess.check_output(test_command)
89-
out = yaml.load(outstr)
93+
out = yaml.load(outstr, Loader=SafeLoader)
9094
if not isinstance(out, dict):
9195
raise ValueError("Non-dict value parsed from output string.")
9296
except ValueError as v:
@@ -155,7 +159,7 @@ def main(): # type: () -> int
155159
return 1
156160

157161
with open(args.test) as f:
158-
tests = yaml.load(f)
162+
tests = yaml.load(f, Loader=SafeLoader)
159163

160164
failures = 0
161165
unsupported = 0

cwltool/draft2tool.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
import os
77
from .pathmapper import PathMapper, DockerPathMapper
88
from .job import CommandLineJob
9-
import yaml
9+
import ruamel.yaml as yaml
10+
try:
11+
from ruamel.yaml import CSafeLoader as SafeLoader
12+
except ImportError:
13+
from ruamel.yaml import SafeLoader
1014
import glob
1115
import logging
1216
import hashlib
@@ -298,7 +302,7 @@ def collect_output_ports(self, ports, builder, outdir):
298302
custom_output = os.path.join(outdir, "cwl.output.json")
299303
if builder.fs_access.exists(custom_output):
300304
with builder.fs_access.open(custom_output, "r") as f:
301-
ret = yaml.load(f)
305+
ret = yaml.load(f, Loader=SafeLoader)
302306
_logger.debug(u"Raw output from %s: %s", custom_output, json.dumps(ret, indent=4))
303307
adjustFileObjs(ret, remove_hostfs)
304308
adjustFileObjs(ret,

cwltool/expression.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import logging
66
import os
77
from .errors import WorkflowException
8-
import yaml
98
import schema_salad.validate as validate
109
import schema_salad.ref_resolver
1110
from . import sandboxjs

cwltool/job.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import tempfile
55
import glob
66
import json
7-
import yaml
87
import logging
98
import sys
109
import requests

cwltool/main.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
import tempfile
1414
import schema_salad.jsonld_context
1515
import schema_salad.makedoc
16-
import yaml
16+
import ruamel.yaml as yaml
17+
try:
18+
from ruamel.yaml import CSafeLoader as SafeLoader
19+
except ImportError:
20+
from ruamel.yaml import SafeLoader
1721
import urlparse
1822
from . import process
1923
from . import job
@@ -419,7 +423,7 @@ def load_job_order(args, t, parser, stdin, print_input_deps=False, relative_deps
419423
if len(args.job_order) == 1 and args.job_order[0][0] != "-":
420424
job_order_file = args.job_order[0]
421425
elif len(args.job_order) == 1 and args.job_order[0] == "-":
422-
job_order_object = yaml.load(stdin)
426+
job_order_object = yaml.load(stdin, Loader=SafeLoader)
423427
job_order_object, _ = loader.resolve_all(job_order_object, "")
424428
else:
425429
job_order_file = None

cwltool/process.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import json
55
import schema_salad.validate as validate
66
import copy
7-
import yaml
87
import copy
98
import logging
109
import pprint

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
'schemas/draft-3/salad/schema_salad/metaschema/*.md']},
3333
install_requires=[
3434
'requests',
35-
'PyYAML',
35+
'ruamel.yaml',
3636
'rdflib >= 4.1.0',
3737
'rdflib-jsonld >= 0.3.0',
3838
'shellescape',

0 commit comments

Comments
 (0)