mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-26 08:40:36 +03:00
Merge pull request #2525 from joshblum/fix-unboundlocalerror
Raise TypeError and not also UnboundLocalError in ImageFile.Parser()
This commit is contained in:
commit
3bd86b9f51
|
@ -380,11 +380,8 @@ class Parser(object):
|
||||||
|
|
||||||
# attempt to open this file
|
# attempt to open this file
|
||||||
try:
|
try:
|
||||||
try:
|
with io.BytesIO(self.data) as fp:
|
||||||
fp = io.BytesIO(self.data)
|
|
||||||
im = Image.open(fp)
|
im = Image.open(fp)
|
||||||
finally:
|
|
||||||
fp.close() # explicitly close the virtual file
|
|
||||||
except IOError:
|
except IOError:
|
||||||
# traceback.print_exc()
|
# traceback.print_exc()
|
||||||
pass # not enough data
|
pass # not enough data
|
||||||
|
@ -432,12 +429,11 @@ class Parser(object):
|
||||||
if self.data:
|
if self.data:
|
||||||
# incremental parsing not possible; reopen the file
|
# incremental parsing not possible; reopen the file
|
||||||
# not that we have all data
|
# not that we have all data
|
||||||
|
with io.BytesIO(self.data) as fp:
|
||||||
try:
|
try:
|
||||||
fp = io.BytesIO(self.data)
|
|
||||||
self.image = Image.open(fp)
|
self.image = Image.open(fp)
|
||||||
finally:
|
finally:
|
||||||
self.image.load()
|
self.image.load()
|
||||||
fp.close() # explicitly close the virtual file
|
|
||||||
return self.image
|
return self.image
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,11 @@ class TestImageFile(PillowTestCase):
|
||||||
def test_raise_ioerror(self):
|
def test_raise_ioerror(self):
|
||||||
self.assertRaises(IOError, lambda: ImageFile.raise_ioerror(1))
|
self.assertRaises(IOError, lambda: ImageFile.raise_ioerror(1))
|
||||||
|
|
||||||
|
def test_raise_typeerror(self):
|
||||||
|
with self.assertRaises(TypeError):
|
||||||
|
parser = ImageFile.Parser()
|
||||||
|
parser.feed(1)
|
||||||
|
|
||||||
def test_truncated_with_errors(self):
|
def test_truncated_with_errors(self):
|
||||||
if "zip_encoder" not in codecs:
|
if "zip_encoder" not in codecs:
|
||||||
self.skipTest("PNG (zlib) encoder not available")
|
self.skipTest("PNG (zlib) encoder not available")
|
||||||
|
|
Loading…
Reference in New Issue
Block a user