mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-26 01:46:18 +03:00
Flake8 fixes
This commit is contained in:
parent
1208fe89cd
commit
1b98b76bcf
|
@ -256,7 +256,10 @@ __version__ = '0.42b'
|
|||
|
||||
import io
|
||||
import sys
|
||||
import struct, array, os.path, datetime
|
||||
import struct
|
||||
import array
|
||||
import os.path
|
||||
import datetime
|
||||
|
||||
#=== COMPATIBILITY WORKAROUNDS ================================================
|
||||
|
||||
|
@ -326,12 +329,19 @@ else:
|
|||
# [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.
|
||||
|
@ -502,7 +512,6 @@ def _clsid(clsid):
|
|||
tuple(map(i8, clsid[8:16]))))
|
||||
|
||||
|
||||
|
||||
def filetime2datetime(filetime):
|
||||
"""
|
||||
convert FILETIME (64 bits int) to Python datetime.datetime
|
||||
|
@ -514,7 +523,6 @@ def filetime2datetime(filetime):
|
|||
return _FILETIME_null_date + datetime.timedelta(microseconds=filetime//10)
|
||||
|
||||
|
||||
|
||||
#=== CLASSES ==================================================================
|
||||
|
||||
class OleMetadata(object):
|
||||
|
@ -622,7 +630,6 @@ class OleMetadata(object):
|
|||
self.language = None
|
||||
self.doc_version = None
|
||||
|
||||
|
||||
def parse_properties(self, olefile):
|
||||
"""
|
||||
Parse standard properties of an OLE file, from the streams
|
||||
|
@ -833,7 +840,6 @@ class _OleDirectoryEntry(object):
|
|||
DIRENTRY_SIZE = 128
|
||||
assert struct.calcsize(STRUCT_DIRENTRY) == DIRENTRY_SIZE
|
||||
|
||||
|
||||
def __init__(self, entry, sid, olefile):
|
||||
"""
|
||||
Constructor for an _OleDirectoryEntry object.
|
||||
|
@ -929,8 +935,6 @@ class _OleDirectoryEntry(object):
|
|||
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
|
||||
|
@ -954,7 +958,6 @@ class _OleDirectoryEntry(object):
|
|||
# (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
|
||||
|
@ -998,7 +1001,6 @@ class _OleDirectoryEntry(object):
|
|||
# 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
|
||||
|
@ -1018,7 +1020,6 @@ class _OleDirectoryEntry(object):
|
|||
#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)",
|
||||
|
@ -1033,7 +1034,6 @@ class _OleDirectoryEntry(object):
|
|||
for kid in self.kids:
|
||||
kid.dump(tab + 2)
|
||||
|
||||
|
||||
def getmtime(self):
|
||||
"""
|
||||
Return modification time of a directory entry.
|
||||
|
@ -1047,7 +1047,6 @@ class _OleDirectoryEntry(object):
|
|||
return None
|
||||
return filetime2datetime(self.modifyTime)
|
||||
|
||||
|
||||
def getctime(self):
|
||||
"""
|
||||
Return creation time of a directory entry.
|
||||
|
@ -1134,7 +1133,6 @@ class OleFileIO(object):
|
|||
if filename:
|
||||
self.open(filename, write_mode=write_mode)
|
||||
|
||||
|
||||
def raise_defect(self, defect_level, message, exception_type=IOError):
|
||||
"""
|
||||
This method should be called for any defect found during file parsing.
|
||||
|
@ -1158,7 +1156,6 @@ class OleFileIO(object):
|
|||
# just record the issue, no exception raised:
|
||||
self.parsing_issues.append((exception_type, message))
|
||||
|
||||
|
||||
def _decode_utf16_str(self, utf16_str, errors='replace'):
|
||||
"""
|
||||
Decode a string encoded in UTF-16 LE format, as found in the OLE
|
||||
|
@ -1177,7 +1174,6 @@ class OleFileIO(object):
|
|||
# path_encoding=None, return the Unicode string as-is:
|
||||
return unicode_str
|
||||
|
||||
|
||||
def open(self, filename, write_mode=False):
|
||||
"""
|
||||
Open an OLE2 file in read-only or read/write mode.
|
||||
|
@ -1393,14 +1389,12 @@ class OleFileIO(object):
|
|||
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.
|
||||
|
@ -1426,7 +1420,6 @@ class OleFileIO(object):
|
|||
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
|
||||
|
@ -1464,7 +1457,6 @@ class OleFileIO(object):
|
|||
print(name, end=" ")
|
||||
print()
|
||||
|
||||
|
||||
def dumpsect(self, sector, firstindex=0):
|
||||
"Displays a sector in a human-readable form, for debugging purpose."
|
||||
if not DEBUG_MODE:
|
||||
|
@ -1501,7 +1493,6 @@ class OleFileIO(object):
|
|||
a.byteswap()
|
||||
return a
|
||||
|
||||
|
||||
def loadfat_sect(self, sect):
|
||||
"""
|
||||
Adds the indexes of the given sector to the FAT
|
||||
|
@ -1533,7 +1524,6 @@ class OleFileIO(object):
|
|||
self.fat = self.fat + nextfat
|
||||
return isect
|
||||
|
||||
|
||||
def loadfat(self, header):
|
||||
"""
|
||||
Load the FAT table.
|
||||
|
@ -1608,7 +1598,6 @@ class OleFileIO(object):
|
|||
debug('\nFAT:')
|
||||
self.dumpfat(self.fat)
|
||||
|
||||
|
||||
def loadminifat(self):
|
||||
"""
|
||||
Load the MiniFAT table.
|
||||
|
@ -1674,7 +1663,6 @@ class OleFileIO(object):
|
|||
self.raise_defect(DEFECT_FATAL, 'incomplete OLE sector')
|
||||
return sector
|
||||
|
||||
|
||||
def write_sect(self, sect, data, padding=b'\x00'):
|
||||
"""
|
||||
Write given sector to file on disk.
|
||||
|
@ -1701,7 +1689,6 @@ class OleFileIO(object):
|
|||
raise ValueError("Data is larger than sector size")
|
||||
self.fp.write(data)
|
||||
|
||||
|
||||
def loaddirectory(self, sect):
|
||||
"""
|
||||
Load the directory.
|
||||
|
@ -1737,7 +1724,6 @@ class OleFileIO(object):
|
|||
# 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.
|
||||
|
@ -1763,14 +1749,12 @@ class OleFileIO(object):
|
|||
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.
|
||||
|
@ -1806,7 +1790,6 @@ class OleFileIO(object):
|
|||
sectorsize=self.sectorsize, fat=self.fat,
|
||||
filesize=self._filesize)
|
||||
|
||||
|
||||
def _list(self, files, prefix, node, streams=True, storages=False):
|
||||
"""
|
||||
listdir helper
|
||||
|
@ -1835,7 +1818,6 @@ class OleFileIO(object):
|
|||
else:
|
||||
self.raise_defect(DEFECT_INCORRECT, 'The directory tree contains an entry which is not a stream nor a storage.')
|
||||
|
||||
|
||||
def listdir(self, streams=True, storages=False):
|
||||
"""
|
||||
Return a list of streams and/or storages stored in this file
|
||||
|
@ -1849,7 +1831,6 @@ class OleFileIO(object):
|
|||
self._list(files, [], self.root, streams, storages)
|
||||
return files
|
||||
|
||||
|
||||
def _find(self, filename):
|
||||
"""
|
||||
Returns directory entry of given filename. (openstream helper)
|
||||
|
@ -1881,7 +1862,6 @@ class OleFileIO(object):
|
|||
node = kid
|
||||
return node.sid
|
||||
|
||||
|
||||
def openstream(self, filename):
|
||||
"""
|
||||
Open a stream as a read-only file object (BytesIO).
|
||||
|
@ -1903,7 +1883,6 @@ class OleFileIO(object):
|
|||
raise IOError("this file is not a stream")
|
||||
return self._open(entry.isectStart, entry.size)
|
||||
|
||||
|
||||
def write_stream(self, stream_name, data):
|
||||
"""
|
||||
Write a stream to disk. For now, it is only possible to replace an
|
||||
|
@ -1953,7 +1932,7 @@ class OleFileIO(object):
|
|||
% (size, self.sectorsize, len(data_sector), size % self.sectorsize))
|
||||
assert(len(data_sector) % self.sectorsize == size % self.sectorsize)
|
||||
self.write_sect(sect, data_sector)
|
||||
## self.fp.write(data_sector)
|
||||
# self.fp.write(data_sector)
|
||||
# jump to next sector in the FAT:
|
||||
try:
|
||||
sect = self.fat[sect]
|
||||
|
@ -1964,7 +1943,6 @@ class OleFileIO(object):
|
|||
if sect != ENDOFCHAIN:
|
||||
raise IOError('incorrect last sector index in OLE stream')
|
||||
|
||||
|
||||
def get_type(self, filename):
|
||||
"""
|
||||
Test if given filename exists as a stream or a storage in the OLE
|
||||
|
@ -1984,7 +1962,6 @@ class OleFileIO(object):
|
|||
except:
|
||||
return False
|
||||
|
||||
|
||||
def getmtime(self, filename):
|
||||
"""
|
||||
Return modification time of a stream/storage.
|
||||
|
@ -2000,7 +1977,6 @@ class OleFileIO(object):
|
|||
entry = self.direntries[sid]
|
||||
return entry.getmtime()
|
||||
|
||||
|
||||
def getctime(self, filename):
|
||||
"""
|
||||
Return creation time of a stream/storage.
|
||||
|
@ -2016,7 +1992,6 @@ class OleFileIO(object):
|
|||
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
|
||||
|
@ -2032,7 +2007,6 @@ class OleFileIO(object):
|
|||
except:
|
||||
return False
|
||||
|
||||
|
||||
def get_size(self, filename):
|
||||
"""
|
||||
Return size of a stream in the OLE container, in bytes.
|
||||
|
@ -2049,7 +2023,6 @@ class OleFileIO(object):
|
|||
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
|
||||
|
@ -2057,7 +2030,6 @@ class OleFileIO(object):
|
|||
"""
|
||||
return self.root.name
|
||||
|
||||
|
||||
def getproperties(self, filename, convert_time=False, no_conversion=None):
|
||||
"""
|
||||
Return properties described in substream.
|
||||
|
@ -2295,11 +2267,11 @@ For more information, see http://www.decalage.info/olefile
|
|||
print('NOT a stream : type=%d' % st_type)
|
||||
print()
|
||||
|
||||
## for streamname in ole.listdir():
|
||||
## # print name using repr() to convert binary chars to \xNN:
|
||||
## print('-', repr('/'.join(streamname)),'-', end=' ')
|
||||
## print(ole.getmtime(streamname))
|
||||
## print()
|
||||
# for streamname in ole.listdir():
|
||||
# # print name using repr() to convert binary chars to \xNN:
|
||||
# print('-', repr('/'.join(streamname)),'-', end=' ')
|
||||
# print(ole.getmtime(streamname))
|
||||
# print()
|
||||
|
||||
print('Modification/Creation times of all directory entries:')
|
||||
for entry in ole.direntries:
|
||||
|
|
Loading…
Reference in New Issue
Block a user