Skip to content

Commit 060041a

Browse files
committed
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.
1 parent 9840964 commit 060041a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

beets/util/confit.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,7 @@ def load_yaml(filename):
668668
parsed, a ConfigReadError is raised.
669669
"""
670670
try:
671-
with open(filename, 'r') as f:
671+
with open(filename, 'rb') as f:
672672
return yaml.load(f, Loader=Loader)
673673
except (IOError, yaml.error.YAMLError) as exc:
674674
raise ConfigReadError(filename, exc)
@@ -908,9 +908,10 @@ def dump(self, full=True, redact=False):
908908
default_source = source
909909
break
910910
if default_source and default_source.filename:
911-
with open(default_source.filename, 'r') as fp:
911+
with open(default_source.filename, 'rb') as fp:
912912
default_data = fp.read()
913-
yaml_out = restore_yaml_comments(yaml_out, default_data)
913+
yaml_out = restore_yaml_comments(yaml_out,
914+
default_data.decode('utf8'))
914915

915916
return yaml_out
916917

0 commit comments

Comments
 (0)