1
0
Fork 0
forked from josch/img2pdf

put read() into a different try block than open()

This commit is contained in:
Johannes 'josch' Schauer 2020-04-05 12:16:59 +02:00
parent 24b679d8e5
commit 1bb21f0c85
Signed by untrusted user: josch
GPG key ID: F2CBA5C78FBD83E1

View file

@ -1864,13 +1864,19 @@ def convert(*images, **kwargs):
# the thing doesn't have a read() function, so try if we can treat # the thing doesn't have a read() function, so try if we can treat
# it as a file name # it as a file name
try: try:
with open(img, "rb") as f: f = open(img, "rb")
rawdata = f.read()
except Exception: except Exception:
# whatever the exception is (string could contain NUL # whatever the exception is (string could contain NUL
# characters or the path could just not exist) it's not a file # characters or the path could just not exist) it's not a file
# name so we now try treating it as raw image content # name so we now try treating it as raw image content
rawdata = img rawdata = img
else:
# we are not using a "with" block here because we only want to
# catch exceptions thrown by open(). The read() may throw its
# own exceptions like MemoryError which should be handled
# differently.
rawdata = f.read()
f.close()
for ( for (
color, color,