mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-01 00:17:27 +03:00 
			
		
		
		
	
						commit
						86616dfc0a
					
				|  | @ -248,7 +248,7 @@ class EpsImageFile(ImageFile.ImageFile): | |||
|                         # Note: The DSC spec says that BoundingBox | ||||
|                         # fields should be integers, but some drivers | ||||
|                         # put floating point values there anyway. | ||||
|                         box = [int(float(s)) for s in v.split()] | ||||
|                         box = [int(float(i)) for i in v.split()] | ||||
|                         self.size = box[2] - box[0], box[3] - box[1] | ||||
|                         self.tile = [("eps", (0, 0) + self.size, offset, | ||||
|                                       (length, box))] | ||||
|  | @ -288,7 +288,7 @@ class EpsImageFile(ImageFile.ImageFile): | |||
| 
 | ||||
|             if s[:11] == "%ImageData:": | ||||
|                 # Encoded bitmapped image. | ||||
|                 [x, y, bi, mo, z3, z4, en, id] = s[11:].split(None, 7) | ||||
|                 x, y, bi, mo = s[11:].split(None, 7)[:4] | ||||
| 
 | ||||
|                 if int(bi) != 8: | ||||
|                     break | ||||
|  |  | |||
|  | @ -17,11 +17,6 @@ | |||
| import os | ||||
| from PIL import Image, _binary | ||||
| 
 | ||||
| try: | ||||
|     import zlib | ||||
| except ImportError: | ||||
|     zlib = None | ||||
| 
 | ||||
| WIDTH = 800 | ||||
| 
 | ||||
| 
 | ||||
|  | @ -83,7 +78,8 @@ class FontFile: | |||
|             glyph = self[i] | ||||
|             if glyph: | ||||
|                 d, dst, src, im = glyph | ||||
|                 xx, yy = src[2] - src[0], src[3] - src[1] | ||||
|                 xx = src[2] - src[0] | ||||
|                 # yy = src[3] - src[1] | ||||
|                 x0, y0 = x, y | ||||
|                 x = x + xx | ||||
|                 if x > WIDTH: | ||||
|  |  | |||
|  | @ -39,8 +39,8 @@ class GbrImageFile(ImageFile.ImageFile): | |||
| 
 | ||||
|         width = i32(self.fp.read(4)) | ||||
|         height = i32(self.fp.read(4)) | ||||
|         bytes = i32(self.fp.read(4)) | ||||
|         if width <= 0 or height <= 0 or bytes != 1: | ||||
|         color_depth = i32(self.fp.read(4)) | ||||
|         if width <= 0 or height <= 0 or color_depth != 1: | ||||
|             raise SyntaxError("not a GIMP brush") | ||||
| 
 | ||||
|         comment = self.fp.read(header_size - 20)[:-1] | ||||
|  |  | |||
|  | @ -94,7 +94,7 @@ def read_32(fobj, start_length, size): | |||
| 
 | ||||
| def read_mk(fobj, start_length, size): | ||||
|     # Alpha masks seem to be uncompressed | ||||
|     (start, length) = start_length | ||||
|     start = start_length[0] | ||||
|     fobj.seek(start) | ||||
|     pixel_size = (size[0] * size[2], size[1] * size[2]) | ||||
|     sizesq = pixel_size[0] * pixel_size[1] | ||||
|  |  | |||
|  | @ -313,7 +313,7 @@ SAVE = { | |||
| def _save(im, fp, filename, check=0): | ||||
| 
 | ||||
|     try: | ||||
|         type, rawmode = SAVE[im.mode] | ||||
|         image_type, rawmode = SAVE[im.mode] | ||||
|     except KeyError: | ||||
|         raise ValueError("Cannot save %s images as IM" % im.mode) | ||||
| 
 | ||||
|  | @ -325,7 +325,7 @@ def _save(im, fp, filename, check=0): | |||
|     if check: | ||||
|         return check | ||||
| 
 | ||||
|     fp.write(("Image type: %s image\r\n" % type).encode('ascii')) | ||||
|     fp.write(("Image type: %s image\r\n" % image_type).encode('ascii')) | ||||
|     if filename: | ||||
|         fp.write(("Name: %s\r\n" % filename).encode('ascii')) | ||||
|     fp.write(("Image size (x*y): %d*%d\r\n" % im.size).encode('ascii')) | ||||
|  |  | |||
|  | @ -322,6 +322,7 @@ class Parser: | |||
|     image = None | ||||
|     data = None | ||||
|     decoder = None | ||||
|     offset = 0 | ||||
|     finished = 0 | ||||
| 
 | ||||
|     def reset(self): | ||||
|  |  | |||
|  | @ -15,7 +15,7 @@ | |||
| # See the README file for information on usage and redistribution. | ||||
| # | ||||
| 
 | ||||
| from functools import reduce | ||||
| import functools | ||||
| 
 | ||||
| 
 | ||||
| class Filter(object): | ||||
|  | @ -43,7 +43,7 @@ class Kernel(Filter): | |||
|     def __init__(self, size, kernel, scale=None, offset=0): | ||||
|         if scale is None: | ||||
|             # default scale is sum of kernel | ||||
|             scale = reduce(lambda a, b: a+b, kernel) | ||||
|             scale = functools.reduce(lambda a, b: a+b, kernel) | ||||
|         if size[0] * size[1] != len(kernel): | ||||
|             raise ValueError("not enough coefficients in kernel") | ||||
|         self.filterargs = size, scale, offset, kernel | ||||
|  |  | |||
|  | @ -20,7 +20,7 @@ | |||
| from PIL import Image | ||||
| from PIL._util import isStringType | ||||
| import operator | ||||
| from functools import reduce | ||||
| import functools | ||||
| 
 | ||||
| 
 | ||||
| # | ||||
|  | @ -213,7 +213,7 @@ def equalize(image, mask=None): | |||
|         if len(histo) <= 1: | ||||
|             lut.extend(list(range(256))) | ||||
|         else: | ||||
|             step = (reduce(operator.add, histo) - histo[-1]) // 255 | ||||
|             step = (functools.reduce(operator.add, histo) - histo[-1]) // 255 | ||||
|             if not step: | ||||
|                 lut.extend(list(range(256))) | ||||
|             else: | ||||
|  | @ -233,7 +233,6 @@ def expand(image, border=0, fill=0): | |||
|     :param fill: Pixel fill value (a color value).  Default is 0 (black). | ||||
|     :return: An image. | ||||
|     """ | ||||
|     "Add border to image" | ||||
|     left, top, right, bottom = _border(border) | ||||
|     width = left + image.size[0] + right | ||||
|     height = top + image.size[1] + bottom | ||||
|  |  | |||
|  | @ -225,8 +225,8 @@ def load(filename): | |||
|             p = PaletteFile.PaletteFile(fp) | ||||
|             lut = p.getpalette() | ||||
|         except (SyntaxError, ValueError): | ||||
|             import traceback | ||||
|             traceback.print_exc() | ||||
|             #import traceback | ||||
|             #traceback.print_exc() | ||||
|             pass | ||||
| 
 | ||||
|     if not lut: | ||||
|  |  | |||
|  | @ -23,7 +23,7 @@ | |||
| 
 | ||||
| import math | ||||
| import operator | ||||
| from functools import reduce | ||||
| import functools | ||||
| 
 | ||||
| 
 | ||||
| class Stat: | ||||
|  | @ -71,7 +71,7 @@ class Stat: | |||
| 
 | ||||
|         v = [] | ||||
|         for i in range(0, len(self.h), 256): | ||||
|             v.append(reduce(operator.add, self.h[i:i+256])) | ||||
|             v.append(functools.reduce(operator.add, self.h[i:i+256])) | ||||
|         return v | ||||
| 
 | ||||
|     def _getsum(self): | ||||
|  | @ -79,10 +79,10 @@ class Stat: | |||
| 
 | ||||
|         v = [] | ||||
|         for i in range(0, len(self.h), 256): | ||||
|             sum = 0.0 | ||||
|             layerSum = 0.0 | ||||
|             for j in range(256): | ||||
|                 sum += j * self.h[i + j] | ||||
|             v.append(sum) | ||||
|                 layerSum += j * self.h[i + j] | ||||
|             v.append(layerSum) | ||||
|         return v | ||||
| 
 | ||||
|     def _getsum2(self): | ||||
|  |  | |||
|  | @ -222,7 +222,7 @@ def getiptcinfo(im): | |||
|                     offset += 2 | ||||
|                     # resource name (usually empty) | ||||
|                     name_len = i8(app[offset]) | ||||
|                     name = app[offset+1:offset+1+name_len] | ||||
|                     # name = app[offset+1:offset+1+name_len] | ||||
|                     offset = 1 + offset + name_len | ||||
|                     if offset & 1: | ||||
|                         offset += 1 | ||||
|  |  | |||
|  | @ -454,13 +454,13 @@ def _getmp(self): | |||
|         data = self.info["mp"] | ||||
|     except KeyError: | ||||
|         return None | ||||
|     file = io.BytesIO(data) | ||||
|     head = file.read(8) | ||||
|     file_contents = io.BytesIO(data) | ||||
|     head = file_contents.read(8) | ||||
|     endianness = '>' if head[:4] == b'\x4d\x4d\x00\x2a' else '<' | ||||
|     mp = {} | ||||
|     # process dictionary | ||||
|     info = TiffImagePlugin.ImageFileDirectory(head) | ||||
|     info.load(file) | ||||
|     info.load(file_contents) | ||||
|     for key, value in info.items(): | ||||
|         mp[key] = _fixup(value) | ||||
|     # it's an error not to have a number of images | ||||
|  |  | |||
|  | @ -21,7 +21,7 @@ __version__ = "0.1" | |||
| 
 | ||||
| 
 | ||||
| from PIL import Image, TiffImagePlugin | ||||
| from PIL.OleFileIO import * | ||||
| from PIL.OleFileIO import MAGIC, OleFileIO | ||||
| 
 | ||||
| 
 | ||||
| # | ||||
|  | @ -54,9 +54,9 @@ class MicImageFile(TiffImagePlugin.TiffImageFile): | |||
|         # best way to identify MIC files, but what the... ;-) | ||||
| 
 | ||||
|         self.images = [] | ||||
|         for file in self.ole.listdir(): | ||||
|             if file[1:] and file[0][-4:] == ".ACI" and file[1] == "Image": | ||||
|                 self.images.append(file) | ||||
|         for path in self.ole.listdir(): | ||||
|             if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image": | ||||
|                 self.images.append(path) | ||||
| 
 | ||||
|         # if we didn't find any images, this is probably not | ||||
|         # an MIC file. | ||||
|  |  | |||
|  | @ -49,10 +49,10 @@ class MspImageFile(ImageFile.ImageFile): | |||
|             raise SyntaxError("not an MSP file") | ||||
| 
 | ||||
|         # Header checksum | ||||
|         sum = 0 | ||||
|         checksum = 0 | ||||
|         for i in range(0, 32, 2): | ||||
|             sum = sum ^ i16(s[i:i+2]) | ||||
|         if sum != 0: | ||||
|             checksum = checksum ^ i16(s[i:i+2]) | ||||
|         if checksum != 0: | ||||
|             raise SyntaxError("bad MSP checksum") | ||||
| 
 | ||||
|         self.mode = "1" | ||||
|  | @ -83,10 +83,10 @@ def _save(im, fp, filename): | |||
|     header[6], header[7] = 1, 1 | ||||
|     header[8], header[9] = im.size | ||||
| 
 | ||||
|     sum = 0 | ||||
|     checksum = 0 | ||||
|     for h in header: | ||||
|         sum = sum ^ h | ||||
|     header[12] = sum  # FIXME: is this the right field? | ||||
|         checksum = checksum ^ h | ||||
|     header[12] = checksum  # FIXME: is this the right field? | ||||
| 
 | ||||
|     # header | ||||
|     for h in header: | ||||
|  |  | |||
|  | @ -360,12 +360,12 @@ WORD_CLSID = "00020900-0000-0000-C000-000000000046" | |||
| #TODO: check Excel, PPT, ... | ||||
| 
 | ||||
| #[PL]: Defect levels to classify parsing errors - see OleFileIO._raise_defect() | ||||
| DEFECT_UNSURE =    10    # a case which looks weird, but not sure it's a defect | ||||
| DEFECT_POTENTIAL = 20    # a potential defect | ||||
| DEFECT_INCORRECT = 30    # an error according to specifications, but parsing | ||||
|                          # can go on | ||||
| DEFECT_FATAL =     40    # an error which cannot be ignored, parsing is | ||||
|                          # impossible | ||||
| DEFECT_UNSURE =    10   # a case which looks weird, but not sure it's a defect | ||||
| DEFECT_POTENTIAL = 20   # a potential defect | ||||
| DEFECT_INCORRECT = 30   # an error according to specifications, but parsing | ||||
|                         # can go on | ||||
| DEFECT_FATAL =     40   # an error which cannot be ignored, parsing is | ||||
|                         # impossible | ||||
| 
 | ||||
| #[PL] add useful constants to __all__: | ||||
| for key in list(vars().keys()): | ||||
|  | @ -468,14 +468,14 @@ def _unicode(s, errors='replace'): | |||
| 
 | ||||
| 
 | ||||
| def filetime2datetime(filetime): | ||||
|         """ | ||||
|         convert FILETIME (64 bits int) to Python datetime.datetime | ||||
|         """ | ||||
|         # TODO: manage exception when microseconds is too large | ||||
|         # inspired from http://code.activestate.com/recipes/511425-filetime-to-datetime/ | ||||
|         _FILETIME_null_date = datetime.datetime(1601, 1, 1, 0, 0, 0) | ||||
|         #debug('timedelta days=%d' % (filetime//(10*1000000*3600*24))) | ||||
|         return _FILETIME_null_date + datetime.timedelta(microseconds=filetime//10) | ||||
|     """ | ||||
|     convert FILETIME (64 bits int) to Python datetime.datetime | ||||
|     """ | ||||
|     # TODO: manage exception when microseconds is too large | ||||
|     # inspired from http://code.activestate.com/recipes/511425-filetime-to-datetime/ | ||||
|     _FILETIME_null_date = datetime.datetime(1601, 1, 1, 0, 0, 0) | ||||
|     #debug('timedelta days=%d' % (filetime//(10*1000000*3600*24))) | ||||
|     return _FILETIME_null_date + datetime.timedelta(microseconds=filetime//10) | ||||
| 
 | ||||
| 
 | ||||
| #=== CLASSES ================================================================== | ||||
|  |  | |||
|  | @ -204,7 +204,7 @@ class PcfFontFile(FontFile.FontFile): | |||
|         for i in range(4): | ||||
|             bitmapSizes.append(i32(fp.read(4))) | ||||
| 
 | ||||
|         byteorder = format & 4  # non-zero => MSB | ||||
|         # byteorder = format & 4  # non-zero => MSB | ||||
|         bitorder = format & 8   # non-zero => MSB | ||||
|         padindex = format & 3 | ||||
| 
 | ||||
|  |  | |||
|  | @ -194,7 +194,7 @@ class _PyAccessI16_L(PyAccess): | |||
|         pixel = self.pixels[y][x] | ||||
|         try: | ||||
|             color = min(color, 65535) | ||||
|         except: | ||||
|         except TypeError: | ||||
|             color = min(color[0], 65535) | ||||
| 
 | ||||
|         pixel.l = color & 0xFF | ||||
|  |  | |||
|  | @ -48,7 +48,7 @@ def isInt(f): | |||
|             return 1 | ||||
|         else: | ||||
|             return 0 | ||||
|     except: | ||||
|     except ValueError: | ||||
|         return 0 | ||||
| 
 | ||||
| iforms = [1, 3, -11, -12, -21, -22] | ||||
|  | @ -173,11 +173,11 @@ class SpiderImageFile(ImageFile.ImageFile): | |||
| 
 | ||||
|     # returns a byte image after rescaling to 0..255 | ||||
|     def convert2byte(self, depth=255): | ||||
|         (min, max) = self.getextrema() | ||||
|         (minimum, maximum) = self.getextrema() | ||||
|         m = 1 | ||||
|         if max != min: | ||||
|             m = depth / (max-min) | ||||
|         b = -m * min | ||||
|         if maximum != minimum: | ||||
|             m = depth / (maximum-minimum) | ||||
|         b = -m * minimum | ||||
|         return self.point(lambda i, m=m, b=b: i * m + b).convert("L") | ||||
| 
 | ||||
|     # returns a ImageTk.PhotoImage object, after rescaling to 0..255 | ||||
|  | @ -271,7 +271,7 @@ def _save(im, fp, filename): | |||
| 
 | ||||
| def _save_spider(im, fp, filename): | ||||
|     # get the filename extension and register it with Image | ||||
|     fn, ext = os.path.splitext(filename) | ||||
|     ext = os.path.splitext(filename)[1] | ||||
|     Image.register_extension("SPIDER", ext) | ||||
|     _save(im, fp, filename) | ||||
| 
 | ||||
|  |  | |||
|  | @ -731,8 +731,8 @@ class TiffImageFile(ImageFile.ImageFile): | |||
| 
 | ||||
|         # (self._compression, (extents tuple), | ||||
|         #   0, (rawmode, self._compression, fp)) | ||||
|         ignored, extents, ignored_2, args = self.tile[0] | ||||
|         args = args + (self.ifd.offset,) | ||||
|         extents = self.tile[0][1] | ||||
|         args = self.tile[0][3] + (self.ifd.offset,) | ||||
|         decoder = Image._getdecoder(self.mode, 'libtiff', args, | ||||
|                                     self.decoderconfig) | ||||
|         try: | ||||
|  | @ -978,7 +978,7 @@ class TiffImageFile(ImageFile.ImageFile): | |||
|         # fixup palette descriptor | ||||
| 
 | ||||
|         if self.mode == "P": | ||||
|             palette = [o8(a // 256) for a in self.tag[COLORMAP]] | ||||
|             palette = [o8(b // 256) for b in self.tag[COLORMAP]] | ||||
|             self.palette = ImagePalette.raw("RGB;L", b"".join(palette)) | ||||
| # | ||||
| # -------------------------------------------------------------------- | ||||
|  |  | |||
|  | @ -8,9 +8,9 @@ | |||
| # | ||||
| 
 | ||||
| try: | ||||
|     from tkinter import * | ||||
|     from tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL | ||||
| except ImportError: | ||||
|     from Tkinter import * | ||||
|     from Tkinter import Tk, Toplevel, Frame, Label, Scale, HORIZONTAL | ||||
| 
 | ||||
| from PIL import Image, ImageTk, ImageEnhance | ||||
| import sys | ||||
|  |  | |||
|  | @ -10,9 +10,9 @@ | |||
| # | ||||
| 
 | ||||
| try: | ||||
|     from tkinter import * | ||||
|     from tkinter import Tk, Canvas, NW | ||||
| except ImportError: | ||||
|     from Tkinter import * | ||||
|     from Tkinter import Tk, Canvas, NW | ||||
| 
 | ||||
| from PIL import Image, ImageTk | ||||
| import sys | ||||
|  |  | |||
|  | @ -49,7 +49,7 @@ except getopt.error as v: | |||
|     print(v) | ||||
|     sys.exit(1) | ||||
| 
 | ||||
| format = None | ||||
| output_format = None | ||||
| convert = None | ||||
| 
 | ||||
| options = {} | ||||
|  | @ -68,7 +68,7 @@ for o, a in opt: | |||
|         sys.exit(1) | ||||
| 
 | ||||
|     elif o == "-c": | ||||
|         format = a | ||||
|         output_format = a | ||||
| 
 | ||||
|     if o == "-g": | ||||
|         convert = "L" | ||||
|  | @ -90,8 +90,8 @@ try: | |||
|     if convert and im.mode != convert: | ||||
|         im.draft(convert, im.size) | ||||
|         im = im.convert(convert) | ||||
|     if format: | ||||
|         im.save(argv[1], format, **options) | ||||
|     if output_format: | ||||
|         im.save(argv[1], output_format, **options) | ||||
|     else: | ||||
|         im.save(argv[1], **options) | ||||
| except: | ||||
|  |  | |||
|  | @ -19,7 +19,6 @@ | |||
| 
 | ||||
| from __future__ import print_function | ||||
| 
 | ||||
| import site | ||||
| import getopt | ||||
| import glob | ||||
| import sys | ||||
|  |  | |||
|  | @ -24,8 +24,8 @@ from PIL import PSDraw | |||
| letter = (1.0*72, 1.0*72, 7.5*72, 10.0*72) | ||||
| 
 | ||||
| 
 | ||||
| def description(file, image): | ||||
|     title = os.path.splitext(os.path.split(file)[1])[0] | ||||
| def description(filepath, image): | ||||
|     title = os.path.splitext(os.path.split(filepath)[1])[0] | ||||
|     format = " (%dx%d " | ||||
|     if image.format: | ||||
|         format = " (" + image.format + " %dx%d " | ||||
|  | @ -65,12 +65,12 @@ for o, a in opt: | |||
|         # printer channel | ||||
|         printer = "lpr -P%s" % a | ||||
| 
 | ||||
| for file in argv: | ||||
| for filepath in argv: | ||||
|     try: | ||||
| 
 | ||||
|         im = Image.open(file) | ||||
|         im = Image.open(filepath) | ||||
| 
 | ||||
|         title = description(file, im) | ||||
|         title = description(filepath, im) | ||||
| 
 | ||||
|         if monochrome and im.mode not in ["1", "L"]: | ||||
|             im.draft("L", im.size) | ||||
|  |  | |||
|  | @ -32,7 +32,7 @@ class UI(Frame): | |||
|         self.canvas.pack() | ||||
| 
 | ||||
|         scale = Scale(self, orient=HORIZONTAL, from_=0, to=255, | ||||
|                       resolution=1, command=self.update, length=256) | ||||
|                       resolution=1, command=self.update_scale, length=256) | ||||
|         scale.set(value) | ||||
|         scale.bind("<ButtonRelease-1>", self.redraw) | ||||
|         scale.pack() | ||||
|  | @ -41,7 +41,7 @@ class UI(Frame): | |||
|         # be too slow on some platforms) | ||||
|         # self.redraw() | ||||
| 
 | ||||
|     def update(self, value): | ||||
|     def update_scale(self, value): | ||||
|         self.value = eval(value) | ||||
| 
 | ||||
|         self.redraw() | ||||
|  |  | |||
|  | @ -7,9 +7,9 @@ | |||
| from __future__ import print_function | ||||
| 
 | ||||
| try: | ||||
|     from tkinter import * | ||||
|     from tkinter import Tk, Label | ||||
| except ImportError: | ||||
|     from Tkinter import * | ||||
|     from Tkinter import Tk, Label | ||||
| 
 | ||||
| from PIL import Image, ImageTk | ||||
| 
 | ||||
|  |  | |||
|  | @ -10,7 +10,7 @@ def bench(mode): | |||
|     get = im.im.getpixel | ||||
|     xy = 50, 50  # position shouldn't really matter | ||||
|     t0 = timeit.default_timer() | ||||
|     for i in range(1000000): | ||||
|     for _ in range(1000000): | ||||
|         get(xy) | ||||
|     print(mode, timeit.default_timer() - t0, "us") | ||||
| 
 | ||||
|  |  | |||
|  | @ -21,7 +21,7 @@ class TestJpegLeaks(PillowTestCase): | |||
|         from resource import setrlimit, RLIMIT_AS, RLIMIT_STACK | ||||
|         setrlimit(RLIMIT_STACK, (stack_size, stack_size)) | ||||
|         setrlimit(RLIMIT_AS, (mem_limit, mem_limit)) | ||||
|         for count in range(iterations): | ||||
|         for _ in range(iterations): | ||||
|             with Image.open(test_file) as im: | ||||
|                 im.load() | ||||
| 
 | ||||
|  | @ -29,13 +29,13 @@ class TestJpegLeaks(PillowTestCase): | |||
|         from resource import setrlimit, RLIMIT_AS, RLIMIT_STACK | ||||
|         setrlimit(RLIMIT_STACK, (stack_size, stack_size)) | ||||
|         setrlimit(RLIMIT_AS, (mem_limit, mem_limit)) | ||||
|         for count in range(iterations): | ||||
|         for _ in range(iterations): | ||||
|             with Image.open(test_file) as im: | ||||
|                 im.load() | ||||
|                 test_output = BytesIO() | ||||
|                 im.save(test_output, "JPEG2000") | ||||
|                 test_output.seek(0) | ||||
|                 output = test_output.read() | ||||
|                 test_output.read() | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|  |  | |||
|  | @ -1,5 +1,4 @@ | |||
| from helper import unittest, PillowTestCase, hopper | ||||
| from PIL import Image | ||||
| from io import BytesIO | ||||
| import sys | ||||
| 
 | ||||
|  | @ -102,7 +101,7 @@ post-patch: | |||
|         qtables = [standard_l_qtable, | ||||
|                    standard_chrominance_qtable] | ||||
| 
 | ||||
|         for count in range(iterations): | ||||
|         for _ in range(iterations): | ||||
|             test_output = BytesIO() | ||||
|             im.save(test_output, "JPEG", qtables=qtables) | ||||
| 
 | ||||
|  | @ -166,11 +165,12 @@ post patch: | |||
|         im = hopper('RGB') | ||||
|         exif = b'12345678'*4096 | ||||
| 
 | ||||
|         for count in range(iterations): | ||||
|         for _ in range(iterations): | ||||
|             test_output = BytesIO() | ||||
|             im.save(test_output, "JPEG", exif=exif) | ||||
| 
 | ||||
|     """ | ||||
|     def test_base_save(self): | ||||
|         """ | ||||
| base case: | ||||
|     MB | ||||
| 20.99^           :::::         :::::::::::::::::::::::::::::::::::::::::::@::: | ||||
|  | @ -196,11 +196,9 @@ base case: | |||
|    0 +----------------------------------------------------------------------->Gi | ||||
|      0                                                                   7.882 | ||||
| """ | ||||
| 
 | ||||
|     def test_base_save(self): | ||||
|         im = hopper('RGB') | ||||
| 
 | ||||
|         for count in range(iterations): | ||||
|         for _ in range(iterations): | ||||
|             test_output = BytesIO() | ||||
|             im.save(test_output, "JPEG") | ||||
| 
 | ||||
|  |  | |||
|  | @ -28,7 +28,7 @@ class TestWebPLeaks(PillowTestCase): | |||
|         with open(test_file, 'rb') as f: | ||||
|             im_data = f.read() | ||||
|         start_mem = self._get_mem_usage() | ||||
|         for count in range(iterations): | ||||
|         for _ in range(iterations): | ||||
|             with Image.open(BytesIO(im_data)) as im: | ||||
|                 im.load() | ||||
|             mem = (self._get_mem_usage() - start_mem) | ||||
|  |  | |||
|  | @ -58,10 +58,10 @@ class TestBmpReference(PillowTestCase): | |||
|                     } | ||||
| 
 | ||||
|         def get_compare(f): | ||||
|             (head, name) = os.path.split(f) | ||||
|             name = os.path.split(f)[1] | ||||
|             if name in file_map: | ||||
|                 return os.path.join(base, 'html', file_map[name]) | ||||
|             (name, ext) = os.path.splitext(name) | ||||
|             name = os.path.splitext(name)[0] | ||||
|             return os.path.join(base, 'html', "%s.png" % name) | ||||
| 
 | ||||
|         for f in self.get_files('g'): | ||||
|  |  | |||
|  | @ -49,10 +49,10 @@ class TestCffi(PillowTestCase): | |||
|             self.skipTest("No cffi") | ||||
| 
 | ||||
|     def _test_get_access(self, im): | ||||
|         """ Do we get the same thing as the old pixel access """ | ||||
|         """Do we get the same thing as the old pixel access | ||||
| 
 | ||||
|         """ Using private interfaces, forcing a capi access and | ||||
|         a pyaccess for the same image """ | ||||
|         Using private interfaces, forcing a capi access and | ||||
|         a pyaccess for the same image""" | ||||
|         caccess = im.im.pixel_access(False) | ||||
|         access = PyAccess.new(im, False) | ||||
| 
 | ||||
|  | @ -90,10 +90,10 @@ class TestCffi(PillowTestCase): | |||
|         # self._test_get_access(im) | ||||
| 
 | ||||
|     def _test_set_access(self, im, color): | ||||
|         """ Are we writing the correct bits into the image? """ | ||||
|         """Are we writing the correct bits into the image? | ||||
| 
 | ||||
|         """ Using private interfaces, forcing a capi access and | ||||
|         a pyaccess for the same image """ | ||||
|         Using private interfaces, forcing a capi access and | ||||
|         a pyaccess for the same image""" | ||||
|         caccess = im.im.pixel_access(False) | ||||
|         access = PyAccess.new(im, False) | ||||
| 
 | ||||
|  |  | |||
|  | @ -5,14 +5,14 @@ from PIL import Image | |||
| # sample ppm stream | ||||
| # created as an export of a palette image from Gimp2.6 | ||||
| # save as...-> hopper.fli, default options. | ||||
| file = "Tests/images/hopper.fli" | ||||
| data = open(file, "rb").read() | ||||
| test_file = "Tests/images/hopper.fli" | ||||
| data = open(test_file, "rb").read() | ||||
| 
 | ||||
| 
 | ||||
| class TestFileFli(PillowTestCase): | ||||
| 
 | ||||
|     def test_sanity(self): | ||||
|         im = Image.open(file) | ||||
|         im = Image.open(test_file) | ||||
|         im.load() | ||||
|         self.assertEqual(im.mode, "P") | ||||
|         self.assertEqual(im.size, (128, 128)) | ||||
|  |  | |||
|  | @ -36,9 +36,9 @@ class TestFileGif(PillowTestCase): | |||
| 
 | ||||
|         def test_bilevel(optimize): | ||||
|             im = Image.new("1", (1, 1), 0) | ||||
|             file = BytesIO() | ||||
|             im.save(file, "GIF", optimize=optimize) | ||||
|             return len(file.getvalue()) | ||||
|             test_file = BytesIO() | ||||
|             im.save(test_file, "GIF", optimize=optimize) | ||||
|             return len(test_file.getvalue()) | ||||
| 
 | ||||
|         self.assertEqual(test_grayscale(0), 800) | ||||
|         self.assertEqual(test_grayscale(1), 38) | ||||
|  | @ -49,8 +49,8 @@ class TestFileGif(PillowTestCase): | |||
|         from io import BytesIO | ||||
| 
 | ||||
|         im = Image.frombytes("L", (16, 16), bytes(bytearray(range(256)))) | ||||
|         file = BytesIO() | ||||
|         im.save(file, "GIF", optimize=True) | ||||
|         test_file = BytesIO() | ||||
|         im.save(test_file, "GIF", optimize=True) | ||||
|         self.assertEqual(im.mode, "L") | ||||
| 
 | ||||
|     def test_roundtrip(self): | ||||
|  |  | |||
|  | @ -5,8 +5,8 @@ from PIL import Image | |||
| import sys | ||||
| 
 | ||||
| # sample icon file | ||||
| file = "Tests/images/pillow.icns" | ||||
| data = open(file, "rb").read() | ||||
| test_file = "Tests/images/pillow.icns" | ||||
| data = open(test_file, "rb").read() | ||||
| 
 | ||||
| enable_jpeg2k = hasattr(Image.core, 'jp2klib_version') | ||||
| 
 | ||||
|  | @ -16,7 +16,7 @@ class TestFileIcns(PillowTestCase): | |||
|     def test_sanity(self): | ||||
|         # Loading this icon by default should result in the largest size | ||||
|         # (512x512@2x) being loaded | ||||
|         im = Image.open(file) | ||||
|         im = Image.open(test_file) | ||||
|         im.load() | ||||
|         self.assertEqual(im.mode, "RGBA") | ||||
|         self.assertEqual(im.size, (1024, 1024)) | ||||
|  | @ -39,11 +39,11 @@ class TestFileIcns(PillowTestCase): | |||
|     def test_sizes(self): | ||||
|         # Check that we can load all of the sizes, and that the final pixel | ||||
|         # dimensions are as expected | ||||
|         im = Image.open(file) | ||||
|         im = Image.open(test_file) | ||||
|         for w, h, r in im.info['sizes']: | ||||
|             wr = w * r | ||||
|             hr = h * r | ||||
|             im2 = Image.open(file) | ||||
|             im2 = Image.open(test_file) | ||||
|             im2.size = (w, h, r) | ||||
|             im2.load() | ||||
|             self.assertEqual(im2.mode, 'RGBA') | ||||
|  |  | |||
|  | @ -23,10 +23,10 @@ class TestFileJpeg(PillowTestCase): | |||
|     def roundtrip(self, im, **options): | ||||
|         out = BytesIO() | ||||
|         im.save(out, "JPEG", **options) | ||||
|         bytes = out.tell() | ||||
|         test_bytes = out.tell() | ||||
|         out.seek(0) | ||||
|         im = Image.open(out) | ||||
|         im.bytes = bytes  # for testing only | ||||
|         im.bytes = test_bytes  # for testing only | ||||
|         return im | ||||
| 
 | ||||
|     def test_sanity(self): | ||||
|  |  | |||
|  | @ -22,10 +22,10 @@ class TestFileJpeg2k(PillowTestCase): | |||
|     def roundtrip(self, im, **options): | ||||
|         out = BytesIO() | ||||
|         im.save(out, "JPEG2000", **options) | ||||
|         bytes = out.tell() | ||||
|         test_bytes = out.tell() | ||||
|         out.seek(0) | ||||
|         im = Image.open(out) | ||||
|         im.bytes = bytes  # for testing only | ||||
|         im.bytes = test_bytes  # for testing only | ||||
|         im.load() | ||||
|         return im | ||||
| 
 | ||||
|  |  | |||
|  | @ -39,22 +39,22 @@ class TestFileLibTiff(LibTiffTestCase): | |||
|     def test_g4_tiff(self): | ||||
|         """Test the ordinary file path load path""" | ||||
| 
 | ||||
|         file = "Tests/images/hopper_g4_500.tif" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/hopper_g4_500.tif" | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         self.assertEqual(im.size, (500, 500)) | ||||
|         self._assert_noerr(im) | ||||
| 
 | ||||
|     def test_g4_large(self): | ||||
|         file = "Tests/images/pport_g4.tif" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/pport_g4.tif" | ||||
|         im = Image.open(test_file) | ||||
|         self._assert_noerr(im) | ||||
| 
 | ||||
|     def test_g4_tiff_file(self): | ||||
|         """Testing the string load path""" | ||||
| 
 | ||||
|         file = "Tests/images/hopper_g4_500.tif" | ||||
|         with open(file, 'rb') as f: | ||||
|         test_file = "Tests/images/hopper_g4_500.tif" | ||||
|         with open(test_file, 'rb') as f: | ||||
|             im = Image.open(f) | ||||
| 
 | ||||
|             self.assertEqual(im.size, (500, 500)) | ||||
|  | @ -62,9 +62,9 @@ class TestFileLibTiff(LibTiffTestCase): | |||
| 
 | ||||
|     def test_g4_tiff_bytesio(self): | ||||
|         """Testing the stringio loading code path""" | ||||
|         file = "Tests/images/hopper_g4_500.tif" | ||||
|         test_file = "Tests/images/hopper_g4_500.tif" | ||||
|         s = io.BytesIO() | ||||
|         with open(file, 'rb') as f: | ||||
|         with open(test_file, 'rb') as f: | ||||
|             s.write(f.read()) | ||||
|             s.seek(0) | ||||
|         im = Image.open(s) | ||||
|  | @ -89,8 +89,8 @@ class TestFileLibTiff(LibTiffTestCase): | |||
| 
 | ||||
|     def test_g4_write(self): | ||||
|         """Checking to see that the saved image is the same as what we wrote""" | ||||
|         file = "Tests/images/hopper_g4_500.tif" | ||||
|         orig = Image.open(file) | ||||
|         test_file = "Tests/images/hopper_g4_500.tif" | ||||
|         orig = Image.open(test_file) | ||||
| 
 | ||||
|         out = self.tempfile("temp.tif") | ||||
|         rot = orig.transpose(Image.ROTATE_90) | ||||
|  | @ -108,8 +108,8 @@ class TestFileLibTiff(LibTiffTestCase): | |||
|         self.assertNotEqual(orig.tobytes(), reread.tobytes()) | ||||
| 
 | ||||
|     def test_adobe_deflate_tiff(self): | ||||
|         file = "Tests/images/tiff_adobe_deflate.tif" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/tiff_adobe_deflate.tif" | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         self.assertEqual(im.mode, "RGB") | ||||
|         self.assertEqual(im.size, (278, 374)) | ||||
|  | @ -215,8 +215,8 @@ class TestFileLibTiff(LibTiffTestCase): | |||
| 
 | ||||
|     def test_g4_string_info(self): | ||||
|         """Tests String data in info directory""" | ||||
|         file = "Tests/images/hopper_g4_500.tif" | ||||
|         orig = Image.open(file) | ||||
|         test_file = "Tests/images/hopper_g4_500.tif" | ||||
|         orig = Image.open(test_file) | ||||
| 
 | ||||
|         out = self.tempfile("temp.tif") | ||||
| 
 | ||||
|  |  | |||
|  | @ -18,8 +18,8 @@ class TestFileLibTiffSmall(LibTiffTestCase): | |||
|     def test_g4_hopper_file(self): | ||||
|         """Testing the open file load path""" | ||||
| 
 | ||||
|         file = "Tests/images/hopper_g4.tif" | ||||
|         with open(file, 'rb') as f: | ||||
|         test_file = "Tests/images/hopper_g4.tif" | ||||
|         with open(test_file, 'rb') as f: | ||||
|             im = Image.open(f) | ||||
| 
 | ||||
|             self.assertEqual(im.size, (128, 128)) | ||||
|  | @ -28,9 +28,9 @@ class TestFileLibTiffSmall(LibTiffTestCase): | |||
|     def test_g4_hopper_bytesio(self): | ||||
|         """Testing the bytesio loading code path""" | ||||
|         from io import BytesIO | ||||
|         file = "Tests/images/hopper_g4.tif" | ||||
|         test_file = "Tests/images/hopper_g4.tif" | ||||
|         s = BytesIO() | ||||
|         with open(file, 'rb') as f: | ||||
|         with open(test_file, 'rb') as f: | ||||
|             s.write(f.read()) | ||||
|             s.seek(0) | ||||
|         im = Image.open(s) | ||||
|  | @ -41,8 +41,8 @@ class TestFileLibTiffSmall(LibTiffTestCase): | |||
|     def test_g4_hopper(self): | ||||
|         """The 128x128 lena image failed for some reason.""" | ||||
| 
 | ||||
|         file = "Tests/images/hopper_g4.tif" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/hopper_g4.tif" | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         self.assertEqual(im.size, (128, 128)) | ||||
|         self._assert_noerr(im) | ||||
|  |  | |||
|  | @ -17,10 +17,10 @@ class TestFileMpo(PillowTestCase): | |||
|         # Note that for now, there is no MPO saving functionality | ||||
|         out = BytesIO() | ||||
|         im.save(out, "MPO", **options) | ||||
|         bytes = out.tell() | ||||
|         test_bytes = out.tell() | ||||
|         out.seek(0) | ||||
|         im = Image.open(out) | ||||
|         im.bytes = bytes  # for testing only | ||||
|         im.bytes = test_bytes  # for testing only | ||||
|         return im | ||||
| 
 | ||||
|     def test_sanity(self): | ||||
|  |  | |||
|  | @ -31,8 +31,8 @@ class TestFilePcx(PillowTestCase): | |||
|     def test_pil184(self): | ||||
|         # Check reading of files where xmin/xmax is not zero. | ||||
| 
 | ||||
|         file = "Tests/images/pil184.pcx" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/pil184.pcx" | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         self.assertEqual(im.size, (447, 144)) | ||||
|         self.assertEqual(im.tile[0][1], (0, 0, 447, 144)) | ||||
|  |  | |||
|  | @ -19,9 +19,9 @@ MAGIC = PngImagePlugin._MAGIC | |||
| 
 | ||||
| 
 | ||||
| def chunk(cid, *data): | ||||
|     file = BytesIO() | ||||
|     PngImagePlugin.putchunk(*(file, cid) + data) | ||||
|     return file.getvalue() | ||||
|     test_file = BytesIO() | ||||
|     PngImagePlugin.putchunk(*(test_file, cid) + data) | ||||
|     return test_file.getvalue() | ||||
| 
 | ||||
| o32 = PngImagePlugin.o32 | ||||
| 
 | ||||
|  | @ -56,37 +56,37 @@ class TestFilePng(PillowTestCase): | |||
|         self.assertRegexpMatches( | ||||
|             Image.core.zlib_version, "\d+\.\d+\.\d+(\.\d+)?$") | ||||
| 
 | ||||
|         file = self.tempfile("temp.png") | ||||
|         test_file = self.tempfile("temp.png") | ||||
| 
 | ||||
|         hopper("RGB").save(file) | ||||
|         hopper("RGB").save(test_file) | ||||
| 
 | ||||
|         im = Image.open(file) | ||||
|         im = Image.open(test_file) | ||||
|         im.load() | ||||
|         self.assertEqual(im.mode, "RGB") | ||||
|         self.assertEqual(im.size, (128, 128)) | ||||
|         self.assertEqual(im.format, "PNG") | ||||
| 
 | ||||
|         hopper("1").save(file) | ||||
|         im = Image.open(file) | ||||
|         hopper("1").save(test_file) | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         hopper("L").save(file) | ||||
|         im = Image.open(file) | ||||
|         hopper("L").save(test_file) | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         hopper("P").save(file) | ||||
|         im = Image.open(file) | ||||
|         hopper("P").save(test_file) | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         hopper("RGB").save(file) | ||||
|         im = Image.open(file) | ||||
|         hopper("RGB").save(test_file) | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         hopper("I").save(file) | ||||
|         im = Image.open(file) | ||||
|         hopper("I").save(test_file) | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|     def test_broken(self): | ||||
|         # Check reading of totally broken files.  In this case, the test | ||||
|         # file was checked into Subversion as a text file. | ||||
| 
 | ||||
|         file = "Tests/images/broken.png" | ||||
|         self.assertRaises(IOError, lambda: Image.open(file)) | ||||
|         test_file = "Tests/images/broken.png" | ||||
|         self.assertRaises(IOError, lambda: Image.open(test_file)) | ||||
| 
 | ||||
|     def test_bad_text(self): | ||||
|         # Make sure PIL can read malformed tEXt chunks (@PIL152) | ||||
|  | @ -167,16 +167,16 @@ class TestFilePng(PillowTestCase): | |||
| 
 | ||||
|     def test_interlace(self): | ||||
| 
 | ||||
|         file = "Tests/images/pil123p.png" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/pil123p.png" | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         self.assert_image(im, "P", (162, 150)) | ||||
|         self.assertTrue(im.info.get("interlace")) | ||||
| 
 | ||||
|         im.load() | ||||
| 
 | ||||
|         file = "Tests/images/pil123rgba.png" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/pil123rgba.png" | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         self.assert_image(im, "RGBA", (162, 150)) | ||||
|         self.assertTrue(im.info.get("interlace")) | ||||
|  | @ -184,8 +184,8 @@ class TestFilePng(PillowTestCase): | |||
|         im.load() | ||||
| 
 | ||||
|     def test_load_transparent_p(self): | ||||
|         file = "Tests/images/pil123p.png" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/pil123p.png" | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         self.assert_image(im, "P", (162, 150)) | ||||
|         im = im.convert("RGBA") | ||||
|  | @ -195,8 +195,8 @@ class TestFilePng(PillowTestCase): | |||
|         self.assertEqual(len(im.split()[3].getcolors()), 124) | ||||
| 
 | ||||
|     def test_load_transparent_rgb(self): | ||||
|         file = "Tests/images/rgb_trns.png" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/rgb_trns.png" | ||||
|         im = Image.open(test_file) | ||||
| 
 | ||||
|         self.assert_image(im, "RGB", (64, 64)) | ||||
|         im = im.convert("RGBA") | ||||
|  | @ -209,22 +209,22 @@ class TestFilePng(PillowTestCase): | |||
|         in_file = "Tests/images/pil123p.png" | ||||
|         im = Image.open(in_file) | ||||
| 
 | ||||
|         file = self.tempfile("temp.png") | ||||
|         im.save(file) | ||||
|         test_file = self.tempfile("temp.png") | ||||
|         im.save(test_file) | ||||
| 
 | ||||
|     def test_save_p_single_transparency(self): | ||||
|         in_file = "Tests/images/p_trns_single.png" | ||||
|         im = Image.open(in_file) | ||||
| 
 | ||||
|         file = self.tempfile("temp.png") | ||||
|         im.save(file) | ||||
|         test_file = self.tempfile("temp.png") | ||||
|         im.save(test_file) | ||||
| 
 | ||||
|     def test_save_l_transparency(self): | ||||
|         in_file = "Tests/images/l_trns.png" | ||||
|         im = Image.open(in_file) | ||||
| 
 | ||||
|         file = self.tempfile("temp.png") | ||||
|         im.save(file) | ||||
|         test_file = self.tempfile("temp.png") | ||||
|         im.save(test_file) | ||||
| 
 | ||||
|         # There are 559 transparent pixels. | ||||
|         im = im.convert('RGBA') | ||||
|  | @ -234,8 +234,8 @@ class TestFilePng(PillowTestCase): | |||
|         in_file = "Tests/images/caption_6_33_22.png" | ||||
|         im = Image.open(in_file) | ||||
| 
 | ||||
|         file = self.tempfile("temp.png") | ||||
|         im.save(file) | ||||
|         test_file = self.tempfile("temp.png") | ||||
|         im.save(test_file) | ||||
| 
 | ||||
|     def test_load_verify(self): | ||||
|         # Check open/load/verify exception (@PIL150) | ||||
|  | @ -245,7 +245,7 @@ class TestFilePng(PillowTestCase): | |||
| 
 | ||||
|         im = Image.open(TEST_PNG_FILE) | ||||
|         im.load() | ||||
|         self.assertRaises(RuntimeError, lambda: im.verify()) | ||||
|         self.assertRaises(RuntimeError, im.verify) | ||||
| 
 | ||||
|     def test_roundtrip_dpi(self): | ||||
|         # Check dpi roundtripping | ||||
|  | @ -329,8 +329,8 @@ class TestFilePng(PillowTestCase): | |||
|         # Check writing and reading of tRNS chunks for RGB images. | ||||
|         # Independent file sample provided by Sebastian Spaeth. | ||||
| 
 | ||||
|         file = "Tests/images/caption_6_33_22.png" | ||||
|         im = Image.open(file) | ||||
|         test_file = "Tests/images/caption_6_33_22.png" | ||||
|         im = Image.open(test_file) | ||||
|         self.assertEqual(im.info["transparency"], (248, 248, 248)) | ||||
| 
 | ||||
|         # check saving transparency by default | ||||
|  |  | |||
|  | @ -3,14 +3,14 @@ from helper import unittest, PillowTestCase | |||
| from PIL import Image | ||||
| 
 | ||||
| # sample ppm stream | ||||
| file = "Tests/images/hopper.ppm" | ||||
| data = open(file, "rb").read() | ||||
| test_file = "Tests/images/hopper.ppm" | ||||
| data = open(test_file, "rb").read() | ||||
| 
 | ||||
| 
 | ||||
| class TestFilePpm(PillowTestCase): | ||||
| 
 | ||||
|     def test_sanity(self): | ||||
|         im = Image.open(file) | ||||
|         im = Image.open(test_file) | ||||
|         im.load() | ||||
|         self.assertEqual(im.mode, "RGB") | ||||
|         self.assertEqual(im.size, (128, 128)) | ||||
|  |  | |||
|  | @ -3,14 +3,14 @@ from helper import unittest, PillowTestCase | |||
| from PIL import Image | ||||
| 
 | ||||
| # sample ppm stream | ||||
| file = "Tests/images/hopper.psd" | ||||
| data = open(file, "rb").read() | ||||
| test_file = "Tests/images/hopper.psd" | ||||
| data = open(test_file, "rb").read() | ||||
| 
 | ||||
| 
 | ||||
| class TestImagePsd(PillowTestCase): | ||||
| 
 | ||||
|     def test_sanity(self): | ||||
|         im = Image.open(file) | ||||
|         im = Image.open(test_file) | ||||
|         im.load() | ||||
|         self.assertEqual(im.mode, "RGB") | ||||
|         self.assertEqual(im.size, (128, 128)) | ||||
|  |  | |||
|  | @ -41,12 +41,12 @@ class TestFileWebpMetadata(PillowTestCase): | |||
|         image = Image.open(file_path) | ||||
|         expected_exif = image.info['exif'] | ||||
| 
 | ||||
|         buffer = BytesIO() | ||||
|         test_buffer = BytesIO() | ||||
| 
 | ||||
|         image.save(buffer, "webp", exif=expected_exif) | ||||
|         image.save(test_buffer, "webp", exif=expected_exif) | ||||
| 
 | ||||
|         buffer.seek(0) | ||||
|         webp_image = Image.open(buffer) | ||||
|         test_buffer.seek(0) | ||||
|         webp_image = Image.open(test_buffer) | ||||
| 
 | ||||
|         webp_exif = webp_image.info.get('exif', None) | ||||
|         self.assertTrue(webp_exif) | ||||
|  | @ -76,12 +76,12 @@ class TestFileWebpMetadata(PillowTestCase): | |||
|         image = Image.open(file_path) | ||||
|         expected_icc_profile = image.info['icc_profile'] | ||||
| 
 | ||||
|         buffer = BytesIO() | ||||
|         test_buffer = BytesIO() | ||||
| 
 | ||||
|         image.save(buffer, "webp", icc_profile=expected_icc_profile) | ||||
|         image.save(test_buffer, "webp", icc_profile=expected_icc_profile) | ||||
| 
 | ||||
|         buffer.seek(0) | ||||
|         webp_image = Image.open(buffer) | ||||
|         test_buffer.seek(0) | ||||
|         webp_image = Image.open(test_buffer) | ||||
| 
 | ||||
|         webp_icc_profile = webp_image.info.get('icc_profile', None) | ||||
| 
 | ||||
|  | @ -96,14 +96,14 @@ class TestFileWebpMetadata(PillowTestCase): | |||
| 
 | ||||
|         file_path = "Tests/images/flower.jpg" | ||||
|         image = Image.open(file_path) | ||||
|         image.info['exif'] | ||||
|         self.assertTrue('exif' in image.info) | ||||
| 
 | ||||
|         buffer = BytesIO() | ||||
|         test_buffer = BytesIO() | ||||
| 
 | ||||
|         image.save(buffer, "webp") | ||||
|         image.save(test_buffer, "webp") | ||||
| 
 | ||||
|         buffer.seek(0) | ||||
|         webp_image = Image.open(buffer) | ||||
|         test_buffer.seek(0) | ||||
|         webp_image = Image.open(test_buffer) | ||||
| 
 | ||||
|         self.assertFalse(webp_image._getexif()) | ||||
| 
 | ||||
|  |  | |||
|  | @ -9,8 +9,8 @@ class TestFontBdf(PillowTestCase): | |||
| 
 | ||||
|     def test_sanity(self): | ||||
| 
 | ||||
|         file = open(filename, "rb") | ||||
|         font = BdfFontFile.BdfFontFile(file) | ||||
|         test_file = open(filename, "rb") | ||||
|         font = BdfFontFile.BdfFontFile(test_file) | ||||
| 
 | ||||
|         self.assertIsInstance(font, FontFile.FontFile) | ||||
|         self.assertEqual(len([_f for _f in font.glyph if _f]), 190) | ||||
|  |  | |||
|  | @ -17,8 +17,8 @@ class TestFontPcf(PillowTestCase): | |||
|             self.skipTest("zlib support not available") | ||||
| 
 | ||||
|     def save_font(self): | ||||
|         file = open(fontname, "rb") | ||||
|         font = PcfFontFile.PcfFontFile(file) | ||||
|         test_file = open(fontname, "rb") | ||||
|         font = PcfFontFile.PcfFontFile(test_file) | ||||
|         self.assertIsInstance(font, FontFile.FontFile) | ||||
|         self.assertEqual(len([_f for _f in font.glyph if _f]), 192) | ||||
| 
 | ||||
|  |  | |||
|  | @ -1,7 +1,6 @@ | |||
| from helper import unittest, PillowTestCase, hopper | ||||
| 
 | ||||
| from PIL import Image | ||||
| import sys | ||||
| 
 | ||||
| 
 | ||||
| class TestImage(PillowTestCase): | ||||
|  | @ -42,8 +41,8 @@ class TestImage(PillowTestCase): | |||
|         im.paste(0, (0, 0, 100, 100)) | ||||
|         self.assertFalse(im.readonly) | ||||
| 
 | ||||
|         file = self.tempfile("temp.ppm") | ||||
|         im._dump(file) | ||||
|         test_file = self.tempfile("temp.ppm") | ||||
|         im._dump(test_file) | ||||
| 
 | ||||
|     def test_comparison_with_other_type(self): | ||||
|         # Arrange | ||||
|  |  | |||
|  | @ -76,10 +76,10 @@ class TestImageFilter(PillowTestCase): | |||
|             #   0 1 2 | ||||
|             #   3 4 5 | ||||
|             #   6 7 8 | ||||
|             min = im.filter(ImageFilter.MinFilter).getpixel((1, 1)) | ||||
|             minimum = im.filter(ImageFilter.MinFilter).getpixel((1, 1)) | ||||
|             med = im.filter(ImageFilter.MedianFilter).getpixel((1, 1)) | ||||
|             max = im.filter(ImageFilter.MaxFilter).getpixel((1, 1)) | ||||
|             return min, med, max | ||||
|             maximum = im.filter(ImageFilter.MaxFilter).getpixel((1, 1)) | ||||
|             return minimum, med, maximum | ||||
| 
 | ||||
|         self.assertEqual(rankfilter("1"), (0, 4, 8)) | ||||
|         self.assertEqual(rankfilter("L"), (0, 4, 8)) | ||||
|  |  | |||
|  | @ -18,7 +18,7 @@ class TestImageLoad(PillowTestCase): | |||
|     def test_close(self): | ||||
|         im = Image.open("Tests/images/hopper.gif") | ||||
|         im.close() | ||||
|         self.assertRaises(ValueError, lambda: im.load()) | ||||
|         self.assertRaises(ValueError, im.load) | ||||
|         self.assertRaises(ValueError, lambda: im.getpixel((0, 0))) | ||||
| 
 | ||||
|     def test_contextmanager(self): | ||||
|  |  | |||
|  | @ -45,13 +45,13 @@ class TestImageSplit(PillowTestCase): | |||
|         codecs = dir(Image.core) | ||||
| 
 | ||||
|         if 'zip_encoder' in codecs: | ||||
|             file = self.tempfile("temp.png") | ||||
|             test_file = self.tempfile("temp.png") | ||||
|         else: | ||||
|             file = self.tempfile("temp.pcx") | ||||
|             test_file = self.tempfile("temp.pcx") | ||||
| 
 | ||||
|         def split_open(mode): | ||||
|             hopper(mode).save(file) | ||||
|             im = Image.open(file) | ||||
|             hopper(mode).save(test_file) | ||||
|             im = Image.open(test_file) | ||||
|             return len(im.split()) | ||||
|         self.assertEqual(split_open("1"), 1) | ||||
|         self.assertEqual(split_open("L"), 1) | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| from helper import unittest, PillowTestCase, hopper | ||||
| import helper | ||||
| from helper import unittest, PillowTestCase | ||||
| 
 | ||||
| from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180, | ||||
|                        ROTATE_270, TRANSPOSE) | ||||
|  | @ -7,8 +8,8 @@ from PIL.Image import (FLIP_LEFT_RIGHT, FLIP_TOP_BOTTOM, ROTATE_90, ROTATE_180, | |||
| class TestImageTranspose(PillowTestCase): | ||||
| 
 | ||||
|     hopper = { | ||||
|         'L': hopper('L').crop((0, 0, 121, 127)).copy(), | ||||
|         'RGB': hopper('RGB').crop((0, 0, 121, 127)).copy(), | ||||
|         'L': helper.hopper('L').crop((0, 0, 121, 127)).copy(), | ||||
|         'RGB': helper.hopper('RGB').crop((0, 0, 121, 127)).copy(), | ||||
|     } | ||||
| 
 | ||||
|     def test_flip_left_right(self): | ||||
|  |  | |||
|  | @ -24,11 +24,11 @@ class TestImageFile(PillowTestCase): | |||
|             if format in ("MSP", "XBM"): | ||||
|                 im = im.convert("1") | ||||
| 
 | ||||
|             file = BytesIO() | ||||
|             test_file = BytesIO() | ||||
| 
 | ||||
|             im.save(file, format) | ||||
|             im.save(test_file, format) | ||||
| 
 | ||||
|             data = file.getvalue() | ||||
|             data = test_file.getvalue() | ||||
| 
 | ||||
|             parser = ImageFile.Parser() | ||||
|             parser.feed(data) | ||||
|  |  | |||
|  | @ -94,7 +94,8 @@ try: | |||
|         def _render(self, font): | ||||
|             txt = "Hello World!" | ||||
|             ttf = ImageFont.truetype(font, FONT_SIZE) | ||||
|             w, h = ttf.getsize(txt) | ||||
|             ttf.getsize(txt) | ||||
|              | ||||
|             img = Image.new("RGB", (256, 64), "white") | ||||
|             d = ImageDraw.Draw(img) | ||||
|             d.text((10, 10), txt, font=ttf, fill='black') | ||||
|  |  | |||
|  | @ -17,11 +17,11 @@ class TestImagePalette(PillowTestCase): | |||
| 
 | ||||
|         palette = ImagePalette() | ||||
| 
 | ||||
|         map = {} | ||||
|         test_map = {} | ||||
|         for i in range(256): | ||||
|             map[palette.getcolor((i, i, i))] = i | ||||
|             test_map[palette.getcolor((i, i, i))] = i | ||||
| 
 | ||||
|         self.assertEqual(len(map), 256) | ||||
|         self.assertEqual(len(test_map), 256) | ||||
|         self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3))) | ||||
| 
 | ||||
|     def test_file(self): | ||||
|  | @ -117,7 +117,7 @@ class TestImagePalette(PillowTestCase): | |||
|         palette = raw("RGB", list(range(256))*3) | ||||
| 
 | ||||
|         # Act / Assert | ||||
|         self.assertRaises(ValueError, lambda: palette.tobytes()) | ||||
|         self.assertRaises(ValueError, palette.tobytes) | ||||
|         self.assertRaises(ValueError, lambda: palette.getcolor((1, 2, 3))) | ||||
|         f = self.tempfile("temp.lut") | ||||
|         self.assertRaises(ValueError, lambda: palette.save(f)) | ||||
|  |  | |||
|  | @ -7,10 +7,10 @@ class TestImageSequence(PillowTestCase): | |||
| 
 | ||||
|     def test_sanity(self): | ||||
| 
 | ||||
|         file = self.tempfile("temp.im") | ||||
|         test_file = self.tempfile("temp.im") | ||||
| 
 | ||||
|         im = hopper("RGB") | ||||
|         im.save(file) | ||||
|         im.save(test_file) | ||||
| 
 | ||||
|         seq = ImageSequence.Iterator(im) | ||||
| 
 | ||||
|  |  | |||
|  | @ -9,7 +9,6 @@ class TestImageShow(PillowTestCase): | |||
|     def test_sanity(self): | ||||
|         dir(Image) | ||||
|         dir(ImageShow) | ||||
|         pass | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|  |  | |||
|  | @ -8,7 +8,6 @@ class TestImageWin(PillowTestCase): | |||
| 
 | ||||
|     def test_sanity(self): | ||||
|         dir(ImageWin) | ||||
|         pass | ||||
| 
 | ||||
|     def test_hdc(self): | ||||
|         # Arrange | ||||
|  | @ -101,8 +100,8 @@ class TestImageWinDib(PillowTestCase): | |||
| 
 | ||||
|         # Act | ||||
|         # Make one the same as the using tobytes()/frombytes() | ||||
|         buffer = dib1.tobytes() | ||||
|         dib2.frombytes(buffer) | ||||
|         test_buffer = dib1.tobytes() | ||||
|         dib2.frombytes(test_buffer) | ||||
| 
 | ||||
|         # Assert | ||||
|         # Confirm they're the same | ||||
|  | @ -112,11 +111,11 @@ class TestImageWinDib(PillowTestCase): | |||
|         # Arrange | ||||
|         im = hopper() | ||||
|         dib = ImageWin.Dib(im) | ||||
|         buffer = dib.tobytes() | ||||
|         test_buffer = dib.tobytes() | ||||
| 
 | ||||
|         # Act/Assert | ||||
|         self.assert_warning(DeprecationWarning, lambda: dib.tostring()) | ||||
|         self.assert_warning(DeprecationWarning, lambda: dib.fromstring(buffer)) | ||||
|         self.assert_warning(DeprecationWarning, dib.tostring) | ||||
|         self.assert_warning(DeprecationWarning, lambda: dib.fromstring(test_buffer)) | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|  |  | |||
|  | @ -64,15 +64,15 @@ class TestModeI16(PillowTestCase): | |||
|             self.assertEqual(imIn.getpixel((0, 0)), 2) | ||||
| 
 | ||||
|             if mode == "L": | ||||
|                 max = 255 | ||||
|                 maximum = 255 | ||||
|             else: | ||||
|                 max = 32767 | ||||
|                 maximum = 32767 | ||||
| 
 | ||||
|             imIn = Image.new(mode, (1, 1), 256) | ||||
|             self.assertEqual(imIn.getpixel((0, 0)), min(256, max)) | ||||
|             self.assertEqual(imIn.getpixel((0, 0)), min(256, maximum)) | ||||
| 
 | ||||
|             imIn.putpixel((0, 0), 512) | ||||
|             self.assertEqual(imIn.getpixel((0, 0)), min(512, max)) | ||||
|             self.assertEqual(imIn.getpixel((0, 0)), min(512, maximum)) | ||||
| 
 | ||||
|         basic("L") | ||||
| 
 | ||||
|  |  | |||
|  | @ -60,7 +60,7 @@ class TestPickle(PillowTestCase): | |||
|         import pickle | ||||
| 
 | ||||
|         # Act / Assert | ||||
|         for file in [ | ||||
|         for test_file in [ | ||||
|                 "Tests/images/test-card.png", | ||||
|                 "Tests/images/zero_bb.png", | ||||
|                 "Tests/images/zero_bb_scale2.png", | ||||
|  | @ -69,7 +69,7 @@ class TestPickle(PillowTestCase): | |||
|                 "Tests/images/p_trns_single.png", | ||||
|                 "Tests/images/pil123p.png" | ||||
|         ]: | ||||
|             self.helper_pickle_string(pickle, file=file) | ||||
|             self.helper_pickle_string(pickle, file=test_file) | ||||
| 
 | ||||
|     def test_pickle_l_mode(self): | ||||
|         # Arrange | ||||
|  |  | |||
|  | @ -6,10 +6,7 @@ import sys | |||
| import threading | ||||
| import time | ||||
| 
 | ||||
| try: | ||||
|     format = sys.argv[1] | ||||
| except: | ||||
|     format = "PNG" | ||||
| test_format = sys.argv[1] if len(sys.argv) > 1 else "PNG" | ||||
| 
 | ||||
| im = Image.open("Tests/images/hopper.ppm") | ||||
| im.load() | ||||
|  | @ -28,7 +25,7 @@ class Worker(threading.Thread): | |||
|                 sys.stdout.write("x") | ||||
|                 break | ||||
|             f = io.BytesIO() | ||||
|             im.save(f, format, optimize=1) | ||||
|             im.save(f, test_format, optimize=1) | ||||
|             data = f.getvalue() | ||||
|             result.append(len(data)) | ||||
|             im = Image.open(io.BytesIO(data)) | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue
	
	Block a user