From bef530cb091b1b3ec2eecdb11923d02b125c7401 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Mar 2017 21:06:49 +1100 Subject: [PATCH 1/8] Changed None comparison to is --- PIL/TiffImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 9dbd2d3790c..1cce43d744f 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1168,7 +1168,7 @@ def _setup(self): self.info["dpi"] = xres, yres elif resunit == 3: # dots per centimeter. convert to dpi self.info["dpi"] = xres * 2.54, yres * 2.54 - elif resunit == None: # used to default to 1, but now 2) + elif resunit is None: # used to default to 1, but now 2) self.info["dpi"] = xres, yres # For backward compatibility, we also preserve the old behavior. self.info["resolution"] = xres, yres From 1fcdf6a2db21400e63cdb46aa1c44fec5d0e5aad Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Mar 2017 21:00:04 +1100 Subject: [PATCH 2/8] Removed duplicate test --- Tests/test_file_libtiff.py | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/Tests/test_file_libtiff.py b/Tests/test_file_libtiff.py index 48b74964fed..7839c405380 100644 --- a/Tests/test_file_libtiff.py +++ b/Tests/test_file_libtiff.py @@ -564,20 +564,6 @@ def test_save_tiff_with_jpegtables(self): # Should not raise UnicodeDecodeError or anything else im.save(outfile) - def test_page_number_x_0(self): - # Issue 973 - # Test TIFF with tag 297 (Page Number) having value of 0 0. - # The first number is the current page number. - # The second is the total number of pages, zero means not available. - outfile = self.tempfile("temp.tif") - # Created by printing a page in Chrome to PDF, then: - # /usr/bin/gs -q -sDEVICE=tiffg3 -sOutputFile=total-pages-zero.tif - # -dNOPAUSE /tmp/test.pdf -c quit - infile = "Tests/images/total-pages-zero.tif" - im = Image.open(infile) - # Should not divide by zero - im.save(outfile) - if __name__ == '__main__': unittest.main() From 18fea70b51b27d98a7c0bd16a6025cf872273b0d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Mar 2017 21:05:41 +1100 Subject: [PATCH 3/8] Removed unused variable --- Tests/test_imagecms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index a661ab24d0f..d0168b141e5 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -343,7 +343,7 @@ def create_test_image(): ] chans = [] bands = ImageMode.getmode(mode).bands - for band_ndx, band in enumerate(bands): + for band_ndx in range(len(bands)): channel_type = 'L' # 8-bit unorm channel_pattern = hopper(channel_type) From 4a6e8d7e92214964121c658325887b5855dfd786 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Mar 2017 21:27:16 +1100 Subject: [PATCH 4/8] Removed unnecessary pass --- Tests/test_imagesequence.py | 1 - 1 file changed, 1 deletion(-) diff --git a/Tests/test_imagesequence.py b/Tests/test_imagesequence.py index 0877bfb8a63..c2d62f38c88 100644 --- a/Tests/test_imagesequence.py +++ b/Tests/test_imagesequence.py @@ -58,7 +58,6 @@ def test_consecutive(self): for frame in ImageSequence.Iterator(im): if firstFrame is None: firstFrame = frame.copy() - pass for frame in ImageSequence.Iterator(im): self.assert_image_equal(frame, firstFrame) break From 24eb48e9e05f8f5cd7868772513b1cf3ca463d06 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Mar 2017 21:28:58 +1100 Subject: [PATCH 5/8] Removed unnecessary lambdas --- Tests/test_file_fitsstub.py | 2 +- Tests/test_file_hdf5stub.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_fitsstub.py b/Tests/test_file_fitsstub.py index 1bf459512e5..f875a2ce3e6 100644 --- a/Tests/test_file_fitsstub.py +++ b/Tests/test_file_fitsstub.py @@ -32,7 +32,7 @@ def test_load(self): im = Image.open(TEST_FILE) # Act / Assert: stub cannot load without an implemented handler - self.assertRaises(IOError, lambda: im.load()) + self.assertRaises(IOError, im.load) def test_save(self): # Arrange diff --git a/Tests/test_file_hdf5stub.py b/Tests/test_file_hdf5stub.py index e030001da0b..cc2b80aa2a0 100644 --- a/Tests/test_file_hdf5stub.py +++ b/Tests/test_file_hdf5stub.py @@ -32,7 +32,7 @@ def test_load(self): im = Image.open(TEST_FILE) # Act / Assert: stub cannot load without an implemented handler - self.assertRaises(IOError, lambda: im.load()) + self.assertRaises(IOError, im.load) def test_save(self): # Arrange From 0b93853fd838603d280e8449b6350ddbfae99789 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Mar 2017 21:31:58 +1100 Subject: [PATCH 6/8] Removed duplicate imports --- PIL/EpsImagePlugin.py | 1 - Tests/helper.py | 3 --- Tests/test_file_gif.py | 4 +--- 3 files changed, 1 insertion(+), 7 deletions(-) diff --git a/PIL/EpsImagePlugin.py b/PIL/EpsImagePlugin.py index 56b115f3086..6c4d77b19e3 100644 --- a/PIL/EpsImagePlugin.py +++ b/PIL/EpsImagePlugin.py @@ -84,7 +84,6 @@ def Ghostscript(tile, size, fp, scale=1): float((72.0 * size[1]) / (bbox[3]-bbox[1]))) # print("Ghostscript", scale, size, orig_size, bbox, orig_bbox, res) - import os import subprocess import tempfile diff --git a/Tests/helper.py b/Tests/helper.py index cbfad6f0313..e6e5eee79d0 100644 --- a/Tests/helper.py +++ b/Tests/helper.py @@ -167,7 +167,6 @@ def open_withImagemagick(self, f): outfile = self.tempfile("temp.png") if command_succeeds([IMCONVERT, f, outfile]): - from PIL import Image return Image.open(outfile) raise IOError() @@ -179,7 +178,6 @@ def open_withImagemagick(self, f): def fromstring(data): from io import BytesIO - from PIL import Image return Image.open(BytesIO(data)) @@ -191,7 +189,6 @@ def tostring(im, string_format, **options): def hopper(mode=None, cache={}): - from PIL import Image if mode is None: # Always return fresh not-yet-loaded version of image. # Operations on not-yet-loaded images is separate class of errors diff --git a/Tests/test_file_gif.py b/Tests/test_file_gif.py index d987f685119..7b01bcbd32b 100644 --- a/Tests/test_file_gif.py +++ b/Tests/test_file_gif.py @@ -90,8 +90,6 @@ def check(colors, size, expected_palette_length): check(256, 511, 256) def test_optimize_full_l(self): - from io import BytesIO - im = Image.frombytes("L", (16, 16), bytes(bytearray(range(256)))) test_file = BytesIO() im.save(test_file, "GIF", optimize=True) @@ -425,7 +423,7 @@ def test_transparent_optimize(self): reloaded = Image.open(out) self.assertEqual(reloaded.info['transparency'], 253) - + if __name__ == '__main__': unittest.main() From 798fde57cac7f56d3f49183e106f8a518d71a729 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Mar 2017 21:32:31 +1100 Subject: [PATCH 7/8] Removed unused imports --- PIL/EpsImagePlugin.py | 2 +- PIL/GifImagePlugin.py | 1 - PIL/JpegImagePlugin.py | 2 +- PIL/PngImagePlugin.py | 2 +- PIL/TgaImagePlugin.py | 2 +- Tests/test_file_jpeg.py | 8 ++++---- Tests/test_file_wmf.py | 1 - 7 files changed, 8 insertions(+), 10 deletions(-) diff --git a/PIL/EpsImagePlugin.py b/PIL/EpsImagePlugin.py index 6c4d77b19e3..cce70880a04 100644 --- a/PIL/EpsImagePlugin.py +++ b/PIL/EpsImagePlugin.py @@ -25,7 +25,7 @@ import os import sys from . import Image, ImageFile -from ._binary import i32le as i32, o32le as o32 +from ._binary import i32le as i32 __version__ = "0.5" diff --git a/PIL/GifImagePlugin.py b/PIL/GifImagePlugin.py index 7fe662fc6d1..a0d38f7d6be 100644 --- a/PIL/GifImagePlugin.py +++ b/PIL/GifImagePlugin.py @@ -508,7 +508,6 @@ def _save_netpbm(im, fp, filename): import os from subprocess import Popen, check_call, PIPE, CalledProcessError - import tempfile file = im._dump() with open(filename, 'wb') as f: diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index f01885b6093..7a29d8bffe4 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -39,7 +39,7 @@ import io import warnings from . import Image, ImageFile, TiffImagePlugin -from ._binary import i8, o8, i16be as i16, i32be as i32 +from ._binary import i8, o8, i16be as i16 from .JpegPresets import presets from ._util import isStringType diff --git a/PIL/PngImagePlugin.py b/PIL/PngImagePlugin.py index defbe54afd5..5e5eb14c735 100644 --- a/PIL/PngImagePlugin.py +++ b/PIL/PngImagePlugin.py @@ -37,7 +37,7 @@ import struct from . import Image, ImageFile, ImagePalette -from ._binary import i8, i16be as i16, i32be as i32, o8, o16be as o16, o32be as o32 +from ._binary import i8, i16be as i16, i32be as i32, o16be as o16, o32be as o32 __version__ = "0.9" diff --git a/PIL/TgaImagePlugin.py b/PIL/TgaImagePlugin.py index de2844339d7..0bc52529a54 100644 --- a/PIL/TgaImagePlugin.py +++ b/PIL/TgaImagePlugin.py @@ -18,7 +18,7 @@ from . import Image, ImageFile, ImagePalette -from ._binary import i8, i16le as i16, o8, o16le as o16, o32le as o32 +from ._binary import i8, i16le as i16, o8, o16le as o16 __version__ = "0.3" diff --git a/Tests/test_file_jpeg.py b/Tests/test_file_jpeg.py index b703598c53b..f90a29162f9 100644 --- a/Tests/test_file_jpeg.py +++ b/Tests/test_file_jpeg.py @@ -1,4 +1,4 @@ -from helper import unittest, PillowTestCase, hopper, py3 +from helper import unittest, PillowTestCase, hopper from helper import djpeg_available, cjpeg_available from io import BytesIO @@ -32,11 +32,11 @@ def gen_random_image(self, size, mode='RGB'): """ Generates a very hard to compress file :param size: tuple :param mode: optional image mode - + """ return Image.frombytes(mode, size, os.urandom(size[0]*size[1]*len(mode))) - + def test_sanity(self): # internal version number @@ -176,7 +176,7 @@ def test_progressive_cmyk_buffer(self): f = BytesIO() im = self.gen_random_image((256,256), 'CMYK') im.save(f, format='JPEG', progressive=True, quality=94) - + def test_large_exif(self): # https://github.com/python-pillow/Pillow/issues/148 f = self.tempfile('temp.jpg') diff --git a/Tests/test_file_wmf.py b/Tests/test_file_wmf.py index 9f2f893cbea..2da74cc13b0 100644 --- a/Tests/test_file_wmf.py +++ b/Tests/test_file_wmf.py @@ -1,6 +1,5 @@ from helper import unittest, PillowTestCase from PIL import Image -from io import BytesIO class TestFileWmf(PillowTestCase): From 7467d1e010feb1ad19bf49d1ba1d487ed13c068e Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Fri, 3 Mar 2017 21:57:30 +1100 Subject: [PATCH 8/8] Changed comment to be 80 characters or less --- PIL/SunImagePlugin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/PIL/SunImagePlugin.py b/PIL/SunImagePlugin.py index eb25caffcb5..b57883df62c 100644 --- a/PIL/SunImagePlugin.py +++ b/PIL/SunImagePlugin.py @@ -37,7 +37,8 @@ class SunImageFile(ImageFile.ImageFile): def _open(self): - # The Sun Raster file header is 32 bytes in length and has the following format: + # The Sun Raster file header is 32 bytes in length + # and has the following format: # typedef struct _SunRaster # {