Dedup code in image.open

This commit is contained in:
wiredfool 2015-09-10 07:03:24 -07:00
parent 525f47a64f
commit 9cbbab2da5

View File

@ -2299,6 +2299,7 @@ def open(fp, mode="r"):
preinit() preinit()
def _open_core(fp, filename, prefix):
for i in ID: for i in ID:
try: try:
factory, accept = OPEN[i] factory, accept = OPEN[i]
@ -2309,24 +2310,20 @@ def open(fp, mode="r"):
return im return im
except (SyntaxError, IndexError, TypeError, struct.error): except (SyntaxError, IndexError, TypeError, struct.error):
logger.debug("", exc_info=True) logger.debug("", exc_info=True)
return None
im = _open_core(fp, filename, prefix)
if im is None:
if init(): if init():
im = _open_core(fp, filename, prefix)
for i in ID: if im:
try:
factory, accept = OPEN[i]
if not accept or accept(prefix):
fp.seek(0)
im = factory(fp, filename)
_decompression_bomb_check(im.size)
return im return im
except (SyntaxError, IndexError, TypeError, struct.error):
logger.debug("", exc_info=True)
raise IOError("cannot identify image file %r" raise IOError("cannot identify image file %r"
% (filename if filename else fp)) % (filename if filename else fp))
# #
# Image processing. # Image processing.