Load YAML as binary data

This lets the YAML library itself deal with the encoding (mostly), which
should address #2456 and #2565, which have to do with `open` giving us a
system-specific encoding by default on Python 3 on Windows when the files
should have been written using UTF-8 per the YAML standard.
This commit is contained in:
Adrian Sampson 2017-05-17 10:19:18 -04:00
parent 9840964f51
commit 060041a69e

View file

@ -668,7 +668,7 @@ def load_yaml(filename):
parsed, a ConfigReadError is raised.
"""
try:
with open(filename, 'r') as f:
with open(filename, 'rb') as f:
return yaml.load(f, Loader=Loader)
except (IOError, yaml.error.YAMLError) as exc:
raise ConfigReadError(filename, exc)
@ -908,9 +908,10 @@ class Configuration(RootView):
default_source = source
break
if default_source and default_source.filename:
with open(default_source.filename, 'r') as fp:
with open(default_source.filename, 'rb') as fp:
default_data = fp.read()
yaml_out = restore_yaml_comments(yaml_out, default_data)
yaml_out = restore_yaml_comments(yaml_out,
default_data.decode('utf8'))
return yaml_out