From 63ae7fbfe998558c0b4354ec665f954ffae870f2 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 10 May 2016 22:20:49 +1000 Subject: [PATCH 1/6] Removed unnecessary lambdas --- Tests/test_file_tiff.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_tiff.py b/Tests/test_file_tiff.py index ca0816351..22915a735 100644 --- a/Tests/test_file_tiff.py +++ b/Tests/test_file_tiff.py @@ -251,8 +251,8 @@ class TestFileTiff(PillowTestCase): filename = "Tests/images/pil136.tiff" im = Image.open(filename) - self.assert_warning(DeprecationWarning, lambda: im.tag_v2.as_dict()) - self.assert_warning(DeprecationWarning, lambda: im.tag.as_dict()) + self.assert_warning(DeprecationWarning, im.tag_v2.as_dict) + self.assert_warning(DeprecationWarning, im.tag.as_dict) def test_dict(self): # Arrange From e51061dd59d15df0cf960899bfe73cb050421689 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 10 May 2016 22:21:55 +1000 Subject: [PATCH 2/6] Used isinstance instead of comparing types --- PIL/JpegImagePlugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PIL/JpegImagePlugin.py b/PIL/JpegImagePlugin.py index 0ed1fc73f..00026c4f7 100644 --- a/PIL/JpegImagePlugin.py +++ b/PIL/JpegImagePlugin.py @@ -399,7 +399,7 @@ def _fixup_dict(src_dict): # returns a dict with any single item tuples/lists as individual values def _fixup(value): try: - if len(value) == 1 and type(value) != type({}): + if len(value) == 1 and not isinstance(value, dict): return value[0] except: pass return value From 6de51536c42b5a294ccdc4f837dc68ffd3262e21 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 10 May 2016 22:23:23 +1000 Subject: [PATCH 3/6] Replaced mixed tabs and spaces with spaces --- Tests/test_imagepath.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Tests/test_imagepath.py b/Tests/test_imagepath.py index 0354b0fd9..03e685461 100644 --- a/Tests/test_imagepath.py +++ b/Tests/test_imagepath.py @@ -66,7 +66,7 @@ class TestImagePath(PillowTestCase): try: # post patch, this fails with a memory error x = evil() - + # This fails due to the invalid malloc above, # and segfaults for i in range(200000): @@ -85,15 +85,15 @@ class TestImagePath(PillowTestCase): class evil: - def __init__(self): - self.corrupt = Image.core.path(0x4000000000000000) + def __init__(self): + self.corrupt = Image.core.path(0x4000000000000000) - def __getitem__(self, i): - x = self.corrupt[i] - return struct.pack("dd", x[0], x[1]) + def __getitem__(self, i): + x = self.corrupt[i] + return struct.pack("dd", x[0], x[1]) - def __setitem__(self, i, x): - self.corrupt[i] = struct.unpack("dd", x) + def __setitem__(self, i, x): + self.corrupt[i] = struct.unpack("dd", x) if __name__ == '__main__': From b1a528bf107507dcad2ad0f619cfbac25a3e644b Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 10 May 2016 22:31:36 +1000 Subject: [PATCH 4/6] Changed variable names to avoid redefining builtins --- PIL/TiffImagePlugin.py | 11 ++++++----- Scripts/pildriver.py | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/PIL/TiffImagePlugin.py b/PIL/TiffImagePlugin.py index 99beb0f97..ad6939c26 100644 --- a/PIL/TiffImagePlugin.py +++ b/PIL/TiffImagePlugin.py @@ -1119,18 +1119,19 @@ class TiffImageFile(ImageFile.ImageFile): if DEBUG: print("- size:", self.size) - format = self.tag_v2.get(SAMPLEFORMAT, (1,)) - if len(format) > 1 and max(format) == min(format) == 1: + sampleFormat = self.tag_v2.get(SAMPLEFORMAT, (1,)) + if (len(sampleFormat) > 1 + and max(sampleFormat) == min(sampleFormat) == 1): # SAMPLEFORMAT is properly per band, so an RGB image will # be (1,1,1). But, we don't support per band pixel types, # and anything more than one band is a uint8. So, just # take the first element. Revisit this if adding support # for more exotic images. - format = (1,) + sampleFormat = (1,) # mode: check photometric interpretation and bits per pixel key = ( - self.tag_v2.prefix, photo, format, fillorder, + self.tag_v2.prefix, photo, sampleFormat, fillorder, self.tag_v2.get(BITSPERSAMPLE, (1,)), self.tag_v2.get(EXTRASAMPLES, ()) ) @@ -1215,7 +1216,7 @@ class TiffImageFile(ImageFile.ImageFile): # https://github.com/python-pillow/Pillow/issues/279 if fillorder == 2: key = ( - self.tag_v2.prefix, photo, format, 1, + self.tag_v2.prefix, photo, sampleFormat, 1, self.tag_v2.get(BITSPERSAMPLE, (1,)), self.tag_v2.get(EXTRASAMPLES, ()) ) diff --git a/Scripts/pildriver.py b/Scripts/pildriver.py index 0ede74db5..318584ad1 100644 --- a/Scripts/pildriver.py +++ b/Scripts/pildriver.py @@ -208,9 +208,9 @@ class PILDriver(object): Process the top image with the given filter. """ from PIL import ImageFilter - filter = eval("ImageFilter." + self.do_pop().upper()) + imageFilter = eval("ImageFilter." + self.do_pop().upper()) image = self.do_pop() - self.push(image.filter(filter)) + self.push(image.filter(imageFilter)) def do_getbbox(self): """usage: getbbox From 6475530f65de141f32e46311b852ecc385a62be7 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 10 May 2016 23:07:16 +1000 Subject: [PATCH 5/6] Removed use of eval --- Scripts/enhancer.py | 2 +- Scripts/pildriver.py | 2 +- Scripts/thresholder.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Scripts/enhancer.py b/Scripts/enhancer.py index 6393c983f..bf79dfe48 100644 --- a/Scripts/enhancer.py +++ b/Scripts/enhancer.py @@ -39,7 +39,7 @@ class Enhance(Frame): s.pack() def update(self, value): - self.value = eval(value) + self.value = float(value) self.tkim.paste(self.enhancer.enhance(self.value)) # diff --git a/Scripts/pildriver.py b/Scripts/pildriver.py index 318584ad1..cc425ad08 100644 --- a/Scripts/pildriver.py +++ b/Scripts/pildriver.py @@ -208,7 +208,7 @@ class PILDriver(object): Process the top image with the given filter. """ from PIL import ImageFilter - imageFilter = eval("ImageFilter." + self.do_pop().upper()) + imageFilter = getattr(ImageFilter, self.do_pop().upper()) image = self.do_pop() self.push(image.filter(imageFilter)) diff --git a/Scripts/thresholder.py b/Scripts/thresholder.py index bfeebfa9f..50c4bbcd2 100644 --- a/Scripts/thresholder.py +++ b/Scripts/thresholder.py @@ -42,7 +42,7 @@ class UI(Frame): # self.redraw() def update_scale(self, value): - self.value = eval(value) + self.value = float(value) self.redraw() From 6bd42b8e00bf62048387d031b72eeb88030cd8bf Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 10 May 2016 22:04:11 +1000 Subject: [PATCH 6/6] Removed unused import --- profile-installed.py | 1 - 1 file changed, 1 deletion(-) diff --git a/profile-installed.py b/profile-installed.py index c319c2899..e3a04c21c 100755 --- a/profile-installed.py +++ b/profile-installed.py @@ -1,5 +1,4 @@ #!/usr/bin/env python -import nose import os import sys import glob