mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-08-09 14:54:46 +03:00
Reduce duplicate code in Image open
This commit is contained in:
parent
926a08cdb3
commit
53a966d80f
35
PIL/Image.py
35
PIL/Image.py
|
@ -2299,29 +2299,18 @@ def open(fp, mode="r"):
|
||||||
|
|
||||||
preinit()
|
preinit()
|
||||||
|
|
||||||
for i in ID:
|
for i in range(0, 2):
|
||||||
try:
|
if i == 0 or init():
|
||||||
factory, accept = OPEN[i]
|
for i in ID:
|
||||||
if not accept or accept(prefix):
|
try:
|
||||||
fp.seek(0)
|
factory, accept = OPEN[i]
|
||||||
im = factory(fp, filename)
|
if not accept or accept(prefix):
|
||||||
_decompression_bomb_check(im.size)
|
fp.seek(0)
|
||||||
return im
|
im = factory(fp, filename)
|
||||||
except (SyntaxError, IndexError, TypeError, struct.error):
|
_decompression_bomb_check(im.size)
|
||||||
logger.debug("", exc_info=True)
|
return im
|
||||||
|
except (SyntaxError, IndexError, TypeError, struct.error):
|
||||||
if init():
|
logger.debug("", exc_info=True)
|
||||||
|
|
||||||
for i in ID:
|
|
||||||
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
|
|
||||||
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))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user