mirror of https://github.com/docker/compose.git
Better support for UTF8+bom Compose files
Signed-off-by: Joffrey F <joffrey@docker.com>
This commit is contained in:
parent
f0674be578
commit
80322cfa5b
|
@ -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))
|
||||
|
|
Loading…
Reference in New Issue