Flake8 blank line fixes

This commit is contained in:
Andrew Murray 2018-03-03 20:54:00 +11:00
parent 45352662bb
commit 2202196162
79 changed files with 93 additions and 12 deletions

View File

@ -14,6 +14,7 @@ def bench(mode):
get(xy) get(xy)
print(mode, timeit.default_timer() - t0, "us") print(mode, timeit.default_timer() - t0, "us")
bench("L") bench("L")
bench("I") bench("I")
bench("I;16") bench("I;16")

View File

@ -40,5 +40,6 @@ class TestImagingLeaks(PillowTestCase):
# Pass a new list at each iteration. # Pass a new list at each iteration.
lambda: im.point(range(256))) lambda: im.point(range(256)))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -10,5 +10,6 @@ class TestJ2kEncodeOverflow(PillowTestCase):
with self.assertRaises(IOError): with self.assertRaises(IOError):
im.save(target) im.save(target)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -60,5 +60,6 @@ class TestPngDos(PillowTestCase):
self.assertLess(total_len, 64*1024*1024, self.assertLess(total_len, 64*1024*1024,
"Total text chunks greater than 64M") "Total text chunks greater than 64M")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -18,6 +18,7 @@ HAS_UPLOADER = False
if os.environ.get('SHOW_ERRORS', None): if os.environ.get('SHOW_ERRORS', None):
# local img.show for errors. # local img.show for errors.
HAS_UPLOADER=True HAS_UPLOADER=True
class test_image_results: class test_image_results:
@classmethod @classmethod
def upload(self, a, b): def upload(self, a, b):
@ -31,7 +32,6 @@ else:
pass pass
def convert_to_comparable(a, b): def convert_to_comparable(a, b):
new_a, new_b = a, b new_a, new_b = a, b
if a.mode == 'P': if a.mode == 'P':

View File

@ -32,6 +32,7 @@ def check(size, i0):
h[i] = m h[i] = m
return h return h
min_start = 0 min_start = 0
# 1) find the smallest table size with no collisions # 1) find the smallest table size with no collisions

View File

@ -23,5 +23,6 @@ class TestBinary(PillowTestCase):
self.assertEqual(_binary.o16be(65535), b'\xff\xff') self.assertEqual(_binary.o16be(65535), b'\xff\xff')
self.assertEqual(_binary.o32be(65535), b'\x00\x00\xff\xff') self.assertEqual(_binary.o32be(65535), b'\x00\x00\xff\xff')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -44,6 +44,7 @@ class TestDecompressionBomb(PillowTestCase):
self.assertRaises(Image.DecompressionBombError, self.assertRaises(Image.DecompressionBombError,
lambda: Image.open(TEST_FILE)) lambda: Image.open(TEST_FILE))
class TestDecompressionCrop(PillowTestCase): class TestDecompressionCrop(PillowTestCase):
def setUp(self): def setUp(self):

View File

@ -111,5 +111,6 @@ class TestFileDds(PillowTestCase):
self.assertRaises(IOError, short_file) self.assertRaises(IOError, short_file)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -15,5 +15,6 @@ class TestFileFtex(PillowTestCase):
target = Image.open('Tests/images/ftex_dxt1.png') target = Image.open('Tests/images/ftex_dxt1.png')
self.assert_image_similar(im, target.convert('RGBA'), 15) self.assert_image_similar(im, target.convert('RGBA'), 15)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -18,5 +18,6 @@ class TestFileGbr(PillowTestCase):
self.assert_image_equal(target, im) self.assert_image_equal(target, im)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -278,7 +278,6 @@ class TestFileGif(PillowTestCase):
img.seek(img.tell() + 1) img.seek(img.tell() + 1)
self.assertEqual(img.disposal_method, method) self.assertEqual(img.disposal_method, method)
# check per frame disposal # check per frame disposal
im_list[0].save( im_list[0].save(
out, out,
@ -586,5 +585,6 @@ class TestFileGif(PillowTestCase):
# codec error prepatch # codec error prepatch
im.load() im.load()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -176,5 +176,6 @@ class TestFileJpeg2k(PillowTestCase):
with self.assertRaises(IOError): with self.assertRaises(IOError):
Image.open('Tests/images/unbound_variable.jp2') Image.open('Tests/images/unbound_variable.jp2')
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -22,6 +22,7 @@ def chunk(cid, *data):
PngImagePlugin.putchunk(*(test_file, cid) + data) PngImagePlugin.putchunk(*(test_file, cid) + data)
return test_file.getvalue() return test_file.getvalue()
o32 = PngImagePlugin.o32 o32 = PngImagePlugin.o32
IHDR = chunk(b"IHDR", o32(1), o32(1), b'\x08\x02', b'\0\0\0') IHDR = chunk(b"IHDR", o32(1), o32(1), b'\x08\x02', b'\0\0\0')

View File

@ -46,5 +46,6 @@ class TestFileSun(PillowTestCase):
with Image.open(target_path) as target: with Image.open(target_path) as target:
self.assert_image_equal(im, target) self.assert_image_equal(im, target)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -398,7 +398,6 @@ class TestFileTiff(PillowTestCase):
self.assertEqual(im.tag_v2[X_RESOLUTION], 72) self.assertEqual(im.tag_v2[X_RESOLUTION], 72)
self.assertEqual(im.tag_v2[Y_RESOLUTION], 36) self.assertEqual(im.tag_v2[Y_RESOLUTION], 36)
def test_roundtrip_tiff_uint16(self): def test_roundtrip_tiff_uint16(self):
# Test an image of all '0' values # Test an image of all '0' values
pixel_value = 0x1234 pixel_value = 0x1234
@ -447,7 +446,6 @@ class TestFileTiff(PillowTestCase):
reread = Image.open(mp) reread = Image.open(mp)
self.assertEqual(reread.n_frames, 3) self.assertEqual(reread.n_frames, 3)
def test_saving_icc_profile(self): def test_saving_icc_profile(self):
# Tests saving TIFF with icc_profile set. # Tests saving TIFF with icc_profile set.
# At the time of writing this will only work for non-compressed tiffs # At the time of writing this will only work for non-compressed tiffs
@ -489,6 +487,7 @@ class TestFileTiff(PillowTestCase):
im.load() im.load()
self.assertFalse(fp.closed) self.assertFalse(fp.closed)
@unittest.skipUnless(sys.platform.startswith('win32'), "Windows only") @unittest.skipUnless(sys.platform.startswith('win32'), "Windows only")
class TestFileTiffW32(PillowTestCase): class TestFileTiffW32(PillowTestCase):
def test_fd_leak(self): def test_fd_leak(self):

View File

@ -78,7 +78,6 @@ class TestFileTiffMetadata(PillowTestCase):
self.assertEqual(loaded.tag[ImageJMetaDataByteCounts], (8, len(bindata) - 8)) self.assertEqual(loaded.tag[ImageJMetaDataByteCounts], (8, len(bindata) - 8))
self.assertEqual(loaded.tag_v2[ImageJMetaDataByteCounts], (8, len(bindata) - 8)) self.assertEqual(loaded.tag_v2[ImageJMetaDataByteCounts], (8, len(bindata) - 8))
def test_read_metadata(self): def test_read_metadata(self):
img = Image.open('Tests/images/hopper_g4.tif') img = Image.open('Tests/images/hopper_g4.tif')

View File

@ -3,6 +3,7 @@ from helper import unittest, PillowLeakTestCase
import sys import sys
from PIL import Image, features, ImageDraw, ImageFont from PIL import Image, features, ImageDraw, ImageFont
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS") @unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS")
class TestTTypeFontLeak(PillowLeakTestCase): class TestTTypeFontLeak(PillowLeakTestCase):
# fails at iteration 3 in master # fails at iteration 3 in master
@ -20,6 +21,7 @@ class TestTTypeFontLeak(PillowLeakTestCase):
ttype = ImageFont.truetype('Tests/fonts/FreeMono.ttf', 20) ttype = ImageFont.truetype('Tests/fonts/FreeMono.ttf', 20)
self._test_font(ttype) self._test_font(ttype)
class TestDefaultFontLeak(TestTTypeFontLeak): class TestDefaultFontLeak(TestTTypeFontLeak):
# fails at iteration 37 in master # fails at iteration 37 in master
iterations = 100 iterations = 100

View File

@ -72,7 +72,6 @@ class TestFontPcf(PillowTestCase):
with Image.open('Tests/images/high_ascii_chars.png') as target: with Image.open('Tests/images/high_ascii_chars.png') as target:
self.assert_image_similar(im, target, 0) self.assert_image_similar(im, target, 0)
def test_high_characters(self): def test_high_characters(self):
message = "".join(chr(i+1) for i in range(140, 232)) message = "".join(chr(i+1) for i in range(140, 232))
self._test_high_characters(message) self._test_high_characters(message)

View File

@ -10,6 +10,7 @@ from PIL import Image
import sys import sys
import os import os
class AccessTest(PillowTestCase): class AccessTest(PillowTestCase):
# initial value # initial value
_init_cffi_access = Image.USE_CFFI_ACCESS _init_cffi_access = Image.USE_CFFI_ACCESS
@ -309,5 +310,6 @@ int main(int argc, char* argv[])
process.communicate() process.communicate()
self.assertEqual(process.returncode, 0) self.assertEqual(process.returncode, 0)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -90,7 +90,6 @@ class TestImageConvert(PillowTestCase):
# https://github.com/python-pillow/Pillow/issues/2702 # https://github.com/python-pillow/Pillow/issues/2702
self.assertEqual(rgba.palette, None) self.assertEqual(rgba.palette, None)
def test_trns_l(self): def test_trns_l(self):
im = hopper('L') im = hopper('L')
im.info['transparency'] = 128 im.info['transparency'] = 128

View File

@ -70,5 +70,6 @@ class TestImageDraft(PillowTestCase):
im.draft(None, (64, 64)) im.draft(None, (64, 64))
im.load() im.load()
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -29,5 +29,6 @@ class TestImageLoad(PillowTestCase):
self.assertRaises(OSError, os.fstat, fn) self.assertRaises(OSError, os.fstat, fn)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -84,5 +84,6 @@ class TestImagePutData(PillowTestCase):
self.assertEqual(len(im.getdata()), len(arr)) self.assertEqual(len(im.getdata()), len(arr))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -7,5 +7,6 @@ class TestImageToBytes(PillowTestCase):
data = hopper().tobytes() data = hopper().tobytes()
self.assertIsInstance(data, bytes) self.assertIsInstance(data, bytes)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -267,5 +267,6 @@ class TestImageTransformPerspective(TestImageTransformAffine):
# Repeat all tests for AFFINE transformations with PERSPECTIVE # Repeat all tests for AFFINE transformations with PERSPECTIVE
transform = Image.PERSPECTIVE transform = Image.PERSPECTIVE
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -437,5 +437,6 @@ class TestImageCms(PillowTestCase):
self.assert_image_equal(test_image.convert(dst_format[2]), reference_image) self.assert_image_equal(test_image.convert(dst_format[2]), reference_image)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -146,6 +146,7 @@ class MockPyDecoder(ImageFile.PyDecoder):
# eof # eof
return (-1, 0) return (-1, 0)
xoff, yoff, xsize, ysize = 10, 20, 100, 100 xoff, yoff, xsize, ysize = 10, 20, 100, 100
@ -222,5 +223,6 @@ class TestPyDecoder(PillowTestCase):
im.tile = [("MOCK", (xoff, yoff, xoff+xsize, yoff+ysize + 100), 32, None)] im.tile = [("MOCK", (xoff, yoff, xoff+xsize, yoff+ysize + 100), 32, None)]
self.assertRaises(ValueError, im.load) self.assertRaises(ValueError, im.load)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -420,7 +420,6 @@ class TestImageFont(PillowTestCase):
with self.assertRaises(UnicodeEncodeError): with self.assertRaises(UnicodeEncodeError):
font.getsize(u"") font.getsize(u"")
def _test_fake_loading_font(self, path_to_fake, fontname): def _test_fake_loading_font(self, path_to_fake, fontname):
# Make a copy of FreeTypeFont so we can patch the original # Make a copy of FreeTypeFont so we can patch the original
free_type_font = copy.deepcopy(ImageFont.FreeTypeFont) free_type_font = copy.deepcopy(ImageFont.FreeTypeFont)

View File

@ -34,5 +34,6 @@ class TestImageFontBitmap(PillowTestCase):
text, fill=(0, 0, 0), font=font_outline) text, fill=(0, 0, 0), font=font_outline)
self.assert_image_similar(im_bitmap, im_outline, 20) self.assert_image_similar(im_bitmap, im_outline, 20)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -6,6 +6,7 @@ from PIL import Image, ImageDraw, ImageFont, features
FONT_SIZE = 20 FONT_SIZE = 20
FONT_PATH = "Tests/fonts/DejaVuSans.ttf" FONT_PATH = "Tests/fonts/DejaVuSans.ttf"
@unittest.skipUnless(features.check('raqm'), "Raqm Library is not installed.") @unittest.skipUnless(features.check('raqm'), "Raqm Library is not installed.")
class TestImagecomplextext(PillowTestCase): class TestImagecomplextext(PillowTestCase):
@ -16,7 +17,6 @@ class TestImagecomplextext(PillowTestCase):
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
draw.text((0, 0), 'TEST', font=ttf, fill=500, direction='ltr') draw.text((0, 0), 'TEST', font=ttf, fill=500, direction='ltr')
def test_complex_text(self): def test_complex_text(self):
ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE) ttf = ImageFont.truetype(FONT_PATH, FONT_SIZE)
@ -127,6 +127,7 @@ class TestImagecomplextext(PillowTestCase):
self.assert_image_similar(im, target_img, .5) self.assert_image_similar(im, target_img, .5)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -13,6 +13,7 @@ def pixel(im):
return int(im) # hack to deal with booleans return int(im) # hack to deal with booleans
print(im) print(im)
A = Image.new("L", (1, 1), 1) A = Image.new("L", (1, 1), 1)
B = Image.new("L", (1, 1), 2) B = Image.new("L", (1, 1), 2)
Z = Image.new("L", (1, 1), 0) # Z for zero Z = Image.new("L", (1, 1), 0) # Z for zero

View File

@ -97,5 +97,6 @@ class TestImageOpsUsm(PillowTestCase):
self.assertTrue(236 <= gp(8, 6)[2] <= 239) self.assertTrue(236 <= gp(8, 6)[2] <= 239)
self.assertTrue(236 <= gp(8, 7)[1] <= 239) self.assertTrue(236 <= gp(8, 7)[1] <= 239)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -70,5 +70,6 @@ class TestImageSequence(PillowTestCase):
color2 = im.getpalette()[0:3] color2 = im.getpalette()[0:3]
self.assertEqual(color1, color2) self.assertEqual(color1, color2)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -226,7 +226,6 @@ class TestLibUnpack(PillowTestCase):
self.assert_unpack("L", "L;16", b'\x00\xc6\x00\xaf', 198, 175) self.assert_unpack("L", "L;16", b'\x00\xc6\x00\xaf', 198, 175)
self.assert_unpack("L", "L;16B", b'\xc6\x00\xaf\x00', 198, 175) self.assert_unpack("L", "L;16B", b'\xc6\x00\xaf\x00', 198, 175)
def test_LA(self): def test_LA(self):
self.assert_unpack("LA", "LA", 2, (1, 2), (3, 4), (5, 6)) self.assert_unpack("LA", "LA", 2, (1, 2), (3, 4), (5, 6))
self.assert_unpack("LA", "LA;L", 2, (1, 4), (2, 5), (3, 6)) self.assert_unpack("LA", "LA;L", 2, (1, 4), (2, 5), (3, 6))

View File

@ -92,5 +92,6 @@ class TestPickle(PillowTestCase):
self.helper_pickle_string(cPickle, protocol, mode="L") self.helper_pickle_string(cPickle, protocol, mode="L")
self.helper_pickle_file(cPickle, protocol, mode="L") self.helper_pickle_file(cPickle, protocol, mode="L")
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -59,5 +59,6 @@ class Test_IFDRational(PillowTestCase):
self.assertEqual(float(IFDRational(301, 1)), self.assertEqual(float(IFDRational(301, 1)),
float(reloaded.tag_v2[282])) float(reloaded.tag_v2[282]))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -12,5 +12,6 @@ class TestUploader(PillowTestCase):
target = hopper('RGB') target = hopper('RGB')
self.assert_image_similar(result, target, 0) self.assert_image_similar(result, target, 0)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -75,5 +75,6 @@ class TestUtil(PillowTestCase):
# Assert # Assert
self.assertRaises(ValueError, lambda: thing.some_attr) self.assertRaises(ValueError, lambda: thing.some_attr)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()

View File

@ -4,6 +4,7 @@ from io import BytesIO
test_file = "Tests/images/hopper.webp" test_file = "Tests/images/hopper.webp"
@unittest.skipUnless(features.check('webp'), "WebP is not installed") @unittest.skipUnless(features.check('webp'), "WebP is not installed")
class TestWebPLeaks(PillowLeakTestCase): class TestWebPLeaks(PillowLeakTestCase):

View File

@ -34,6 +34,7 @@ class Worker(threading.Thread):
sys.stdout.write(".") sys.stdout.write(".")
queue.task_done() queue.task_done()
t0 = time.time() t0 = time.time()
threads = 20 threads = 20

View File

@ -7,6 +7,7 @@ def version(module, version):
if v: if v:
print(version, v) print(version, v)
version(Image, "jpeglib") version(Image, "jpeglib")
version(Image, "zlib") version(Image, "zlib")

View File

@ -271,6 +271,7 @@ class DXT5Decoder(ImageFile.PyDecoder):
raise IOError("Truncated DDS file") raise IOError("Truncated DDS file")
return 0, 0 return 0, 0
Image.register_decoder('DXT1', DXT1Decoder) Image.register_decoder('DXT1', DXT1Decoder)
Image.register_decoder('DXT5', DXT5Decoder) Image.register_decoder('DXT5', DXT5Decoder)

View File

@ -216,6 +216,7 @@ class DibImageFile(BmpImageFile):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Write BMP file # Write BMP file
SAVE = { SAVE = {
"1": ("1", 1, 2), "1": ("1", 1, 2),
"L": ("L", 8, 256), "L": ("L", 8, 256),
@ -279,6 +280,7 @@ def _save(im, fp, filename):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Registry # Registry
Image.register_open(BmpImageFile.format, BmpImageFile, _accept) Image.register_open(BmpImageFile.format, BmpImageFile, _accept)
Image.register_save(BmpImageFile.format, _save) Image.register_save(BmpImageFile.format, _save)

View File

@ -418,6 +418,7 @@ def _save(im, fp, filename, eps=1):
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
Image.register_open(EpsImageFile.format, EpsImageFile, _accept) Image.register_open(EpsImageFile.format, EpsImageFile, _accept)
Image.register_save(EpsImageFile.format, _save) Image.register_save(EpsImageFile.format, _save)

View File

@ -223,6 +223,7 @@ class FpxImageFile(ImageFile.ImageFile):
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
Image.register_open(FpxImageFile.format, FpxImageFile, _accept) Image.register_open(FpxImageFile.format, FpxImageFile, _accept)
Image.register_extension(FpxImageFile.format, ".fpx") Image.register_extension(FpxImageFile.format, ".fpx")

View File

@ -89,5 +89,6 @@ class GbrImageFile(ImageFile.ImageFile):
# #
# registry # registry
Image.register_open(GbrImageFile.format, GbrImageFile, _accept) Image.register_open(GbrImageFile.format, GbrImageFile, _accept)
Image.register_extension(GbrImageFile.format, ".gbr") Image.register_extension(GbrImageFile.format, ".gbr")

View File

@ -292,6 +292,7 @@ class GifImageFile(ImageFile.ImageFile):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Write GIF files # Write GIF files
RAWMODE = { RAWMODE = {
"1": "L", "1": "L",
"L": "L", "L": "L",

View File

@ -55,6 +55,7 @@ def sphere_increasing(middle, pos):
def sphere_decreasing(middle, pos): def sphere_decreasing(middle, pos):
return 1.0 - sqrt(1.0 - linear(middle, pos) ** 2) return 1.0 - sqrt(1.0 - linear(middle, pos) ** 2)
SEGMENTS = [linear, curved, sine, sphere_increasing, sphere_decreasing] SEGMENTS = [linear, curved, sine, sphere_increasing, sphere_decreasing]

View File

@ -342,6 +342,7 @@ def _save(im, fp, filename):
if retcode: if retcode:
raise CalledProcessError(retcode, convert_cmd) raise CalledProcessError(retcode, convert_cmd)
Image.register_open(IcnsImageFile.format, IcnsImageFile, Image.register_open(IcnsImageFile.format, IcnsImageFile,
lambda x: x[:4] == b'icns') lambda x: x[:4] == b'icns')
Image.register_extension(IcnsImageFile.format, '.icns') Image.register_extension(IcnsImageFile.format, '.icns')

View File

@ -294,6 +294,7 @@ class ImImageFile(ImageFile.ImageFile):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Save IM files # Save IM files
SAVE = { SAVE = {
# mode: (im type, raw mode) # mode: (im type, raw mode)
"1": ("0 1", "1"), "1": ("0 1", "1"),
@ -339,6 +340,7 @@ def _save(im, fp, filename):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Registry # Registry
Image.register_open(ImImageFile.format, ImImageFile) Image.register_open(ImImageFile.format, ImImageFile)
Image.register_save(ImImageFile.format, _save) Image.register_save(ImImageFile.format, _save)

View File

@ -36,9 +36,11 @@ logger = logging.getLogger(__name__)
class DecompressionBombWarning(RuntimeWarning): class DecompressionBombWarning(RuntimeWarning):
pass pass
class DecompressionBombError(Exception): class DecompressionBombError(Exception):
pass pass
class _imaging_not_installed(object): class _imaging_not_installed(object):
# module placeholder # module placeholder
def __getattr__(self, id): def __getattr__(self, id):
@ -2745,6 +2747,7 @@ def register_extension(id, extension):
""" """
EXTENSION[extension.lower()] = id.upper() EXTENSION[extension.lower()] = id.upper()
def register_extensions(id, extensions): def register_extensions(id, extensions):
""" """
Registers image extensions. This function should not be Registers image extensions. This function should not be
@ -2756,6 +2759,7 @@ def register_extensions(id, extensions):
for extension in extensions: for extension in extensions:
register_extension(id, extension) register_extension(id, extension)
def registered_extensions(): def registered_extensions():
""" """
Returns a dictionary containing all file extensions belonging Returns a dictionary containing all file extensions belonging
@ -2886,5 +2890,6 @@ def _apply_env_variables(env=None):
except ValueError as e: except ValueError as e:
warnings.warn("{0}: {1}".format(var_name, e)) warnings.warn("{0}: {1}".format(var_name, e))
_apply_env_variables() _apply_env_variables()
atexit.register(core.clear_cache) atexit.register(core.clear_cache)

View File

@ -554,6 +554,7 @@ def buildProofTransform(
except (IOError, TypeError, ValueError) as v: except (IOError, TypeError, ValueError) as v:
raise PyCMSError(v) raise PyCMSError(v)
buildTransformFromOpenProfiles = buildTransform buildTransformFromOpenProfiles = buildTransform
buildProofTransformFromOpenProfiles = buildProofTransform buildProofTransformFromOpenProfiles = buildProofTransform

View File

@ -139,6 +139,7 @@ def getcolor(color, mode):
return color + (alpha,) return color + (alpha,)
return color return color
colormap = { colormap = {
# X11 colour table from https://drafts.csswg.org/css-color-4/, with # X11 colour table from https://drafts.csswg.org/css-color-4/, with
# gray/grey spelling issues fixed. This is a superset of HTML 4.0 # gray/grey spelling issues fixed. This is a superset of HTML 4.0

View File

@ -33,6 +33,7 @@ import sys
LAYOUT_BASIC = 0 LAYOUT_BASIC = 0
LAYOUT_RAQM = 1 LAYOUT_RAQM = 1
class _imagingft_not_installed(object): class _imagingft_not_installed(object):
# module placeholder # module placeholder
def __getattr__(self, id): def __getattr__(self, id):

View File

@ -235,6 +235,7 @@ def imagemath_max(self, other):
def imagemath_convert(self, mode): def imagemath_convert(self, mode):
return _Operand(self.im.convert(mode)) return _Operand(self.im.convert(mode))
ops = {} ops = {}
for k, v in list(globals().items()): for k, v in list(globals().items()):
if k[:10] == "imagemath_": if k[:10] == "imagemath_":

View File

@ -162,6 +162,7 @@ def _toqclass_helper(im):
'data': __data, 'im': im, 'format': format, 'colortable': colortable 'data': __data, 'im': im, 'format': format, 'colortable': colortable
} }
if qt_is_installed: if qt_is_installed:
class ImageQt(QImage): class ImageQt(QImage):

View File

@ -144,4 +144,5 @@ class Stat(object):
v.append(math.sqrt(self.var[i])) v.append(math.sqrt(self.var[i]))
return v return v
Global = Stat # compatibility Global = Stat # compatibility

View File

@ -266,6 +266,7 @@ def _save(im, fp, filename):
# ------------------------------------------------------------ # ------------------------------------------------------------
# Registry stuff # Registry stuff
Image.register_open(Jpeg2KImageFile.format, Jpeg2KImageFile, _accept) Image.register_open(Jpeg2KImageFile.format, Jpeg2KImageFile, _accept)
Image.register_save(Jpeg2KImageFile.format, _save) Image.register_save(Jpeg2KImageFile.format, _save)

View File

@ -153,6 +153,7 @@ class PSDraw(object):
# Copyright (c) Fredrik Lundh 1994. # Copyright (c) Fredrik Lundh 1994.
# #
EDROFF_PS = """\ EDROFF_PS = """\
/S { show } bind def /S { show } bind def
/P { moveto show } bind def /P { moveto show } bind def

View File

@ -90,6 +90,7 @@ def build_prototype_image():
image.putpalette(palettedata) image.putpalette(palettedata)
return image return image
Palm8BitColormapImage = build_prototype_image() Palm8BitColormapImage = build_prototype_image()
# OK, we now have in Palm8BitColormapImage, # OK, we now have in Palm8BitColormapImage,

View File

@ -110,6 +110,7 @@ class PcxImageFile(ImageFile.ImageFile):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# save PCX files # save PCX files
SAVE = { SAVE = {
# mode: (version, bits, planes, raw mode) # mode: (version, bits, planes, raw mode)
"1": (2, 1, 1, "1"), "1": (2, 1, 1, "1"),
@ -171,6 +172,7 @@ def _save(im, fp, filename):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# registry # registry
Image.register_open(PcxImageFile.format, PcxImageFile, _accept) Image.register_open(PcxImageFile.format, PcxImageFile, _accept)
Image.register_save(PcxImageFile.format, _save) Image.register_save(PcxImageFile.format, _save)

View File

@ -263,6 +263,7 @@ def _save(im, fp, filename, save_all=False):
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
Image.register_save("PDF", _save) Image.register_save("PDF", _save)
Image.register_save_all("PDF", _save_all) Image.register_save_all("PDF", _save_all)

View File

@ -85,6 +85,7 @@ def _safe_zlib_decompress(s):
raise ValueError("Decompressed Data Too Large") raise ValueError("Decompressed Data Too Large")
return plaintext return plaintext
def _crc32(data, seed=0): def _crc32(data, seed=0):
return zlib.crc32(data, seed) & 0xffffffff return zlib.crc32(data, seed) & 0xffffffff

View File

@ -150,6 +150,7 @@ def _save(im, fp, filename):
# #
# -------------------------------------------------------------------- # --------------------------------------------------------------------
Image.register_open(PpmImageFile.format, PpmImageFile, _accept) Image.register_open(PpmImageFile.format, PpmImageFile, _accept)
Image.register_save(PpmImageFile.format, _save) Image.register_save(PpmImageFile.format, _save)

View File

@ -301,6 +301,7 @@ def _maketile(file, mode, bbox, channels):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# registry # registry
Image.register_open(PsdImageFile.format, PsdImageFile, _accept) Image.register_open(PsdImageFile.format, PsdImageFile, _accept)
Image.register_extension(PsdImageFile.format, ".psd") Image.register_extension(PsdImageFile.format, ".psd")

View File

@ -193,6 +193,7 @@ def _save(im, fp, filename):
fp.close() fp.close()
class SGI16Decoder(ImageFile.PyDecoder): class SGI16Decoder(ImageFile.PyDecoder):
_pulls_fd = True _pulls_fd = True

View File

@ -51,6 +51,7 @@ def isInt(f):
except (ValueError, OverflowError): except (ValueError, OverflowError):
return 0 return 0
iforms = [1, 3, -11, -12, -21, -22] iforms = [1, 3, -11, -12, -21, -22]
@ -279,6 +280,7 @@ def _save_spider(im, fp, filename):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
Image.register_open(SpiderImageFile.format, SpiderImageFile) Image.register_open(SpiderImageFile.format, SpiderImageFile)
Image.register_save(SpiderImageFile.format, _save_spider) Image.register_save(SpiderImageFile.format, _save_spider)

View File

@ -130,6 +130,7 @@ class SunImageFile(ImageFile.ImageFile):
# #
# registry # registry
Image.register_open(SunImageFile.format, SunImageFile, _accept) Image.register_open(SunImageFile.format, SunImageFile, _accept)
Image.register_extension(SunImageFile.format, ".ras") Image.register_extension(SunImageFile.format, ".ras")

View File

@ -130,6 +130,7 @@ class TgaImageFile(ImageFile.ImageFile):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Write TGA file # Write TGA file
SAVE = { SAVE = {
"1": ("1", 1, 0, 3), "1": ("1", 1, 0, 3),
"L": ("L", 8, 0, 3), "L": ("L", 8, 0, 3),
@ -186,6 +187,7 @@ def _save(im, fp, filename):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Registry # Registry
Image.register_open(TgaImageFile.format, TgaImageFile) Image.register_open(TgaImageFile.format, TgaImageFile)
Image.register_save(TgaImageFile.format, _save) Image.register_save(TgaImageFile.format, _save)

View File

@ -1286,7 +1286,6 @@ class TiffImageFile(ImageFile.ImageFile):
if ';16L' in rawmode: if ';16L' in rawmode:
rawmode = rawmode.replace(';16L', ';16N') rawmode = rawmode.replace(';16L', ';16N')
# Offset in the tile tuple is 0, we go from 0,0 to # Offset in the tile tuple is 0, we go from 0,0 to
# w,h, and we only do this once -- eds # w,h, and we only do this once -- eds
a = (rawmode, self._compression, False) a = (rawmode, self._compression, False)

View File

@ -355,6 +355,7 @@ def _populate():
TAGS_V2[k] = TagInfo(k, *v) TAGS_V2[k] = TagInfo(k, *v)
_populate() _populate()
## ##
# Map type numbers to type names -- defined in ImageFileDirectory. # Map type numbers to type names -- defined in ImageFileDirectory.

View File

@ -74,6 +74,7 @@ def open(filename):
with builtins.open(filename, "rb") as fp: with builtins.open(filename, "rb") as fp:
return imopen(fp) return imopen(fp)
quake2palette = ( quake2palette = (
# default palette taken from piffo 0.93 by Hans Häggström # default palette taken from piffo 0.93 by Hans Häggström
b"\x01\x01\x01\x0b\x0b\x0b\x12\x12\x12\x17\x17\x17\x1b\x1b\x1b\x1e" b"\x01\x01\x01\x0b\x0b\x0b\x12\x12\x12\x17\x17\x17\x1b\x1b\x1b\x1e"

View File

@ -42,6 +42,7 @@ def register_handler(handler):
global _handler global _handler
_handler = handler _handler = handler
if hasattr(Image.core, "drawwmf"): if hasattr(Image.core, "drawwmf"):
# install default handler (windows only) # install default handler (windows only)
@ -161,6 +162,7 @@ def _save(im, fp, filename):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Registry stuff # Registry stuff
Image.register_open(WmfStubImageFile.format, WmfStubImageFile, _accept) Image.register_open(WmfStubImageFile.format, WmfStubImageFile, _accept)
Image.register_save(WmfStubImageFile.format, _save) Image.register_save(WmfStubImageFile.format, _save)

View File

@ -121,6 +121,7 @@ class XpmImageFile(ImageFile.ImageFile):
# #
# Registry # Registry
Image.register_open(XpmImageFile.format, XpmImageFile, _accept) Image.register_open(XpmImageFile.format, XpmImageFile, _accept)
Image.register_extension(XpmImageFile.format, ".xpm") Image.register_extension(XpmImageFile.format, ".xpm")

View File

@ -8,6 +8,7 @@ modules = {
"webp": "PIL._webp", "webp": "PIL._webp",
} }
def check_module(feature): def check_module(feature):
if not (feature in modules): if not (feature in modules):
raise ValueError("Unknown module %s" % feature) raise ValueError("Unknown module %s" % feature)
@ -20,9 +21,11 @@ def check_module(feature):
except ImportError: except ImportError:
return False return False
def get_supported_modules(): def get_supported_modules():
return [f for f in modules if check_module(f)] return [f for f in modules if check_module(f)]
codecs = { codecs = {
"jpg": "jpeg", "jpg": "jpeg",
"jpg_2000": "jpeg2k", "jpg_2000": "jpeg2k",
@ -30,6 +33,7 @@ codecs = {
"libtiff": "libtiff" "libtiff": "libtiff"
} }
def check_codec(feature): def check_codec(feature):
if feature not in codecs: if feature not in codecs:
raise ValueError("Unknown codec %s" % feature) raise ValueError("Unknown codec %s" % feature)
@ -42,6 +46,7 @@ def check_codec(feature):
def get_supported_codecs(): def get_supported_codecs():
return [f for f in codecs if check_codec(f)] return [f for f in codecs if check_codec(f)]
features = { features = {
"webp_anim": ("PIL._webp", 'HAVE_WEBPANIM'), "webp_anim": ("PIL._webp", 'HAVE_WEBPANIM'),
"webp_mux": ("PIL._webp", 'HAVE_WEBPMUX'), "webp_mux": ("PIL._webp", 'HAVE_WEBPMUX'),
@ -49,6 +54,7 @@ features = {
"raqm": ("PIL._imagingft", "HAVE_RAQM") "raqm": ("PIL._imagingft", "HAVE_RAQM")
} }
def check_feature(feature): def check_feature(feature):
if feature not in features: if feature not in features:
raise ValueError("Unknown feature %s" % feature) raise ValueError("Unknown feature %s" % feature)
@ -71,9 +77,9 @@ def check(feature):
feature in codecs and check_codec(feature) or \ feature in codecs and check_codec(feature) or \
feature in features and check_feature(feature)) feature in features and check_feature(feature))
def get_supported(): def get_supported():
ret = get_supported_modules() ret = get_supported_modules()
ret.extend(get_supported_features()) ret.extend(get_supported_features())
ret.extend(get_supported_codecs()) ret.extend(get_supported_codecs())
return ret return ret

View File

@ -14,5 +14,6 @@ def fetch(url):
fd.write(content) fd.write(content)
return name return name
if __name__ == '__main__': if __name__ == '__main__':
fetch(sys.argv[1]) fetch(sys.argv[1])

View File

@ -6,5 +6,6 @@ def untar(src, dest):
with tarfile.open(src, 'r:gz') as tgz: with tarfile.open(src, 'r:gz') as tgz:
tgz.extractall(dest) tgz.extractall(dest)
if __name__ == '__main__': if __name__ == '__main__':
untar(sys.argv[1], sys.argv[2]) untar(sys.argv[1], sys.argv[2])

View File

@ -6,5 +6,6 @@ def unzip(src, dest):
with zipfile.ZipFile(src) as zf: with zipfile.ZipFile(src) as zf:
zf.extractall(dest) zf.extractall(dest)
if __name__ == '__main__': if __name__ == '__main__':
unzip(sys.argv[1], sys.argv[2]) unzip(sys.argv[1], sys.argv[2])