mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Dedup code in image.open
This commit is contained in:
parent
525f47a64f
commit
9cbbab2da5
25
PIL/Image.py
25
PIL/Image.py
|
@ -2299,19 +2299,7 @@ def open(fp, mode="r"):
|
|||
|
||||
preinit()
|
||||
|
||||
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)
|
||||
|
||||
if init():
|
||||
|
||||
def _open_core(fp, filename, prefix):
|
||||
for i in ID:
|
||||
try:
|
||||
factory, accept = OPEN[i]
|
||||
|
@ -2322,11 +2310,20 @@ def open(fp, mode="r"):
|
|||
return im
|
||||
except (SyntaxError, IndexError, TypeError, struct.error):
|
||||
logger.debug("", exc_info=True)
|
||||
return None
|
||||
|
||||
im = _open_core(fp, filename, prefix)
|
||||
|
||||
if im is None:
|
||||
if init():
|
||||
im = _open_core(fp, filename, prefix)
|
||||
|
||||
if im:
|
||||
return im
|
||||
|
||||
raise IOError("cannot identify image file %r"
|
||||
% (filename if filename else fp))
|
||||
|
||||
|
||||
#
|
||||
# Image processing.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user