Various Flake8 fixes

This commit is contained in:
Andrew Murray 2015-04-24 09:26:52 +10:00
parent 40165d6860
commit d1c182cadc
40 changed files with 201 additions and 230 deletions

View File

@ -18,6 +18,7 @@ _handler = None
#
# @param handler Handler object.
def register_handler(handler):
global _handler
_handler = handler
@ -25,9 +26,11 @@ def register_handler(handler):
# --------------------------------------------------------------------
# Image adapter
def _accept(prefix):
return prefix[:6] == b"SIMPLE"
class FITSStubImageFile(ImageFile.StubImageFile):
format = "FITS"

View File

@ -53,6 +53,7 @@ class Color(_Enhance):
self.degenerate = image.convert(self.intermediate_mode).convert(image.mode)
class Contrast(_Enhance):
"""Adjust image contrast.

View File

@ -35,6 +35,7 @@ else: #PyQt4 is used
##
# (Internal) Turns an RGB color into a Qt compatible color integer.
def rgb(r, g, b, a=255):
# use qRgb to pack the colors, and then turn the resulting long
# into a negative integer with the same bitpattern.

View File

@ -234,7 +234,10 @@ __version__ = '0.30'
import io
import sys
import struct, array, os.path, datetime
import struct
import array
import os.path
import datetime
#[PL] Define explicitly the public API to avoid private objects in pydoc:
__all__ = ['OleFileIO', 'isOleFile', 'MAGIC']
@ -283,12 +286,17 @@ KEEP_UNICODE_NAMES = False
#[PL] DEBUG display mode: False by default, use set_debug_mode() or "-d" on
# command line to change it.
DEBUG_MODE = False
def debug_print(msg):
print(msg)
def debug_pass(msg):
pass
debug = debug_pass
def set_debug_mode(debug_mode):
"""
Set debug mode on or off, to control display of debugging messages.
@ -433,7 +441,6 @@ def _clsid(clsid):
tuple(map(i8, clsid[8:16]))))
# UNICODE support:
# (necessary to handle storages/streams names which use Unicode)
@ -471,7 +478,6 @@ def filetime2datetime(filetime):
return _FILETIME_null_date + datetime.timedelta(microseconds=filetime//10)
#=== CLASSES ==================================================================
class OleMetadata:
@ -579,7 +585,6 @@ class OleMetadata:
self.language = None
self.doc_version = None
def parse_properties(self, olefile):
"""
Parse standard properties of an OLE file, from the streams
@ -789,7 +794,6 @@ class _OleDirectoryEntry:
DIRENTRY_SIZE = 128
assert struct.calcsize(STRUCT_DIRENTRY) == DIRENTRY_SIZE
def __init__(self, entry, sid, olefile):
"""
Constructor for an _OleDirectoryEntry object.
@ -882,8 +886,6 @@ class _OleDirectoryEntry:
minifat = False
olefile._check_duplicate_stream(self.isectStart, minifat)
def build_storage_tree(self):
"""
Read and build the red-black tree attached to this _OleDirectoryEntry
@ -907,7 +909,6 @@ class _OleDirectoryEntry:
# (see rich comparison methods in this class)
self.kids.sort()
def append_kids(self, child_sid):
"""
Walk through red-black tree of children of this directory entry to add
@ -951,7 +952,6 @@ class _OleDirectoryEntry:
# Afterwards build kid's own tree if it's also a storage:
child.build_storage_tree()
def __eq__(self, other):
"Compare entries by name"
return self.name == other.name
@ -971,7 +971,6 @@ class _OleDirectoryEntry:
#TODO: replace by the same function as MS implementation ?
# (order by name length first, then case-insensitive order)
def dump(self, tab = 0):
"Dump this entry, and all its subentries (for debug purposes only)"
TYPES = ["(invalid)", "(storage)", "(stream)", "(lockbytes)",
@ -986,7 +985,6 @@ class _OleDirectoryEntry:
for kid in self.kids:
kid.dump(tab + 2)
def getmtime(self):
"""
Return modification time of a directory entry.
@ -1000,7 +998,6 @@ class _OleDirectoryEntry:
return None
return filetime2datetime(self.modifyTime)
def getctime(self):
"""
Return creation time of a directory entry.
@ -1064,7 +1061,6 @@ class OleFileIO:
if filename:
self.open(filename)
def _raise_defect(self, defect_level, message, exception_type=IOError):
"""
This method should be called for any defect found during file parsing.
@ -1086,7 +1082,6 @@ class OleFileIO:
# just record the issue, no exception raised:
self.parsing_issues.append((exception_type, message))
def open(self, filename):
"""
Open an OLE2 file.
@ -1266,14 +1261,12 @@ class OleFileIO:
self.ministream = None
self.minifatsect = self.MiniFatStart #i32(header, 60)
def close(self):
"""
close the OLE file, to release the file object
"""
self.fp.close()
def _check_duplicate_stream(self, first_sect, minifat=False):
"""
Checks if a stream has not been already referenced elsewhere.
@ -1298,7 +1291,6 @@ class OleFileIO:
else:
used_streams.append(first_sect)
def dumpfat(self, fat, firstindex=0):
"Displays a part of FAT in human-readable form for debugging purpose"
# [PL] added only for debug
@ -1335,7 +1327,6 @@ class OleFileIO:
print(nom, end=" ")
print()
def dumpsect(self, sector, firstindex=0):
"Displays a sector in a human-readable form, for debugging purpose."
if not DEBUG_MODE:
@ -1370,7 +1361,6 @@ class OleFileIO:
a.byteswap()
return a
def loadfat_sect(self, sect):
"""
Adds the indexes of the given sector to the FAT
@ -1400,7 +1390,6 @@ class OleFileIO:
self.fat = self.fat + nextfat
return isect
def loadfat(self, header):
"""
Load the FAT table.
@ -1471,7 +1460,6 @@ class OleFileIO:
debug('\nFAT:')
self.dumpfat(self.fat)
def loadminifat(self):
"""
Load the MiniFAT table.
@ -1531,7 +1519,6 @@ class OleFileIO:
self._raise_defect(DEFECT_FATAL, 'incomplete OLE sector')
return sector
def loaddirectory(self, sect):
"""
Load the directory.
@ -1567,7 +1554,6 @@ class OleFileIO:
# read and build all storage trees, starting from the root:
self.root.build_storage_tree()
def _load_direntry (self, sid):
"""
Load a directory entry from the directory.
@ -1592,14 +1578,12 @@ class OleFileIO:
self.direntries[sid] = _OleDirectoryEntry(entry, sid, self)
return self.direntries[sid]
def dumpdirectory(self):
"""
Dump directory (for debugging only)
"""
self.root.dump()
def _open(self, start, size = 0x7FFFFFFF, force_FAT=False):
"""
Open a stream, either in FAT or MiniFAT according to its size.
@ -1633,7 +1617,6 @@ class OleFileIO:
return _OleStream(self.fp, start, size, 512,
self.sectorsize, self.fat, self._filesize)
def _list(self, files, prefix, node, streams=True, storages=False):
"""
(listdir helper)
@ -1659,7 +1642,6 @@ class OleFileIO:
# add it to the list
files.append(prefix[1:] + [entry.name])
def listdir(self, streams=True, storages=False):
"""
Return a list of streams stored in this file
@ -1672,7 +1654,6 @@ class OleFileIO:
self._list(files, [], self.root, streams, storages)
return files
def _find(self, filename):
"""
Returns directory entry of given filename. (openstream helper)
@ -1703,7 +1684,6 @@ class OleFileIO:
node = kid
return node.sid
def openstream(self, filename):
"""
Open a stream as a read-only file object (BytesIO).
@ -1724,7 +1704,6 @@ class OleFileIO:
raise IOError("this file is not a stream")
return self._open(entry.isectStart, entry.size)
def get_type(self, filename):
"""
Test if given filename exists as a stream or a storage in the OLE
@ -1744,7 +1723,6 @@ class OleFileIO:
except:
return False
def getmtime(self, filename):
"""
Return modification time of a stream/storage.
@ -1760,7 +1738,6 @@ class OleFileIO:
entry = self.direntries[sid]
return entry.getmtime()
def getctime(self, filename):
"""
Return creation time of a stream/storage.
@ -1776,7 +1753,6 @@ class OleFileIO:
entry = self.direntries[sid]
return entry.getctime()
def exists(self, filename):
"""
Test if given filename exists as a stream or a storage in the OLE
@ -1791,7 +1767,6 @@ class OleFileIO:
except:
return False
def get_size(self, filename):
"""
Return size of a stream in the OLE container, in bytes.
@ -1808,7 +1783,6 @@ class OleFileIO:
raise TypeError('object is not an OLE stream')
return entry.size
def get_rootentry_name(self):
"""
Return root entry name. Should usually be 'Root Entry' or 'R' in most
@ -1816,7 +1790,6 @@ class OleFileIO:
"""
return self.root.name
def getproperties(self, filename, convert_time=False, no_conversion=None):
"""
Return properties described in substream.
@ -1828,7 +1801,7 @@ class OleFileIO:
:returns: a dictionary of values indexed by id (integer)
"""
# make sure no_conversion is a list, just to simplify code below:
if no_conversion == None:
if no_conversion is None:
no_conversion = []
# stream path as a string to report exceptions:
streampath = filename

View File

@ -78,6 +78,7 @@ MAX_TEXT_CHUNK = ImageFile.SAFEBLOCK
# Set the maximum total text chunk size.
MAX_TEXT_MEMORY = 64 * MAX_TEXT_CHUNK
def _safe_zlib_decompress(s):
dobj = zlib.decompressobj()
plaintext = dobj.decompress(s, MAX_TEXT_CHUNK)

View File

@ -8,6 +8,7 @@ from PIL import Image, ImageFilter
min_iterations = 100
max_iterations = 10000
@unittest.skipIf(sys.platform.startswith('win32'), "requires Unix or MacOS")
class TestImagingLeaks(PillowTestCase):
@ -40,4 +41,3 @@ class TestImagingLeaks(PillowTestCase):
if __name__ == '__main__':
unittest.main()

View File

@ -74,7 +74,6 @@ post-patch:
"""
def test_qtables_leak(self):
im = hopper('RGB')
@ -103,7 +102,6 @@ post-patch:
qtables = [standard_l_qtable,
standard_chrominance_qtable]
for count in range(iterations):
test_output = BytesIO()
im.save(test_output, "JPEG", qtables=qtables)
@ -172,7 +170,6 @@ post patch:
test_output = BytesIO()
im.save(test_output, "JPEG", exif=exif)
"""
base case:
MB

View File

@ -5,6 +5,7 @@ import zlib
TEST_FILE = "Tests/images/png_decompression_dos.png"
class TestPngDos(PillowTestCase):
def test_dos_text(self):

View File

@ -2,6 +2,7 @@ from helper import unittest, PillowTestCase
from PIL import _binary
class TestBinary(PillowTestCase):
def test_standard(self):

View File

@ -43,7 +43,6 @@ class TestFileIco(PillowTestCase):
self.assert_image_equal(reloaded, hopper().resize((32, 32), Image.LANCZOS))
if __name__ == '__main__':
unittest.main()

View File

@ -308,9 +308,6 @@ class TestFileJpeg(PillowTestCase):
# qtable entry has wrong number of items
self.assertRaises(Exception, lambda: self.roundtrip(im, qtables=[[1, 2, 3, 4]]))
@unittest.skipUnless(djpeg_available(), "djpeg not available")
def test_load_djpeg(self):
img = Image.open(TEST_FILE)

View File

@ -382,7 +382,6 @@ class TestFilePng(PillowTestCase):
self.assert_image_equal(im, repr_png)
if __name__ == '__main__':
unittest.main()

View File

@ -15,7 +15,6 @@ class TestFileWebpMetadata(PillowTestCase):
if not _webp.HAVE_WEBPMUX:
self.skipTest('WebPMux support not installed')
def test_read_exif_metadata(self):
file_path = "Tests/images/flower.webp"

View File

@ -17,6 +17,7 @@ except ImportError as v:
SRGB = "Tests/icc/sRGB_IEC61966-2-1_black_scaled.icc"
HAVE_PROFILE = os.path.exists(SRGB)
class TestImageCms(PillowTestCase):
def setUp(self):

View File

@ -21,7 +21,6 @@ class TestImageEnhance(PillowTestCase):
im = Image.new("RGB", (1, 1))
ImageEnhance.Sharpness(im).enhance(0.5)
def _half_transparent_image(self):
# returns an image, half transparent, half solid
im = hopper('RGB')

View File

@ -1,6 +1,7 @@
from helper import unittest, PillowTestCase
from PIL import Image, ImageFont, ImageDraw
class TestImageFontBitmap(PillowTestCase):
def test_similar(self):
text = 'EmbeddedBitmap'

View File

@ -41,5 +41,3 @@ class Test_scipy_resize(PillowTestCase):
assert_equal(im2, res)
assert_equal(im3, res)
assert_equal(im4, res)