6
0
mirror of https://github.com/ChristianLight/tutor.git synced 2024-11-05 04:48:00 +00:00

Fix encoding mode for binary files

Writing binary files triggered an error:

    ValueError: binary mode doesn't take an encoding argument
This commit is contained in:
Régis Behmo 2020-11-14 12:25:21 +01:00
parent c35a0480e1
commit 6bf8bcdffe

View File

@ -228,10 +228,12 @@ def write_to(content, path):
Write some content to a path. Content can be either str or bytes.
"""
open_mode = "w"
encoding = "utf8"
if isinstance(content, bytes):
open_mode += "b"
encoding = None
utils.ensure_file_directory_exists(path)
with open(path, open_mode, encoding="utf8") as of:
with open(path, open_mode, encoding=encoding) as of:
of.write(content)