Merge pull request #6017 from docker/6015-utf8-bom

Better support for UTF8+bom Compose files
This commit is contained in:
Joffrey F 2018-06-18 17:05:56 -07:00 committed by GitHub
commit 429b1c8b3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 3 deletions

View File

@ -1436,15 +1436,15 @@ def has_uppercase(name):
return any(char in string.ascii_uppercase for char in name)
def load_yaml(filename, encoding=None):
def load_yaml(filename, encoding=None, binary=True):
try:
with io.open(filename, 'r', encoding=encoding) as fh:
with io.open(filename, 'rb' if binary else 'r', encoding=encoding) as fh:
return yaml.safe_load(fh)
except (IOError, yaml.YAMLError, UnicodeDecodeError) as e:
if encoding is None:
# Sometimes the user's locale sets an encoding that doesn't match
# the YAML files. Im such cases, retry once with the "default"
# UTF-8 encoding
return load_yaml(filename, encoding='utf-8')
return load_yaml(filename, encoding='utf-8-sig', binary=False)
error_name = getattr(e, '__module__', '') + '.' + e.__class__.__name__
raise ConfigurationError(u"{}: {}".format(error_name, e))