py3: read in raw data files as binary

Not specifying the mode means it will be open in text mode which can
munge linebreaks on some platforms and yields the wrong type of string
on py3.
This commit is contained in:
Eli Schwartz 2019-07-25 00:35:57 -04:00
parent d50a6ddc1b
commit d01e441905
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
3 changed files with 3 additions and 3 deletions

View File

@ -937,7 +937,7 @@ class EditMetadataAction(InterfaceAction):
if old != prefs['read_file_metadata']:
prefs['read_file_metadata'] = old
if mi.cover and os.access(mi.cover, os.R_OK):
with open(mi.cover) as f:
with open(mi.cover, 'rb') as f:
cdata = f.read()
elif mi.cover_data[1] is not None:
cdata = mi.cover_data[1]

View File

@ -461,7 +461,7 @@ class MetadataSingleDialogBase(QDialog):
return
cdata = None
if mi.cover and os.access(mi.cover, os.R_OK):
with open(mi.cover) as f:
with open(mi.cover, 'rb') as f:
cdata = f.read()
elif mi.cover_data[1] is not None:
cdata = mi.cover_data[1]

View File

@ -148,7 +148,7 @@ def load_winfonts():
def test_ttf_reading():
for arg in sys.argv[1:]:
with open(arg) as f:
with open(arg, 'rb') as f:
raw = f.read()
print(os.path.basename(arg))
get_font_characteristics(raw)