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 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/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 0ede74db5..cc425ad08 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 = getattr(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 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() 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 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__': 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