From 26bcc443d1c289ce9702fa6c853958f68e7b8142 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 27 May 2015 09:15:45 +1000 Subject: [PATCH 1/3] Specified exception types --- PIL/Image.py | 2 +- PIL/ImageDraw.py | 2 +- Tests/test_cffi.py | 8 ++++---- Tests/test_file_eps.py | 2 +- Tests/test_file_webp_lossless.py | 2 +- Tests/test_file_webp_metadata.py | 2 +- Tests/test_imageqt.py | 6 +++--- Tests/test_scipy.py | 2 +- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/PIL/Image.py b/PIL/Image.py index 1c95bfca0..d246db53c 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -121,7 +121,7 @@ USE_CFFI_ACCESS = hasattr(sys, 'pypy_version_info') try: import cffi HAS_CFFI = True -except: +except ImportError: HAS_CFFI = False diff --git a/PIL/ImageDraw.py b/PIL/ImageDraw.py index 1fc5b4d61..18f9c0c00 100644 --- a/PIL/ImageDraw.py +++ b/PIL/ImageDraw.py @@ -301,7 +301,7 @@ def Draw(im, mode=None): # experimental access to the outline API try: Outline = Image.core.outline -except: +except AttributeError: Outline = None diff --git a/Tests/test_cffi.py b/Tests/test_cffi.py index 5d5427685..cea0db093 100644 --- a/Tests/test_cffi.py +++ b/Tests/test_cffi.py @@ -3,7 +3,7 @@ from helper import unittest, PillowTestCase, hopper try: import cffi from PIL import PyAccess -except: +except ImportError: # Skip in setUp() pass @@ -20,7 +20,7 @@ class TestCffiPutPixel(TestImagePutPixel): def setUp(self): try: import cffi - except: + except ImportError: self.skipTest("No cffi") def test_put(self): @@ -32,7 +32,7 @@ class TestCffiGetPixel(TestImageGetPixel): def setUp(self): try: import cffi - except: + except ImportError: self.skipTest("No cffi") def test_get(self): @@ -45,7 +45,7 @@ class TestCffi(PillowTestCase): def setUp(self): try: import cffi - except: + except ImportError: self.skipTest("No cffi") def _test_get_access(self, im): diff --git a/Tests/test_file_eps.py b/Tests/test_file_eps.py index f1fbac922..08d2d875a 100644 --- a/Tests/test_file_eps.py +++ b/Tests/test_file_eps.py @@ -159,7 +159,7 @@ class TestFileEps(PillowTestCase): # check all the freaking line endings possible try: import StringIO - except: + except ImportError: # don't skip, it skips everything in the parent test return t = StringIO.StringIO(test_string) diff --git a/Tests/test_file_webp_lossless.py b/Tests/test_file_webp_lossless.py index 52a461a74..1322e03c5 100644 --- a/Tests/test_file_webp_lossless.py +++ b/Tests/test_file_webp_lossless.py @@ -4,7 +4,7 @@ from PIL import Image try: from PIL import _webp -except: +except ImportError: pass # Skip in setUp() diff --git a/Tests/test_file_webp_metadata.py b/Tests/test_file_webp_metadata.py index 8b1254d61..06df0f82e 100644 --- a/Tests/test_file_webp_metadata.py +++ b/Tests/test_file_webp_metadata.py @@ -8,7 +8,7 @@ class TestFileWebpMetadata(PillowTestCase): def setUp(self): try: from PIL import _webp - except: + except ImportError: self.skipTest('WebP support not installed') return diff --git a/Tests/test_imageqt.py b/Tests/test_imageqt.py index 7d57ed1d2..ecab9a956 100644 --- a/Tests/test_imageqt.py +++ b/Tests/test_imageqt.py @@ -19,13 +19,13 @@ class TestImageQt(PillowTestCase): def setUp(self): try: from PyQt5.QtGui import QImage, qRgb, qRgba - except: + except ImportError: try: from PyQt4.QtGui import QImage, qRgb, qRgba - except: + except ImportError: try: from PySide.QtGui import QImage, qRgb, qRgba - except: + except ImportError: self.skipTest('PyQt4 or 5 or PySide not installed') def test_rgb(self): diff --git a/Tests/test_scipy.py b/Tests/test_scipy.py index 60f1a1b1e..1632d9475 100644 --- a/Tests/test_scipy.py +++ b/Tests/test_scipy.py @@ -6,7 +6,7 @@ try: from scipy import misc HAS_SCIPY = True -except: +except ImportError: HAS_SCIPY = False From 40c05380c54c8c2dd0e0c2dcb51f2a778c23b642 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 27 May 2015 09:18:11 +1000 Subject: [PATCH 2/3] Changed string statement to docstring --- Tests/check_jpeg_leaks.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Tests/check_jpeg_leaks.py b/Tests/check_jpeg_leaks.py index 4d13978f8..7204b1edb 100644 --- a/Tests/check_jpeg_leaks.py +++ b/Tests/check_jpeg_leaks.py @@ -105,7 +105,9 @@ post-patch: test_output = BytesIO() im.save(test_output, "JPEG", qtables=qtables) - """ + + def test_exif_leak(self): + """ pre patch: MB @@ -160,8 +162,6 @@ post patch: 0 11.33 """ - - def test_exif_leak(self): im = hopper('RGB') exif = b'12345678'*4096 From 77e28787343c80249cecb395e1333c48e15f3457 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 2 Jun 2015 00:09:18 +1000 Subject: [PATCH 3/3] Fixed redefining built-ins --- PIL/ImageFile.py | 4 ++-- PIL/ImageFont.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/PIL/ImageFile.py b/PIL/ImageFile.py index b1d261166..cc1d73f09 100644 --- a/PIL/ImageFile.py +++ b/PIL/ImageFile.py @@ -173,10 +173,10 @@ class ImageFile(Image.Image): else: # use mmap, if possible import mmap - file = open(self.filename, "r+") + fp = open(self.filename, "r+") size = os.path.getsize(self.filename) # FIXME: on Unix, use PROT_READ etc - self.map = mmap.mmap(file.fileno(), size) + self.map = mmap.mmap(fp.fileno(), size) self.im = Image.core.map_buffer( self.map, self.size, d, e, o, a ) diff --git a/PIL/ImageFont.py b/PIL/ImageFont.py index c6e7cb4d9..e3fb6f503 100644 --- a/PIL/ImageFont.py +++ b/PIL/ImageFont.py @@ -67,7 +67,7 @@ class ImageFont(object): def _load_pilfont(self, filename): - file = open(filename, "rb") + fp = open(filename, "rb") for ext in (".png", ".gif", ".pbm"): try: @@ -83,7 +83,7 @@ class ImageFont(object): self.file = fullname - return self._load_pilfont_data(file, image) + return self._load_pilfont_data(fp, image) def _load_pilfont_data(self, file, image):