Skip to content

switch to ruamel.yaml, use C loader if available, only load safely #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions cwltool/cwltest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import sys
import shutil
import tempfile
import yaml
import yaml.scanner
import ruamel.yaml as yaml
try:
from ruamel.yaml import CSafeLoader as SafeLoader
except ImportError:
from ruamel.yaml import SafeLoader

import pipes
import logging
import schema_salad.ref_resolver
Expand Down Expand Up @@ -86,7 +90,7 @@ def run_test(args, i, t): # type: (argparse.Namespace, Any, Dict[str,str]) -> i
t["job"]]

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

with open(args.test) as f:
tests = yaml.load(f)
tests = yaml.load(f, Loader=SafeLoader)

failures = 0
unsupported = 0
Expand Down
8 changes: 6 additions & 2 deletions cwltool/draft2tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import os
from .pathmapper import PathMapper, DockerPathMapper
from .job import CommandLineJob
import yaml
import ruamel.yaml as yaml
try:
from ruamel.yaml import CSafeLoader as SafeLoader
except ImportError:
from ruamel.yaml import SafeLoader
import glob
import logging
import hashlib
Expand Down Expand Up @@ -242,7 +246,7 @@ def collect_output_ports(self, ports, builder, outdir):
custom_output = os.path.join(outdir, "cwl.output.json")
if builder.fs_access.exists(custom_output):
with builder.fs_access.open(custom_output, "r") as f:
ret = yaml.load(f)
ret = yaml.load(f, Loader=SafeLoader)
_logger.debug(u"Raw output from %s: %s", custom_output, json.dumps(ret, indent=4))
adjustFileObjs(ret, remove_hostfs)
adjustFileObjs(ret,
Expand Down
1 change: 0 additions & 1 deletion cwltool/expression.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import logging
import os
from .errors import WorkflowException
import yaml
import schema_salad.validate as validate
import schema_salad.ref_resolver
from . import sandboxjs
Expand Down
1 change: 0 additions & 1 deletion cwltool/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import tempfile
import glob
import json
import yaml
import logging
import sys
import requests
Expand Down
8 changes: 6 additions & 2 deletions cwltool/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@
import tempfile
import schema_salad.jsonld_context
import schema_salad.makedoc
import yaml
import ruamel.yaml as yaml
try:
from ruamel.yaml import CSafeLoader as SafeLoader
except ImportError:
from ruamel.yaml import SafeLoader
import urlparse
from . import process
from . import job
Expand Down Expand Up @@ -413,7 +417,7 @@ def load_job_order(args, t, parser, stdin, print_input_deps=False, relative_deps
if len(args.job_order) == 1 and args.job_order[0][0] != "-":
job_order_file = args.job_order[0]
elif len(args.job_order) == 1 and args.job_order[0] == "-":
job_order_object = yaml.load(stdin)
job_order_object = yaml.load(stdin, Loader=SafeLoader)
job_order_object, _ = loader.resolve_all(job_order_object, "")
else:
job_order_file = None
Expand Down
1 change: 0 additions & 1 deletion cwltool/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import json
import schema_salad.validate as validate
import copy
import yaml
import copy
import logging
import pprint
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'schemas/draft-3/salad/schema_salad/metaschema/*.md']},
install_requires=[
'requests',
'PyYAML',
'ruamel.yaml',
'rdflib >= 4.1.0',
'rdflib-jsonld >= 0.3.0',
'shellescape',
Expand Down