From 060041a69e4646b87dec85e0125f6d8a41648152 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Wed, 17 May 2017 10:19:18 -0400 Subject: [PATCH] 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. --- beets/util/confit.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/beets/util/confit.py b/beets/util/confit.py index 373e05ffc..73ae97abc 100644 --- a/beets/util/confit.py +++ b/beets/util/confit.py @@ -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