From 1f5aeea463f1c5e436f2757ba53829a8c2911d81 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 1 Apr 2015 12:21:58 +1100 Subject: [PATCH 1/5] Fixed incorrect import in FpxImagePlugin --- PIL/FpxImagePlugin.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PIL/FpxImagePlugin.py b/PIL/FpxImagePlugin.py index e92ee89eb..ed0c20c4e 100644 --- a/PIL/FpxImagePlugin.py +++ b/PIL/FpxImagePlugin.py @@ -19,8 +19,8 @@ __version__ = "0.1" -from PIL import Image, ImageFile, OleFileIO -from PIL.OleFileIO import i8, i32, MAGIC +from PIL import Image, ImageFile +from PIL.OleFileIO import i8, i32, MAGIC, OleFileIO # we map from colour field tuples to (mode, rawmode) descriptors From 1199665033c93755653be3ebbe5e9467aa18f642 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 1 Apr 2015 12:29:20 +1100 Subject: [PATCH 2/5] Removed duplicate import from OleFileIO --- PIL/OleFileIO.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/PIL/OleFileIO.py b/PIL/OleFileIO.py index c1cc5d5b6..6a6b644bb 100755 --- a/PIL/OleFileIO.py +++ b/PIL/OleFileIO.py @@ -1983,8 +1983,6 @@ class OleFileIO: if __name__ == "__main__": - import sys - # [PL] display quick usage info if launched from command-line if len(sys.argv) <= 1: print(__doc__) From 68d9860921ce7b9b4d1204cd62a97b31af11c297 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 1 Apr 2015 12:42:39 +1100 Subject: [PATCH 3/5] Changed list comprehension variable name to avoid redefinition --- PIL/BdfFontFile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/PIL/BdfFontFile.py b/PIL/BdfFontFile.py index c52812450..0c1614e0f 100644 --- a/PIL/BdfFontFile.py +++ b/PIL/BdfFontFile.py @@ -69,8 +69,8 @@ def bdf_char(f): bitmap.append(s[:-1]) bitmap = b"".join(bitmap) - [x, y, l, d] = [int(s) for s in props["BBX"].split()] - [dx, dy] = [int(s) for s in props["DWIDTH"].split()] + [x, y, l, d] = [int(p) for p in props["BBX"].split()] + [dx, dy] = [int(p) for p in props["DWIDTH"].split()] bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y) From 2834b789820f419f3cd214956158372735fe9723 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 1 Apr 2015 17:22:44 +1100 Subject: [PATCH 4/5] Removed or commented unused variables from OleFileIO --- PIL/OleFileIO.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/PIL/OleFileIO.py b/PIL/OleFileIO.py index 6a6b644bb..ebdde80ca 100755 --- a/PIL/OleFileIO.py +++ b/PIL/OleFileIO.py @@ -1243,7 +1243,7 @@ class OleFileIO: debug( "Number of sectors in the file: %d" % self.nb_sect ) # file clsid (probably never used, so we don't store it) - clsid = _clsid(header[8:24]) + #clsid = _clsid(header[8:24]) self.sectorsize = self.SectorSize #1 << i16(header, 30) self.minisectorsize = self.MiniSectorSize #1 << i16(header, 32) self.minisectorcutoff = self.MiniSectorCutoff # i32(header, 56) @@ -1561,7 +1561,7 @@ class OleFileIO: ## break ## self.direntries.append(_OleDirectoryEntry(entry, sid, self)) # load root entry: - root_entry = self._load_direntry(0) + self._load_direntry(0) # Root entry is the first entry: self.root = self.direntries[0] # read and build all storage trees, starting from the root: @@ -1786,7 +1786,7 @@ class OleFileIO: :returns: True if object exist, else False. """ try: - sid = self._find(filename) + self._find(filename) return True except: return False @@ -1842,11 +1842,11 @@ class OleFileIO: try: # header s = fp.read(28) - clsid = _clsid(s[8:24]) + #clsid = _clsid(s[8:24]) # format id s = fp.read(20) - fmtid = _clsid(s[:16]) + #fmtid = _clsid(s[:16]) fp.seek(i32(s, 16)) # get section From bd3f036a5685e970d698d54770e05df37d2830b8 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 1 Apr 2015 17:48:26 +1100 Subject: [PATCH 5/5] Fixed many style problems in OleFileIO resulting from indentation --- PIL/OleFileIO.py | 158 +++++++++++++++++++++++------------------------ 1 file changed, 79 insertions(+), 79 deletions(-) diff --git a/PIL/OleFileIO.py b/PIL/OleFileIO.py index ebdde80ca..a08ae0ee3 100755 --- a/PIL/OleFileIO.py +++ b/PIL/OleFileIO.py @@ -1999,89 +1999,89 @@ Options: check_streams = False for filename in sys.argv[1:]: -## try: - # OPTIONS: - if filename == '-d': - # option to switch debug mode on: - set_debug_mode(True) - continue - if filename == '-c': - # option to switch check streams mode on: - check_streams = True - continue + #try: + # OPTIONS: + if filename == '-d': + # option to switch debug mode on: + set_debug_mode(True) + continue + if filename == '-c': + # option to switch check streams mode on: + check_streams = True + continue - ole = OleFileIO(filename)#, raise_defects=DEFECT_INCORRECT) - print("-" * 68) - print(filename) - print("-" * 68) - ole.dumpdirectory() + ole = OleFileIO(filename)#, raise_defects=DEFECT_INCORRECT) + print("-" * 68) + print(filename) + print("-" * 68) + ole.dumpdirectory() + for streamname in ole.listdir(): + if streamname[-1][0] == "\005": + print(streamname, ": properties") + props = ole.getproperties(streamname, convert_time=True) + props = sorted(props.items()) + for k, v in props: + #[PL]: avoid to display too large or binary values: + if isinstance(v, (basestring, bytes)): + if len(v) > 50: + v = v[:50] + if isinstance(v, bytes): + # quick and dirty binary check: + for c in (1,2,3,4,5,6,7,11,12,14,15,16,17,18,19,20, + 21,22,23,24,25,26,27,28,29,30,31): + if c in bytearray(v): + v = '(binary data)' + break + print(" ", k, v) + + if check_streams: + # Read all streams to check if there are errors: + print('\nChecking streams...') for streamname in ole.listdir(): - if streamname[-1][0] == "\005": - print(streamname, ": properties") - props = ole.getproperties(streamname, convert_time=True) - props = sorted(props.items()) - for k, v in props: - #[PL]: avoid to display too large or binary values: - if isinstance(v, (basestring, bytes)): - if len(v) > 50: - v = v[:50] - if isinstance(v, bytes): - # quick and dirty binary check: - for c in (1,2,3,4,5,6,7,11,12,14,15,16,17,18,19,20, - 21,22,23,24,25,26,27,28,29,30,31): - if c in bytearray(v): - v = '(binary data)' - break - print(" ", k, v) - - if check_streams: - # Read all streams to check if there are errors: - print('\nChecking streams...') - for streamname in ole.listdir(): - # print name using repr() to convert binary chars to \xNN: - print('-', repr('/'.join(streamname)),'-', end=' ') - st_type = ole.get_type(streamname) - if st_type == STGTY_STREAM: - print('size %d' % ole.get_size(streamname)) - # just try to read stream in memory: - ole.openstream(streamname) - else: - 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() - - print('Modification/Creation times of all directory entries:') - for entry in ole.direntries: - if entry is not None: - print('- %s: mtime=%s ctime=%s' % (entry.name, - entry.getmtime(), entry.getctime())) + # print name using repr() to convert binary chars to \xNN: + print('-', repr('/'.join(streamname)),'-', end=' ') + st_type = ole.get_type(streamname) + if st_type == STGTY_STREAM: + print('size %d' % ole.get_size(streamname)) + # just try to read stream in memory: + ole.openstream(streamname) + else: + print('NOT a stream : type=%d' % st_type) print() - # parse and display metadata: - meta = ole.get_metadata() - meta.dump() - print() - #[PL] Test a few new methods: - root = ole.get_rootentry_name() - print('Root entry name: "%s"' % root) - if ole.exists('worddocument'): - print("This is a Word document.") - print("type of stream 'WordDocument':", ole.get_type('worddocument')) - print("size :", ole.get_size('worddocument')) - if ole.exists('macros/vba'): - print("This document may contain VBA macros.") +## 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 parsing issues: - print('\nNon-fatal issues raised during parsing:') - if ole.parsing_issues: - for exctype, msg in ole.parsing_issues: - print('- %s: %s' % (exctype.__name__, msg)) - else: - print('None') + print('Modification/Creation times of all directory entries:') + for entry in ole.direntries: + if entry is not None: + print('- %s: mtime=%s ctime=%s' % (entry.name, + entry.getmtime(), entry.getctime())) + print() + + # parse and display metadata: + meta = ole.get_metadata() + meta.dump() + print() + #[PL] Test a few new methods: + root = ole.get_rootentry_name() + print('Root entry name: "%s"' % root) + if ole.exists('worddocument'): + print("This is a Word document.") + print("type of stream 'WordDocument':", ole.get_type('worddocument')) + print("size :", ole.get_size('worddocument')) + if ole.exists('macros/vba'): + print("This document may contain VBA macros.") + + # print parsing issues: + print('\nNon-fatal issues raised during parsing:') + if ole.parsing_issues: + for exctype, msg in ole.parsing_issues: + print('- %s: %s' % (exctype.__name__, msg)) + else: + print('None') ## except IOError as v: ## print("***", "cannot read", file, "-", v)