Merge pull request #1160 from radarhere/health

Further health fixes
This commit is contained in:
Alex Clark 2015-04-01 06:06:47 -04:00
commit b9fb9449fb
3 changed files with 88 additions and 90 deletions

View File

@ -69,8 +69,8 @@ def bdf_char(f):
bitmap.append(s[:-1]) bitmap.append(s[:-1])
bitmap = b"".join(bitmap) bitmap = b"".join(bitmap)
[x, y, l, d] = [int(s) for s in props["BBX"].split()] [x, y, l, d] = [int(p) for p in props["BBX"].split()]
[dx, dy] = [int(s) for s in props["DWIDTH"].split()] [dx, dy] = [int(p) for p in props["DWIDTH"].split()]
bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y) bbox = (dx, dy), (l, -d-y, x+l, -d), (0, 0, x, y)

View File

@ -19,8 +19,8 @@
__version__ = "0.1" __version__ = "0.1"
from PIL import Image, ImageFile, OleFileIO from PIL import Image, ImageFile
from PIL.OleFileIO import i8, i32, MAGIC from PIL.OleFileIO import i8, i32, MAGIC, OleFileIO
# we map from colour field tuples to (mode, rawmode) descriptors # we map from colour field tuples to (mode, rawmode) descriptors

View File

@ -1243,7 +1243,7 @@ class OleFileIO:
debug( "Number of sectors in the file: %d" % self.nb_sect ) debug( "Number of sectors in the file: %d" % self.nb_sect )
# file clsid (probably never used, so we don't store it) # 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.sectorsize = self.SectorSize #1 << i16(header, 30)
self.minisectorsize = self.MiniSectorSize #1 << i16(header, 32) self.minisectorsize = self.MiniSectorSize #1 << i16(header, 32)
self.minisectorcutoff = self.MiniSectorCutoff # i32(header, 56) self.minisectorcutoff = self.MiniSectorCutoff # i32(header, 56)
@ -1561,7 +1561,7 @@ class OleFileIO:
## break ## break
## self.direntries.append(_OleDirectoryEntry(entry, sid, self)) ## self.direntries.append(_OleDirectoryEntry(entry, sid, self))
# load root entry: # load root entry:
root_entry = self._load_direntry(0) self._load_direntry(0)
# Root entry is the first entry: # Root entry is the first entry:
self.root = self.direntries[0] self.root = self.direntries[0]
# read and build all storage trees, starting from the root: # read and build all storage trees, starting from the root:
@ -1786,7 +1786,7 @@ class OleFileIO:
:returns: True if object exist, else False. :returns: True if object exist, else False.
""" """
try: try:
sid = self._find(filename) self._find(filename)
return True return True
except: except:
return False return False
@ -1842,11 +1842,11 @@ class OleFileIO:
try: try:
# header # header
s = fp.read(28) s = fp.read(28)
clsid = _clsid(s[8:24]) #clsid = _clsid(s[8:24])
# format id # format id
s = fp.read(20) s = fp.read(20)
fmtid = _clsid(s[:16]) #fmtid = _clsid(s[:16])
fp.seek(i32(s, 16)) fp.seek(i32(s, 16))
# get section # get section
@ -1983,8 +1983,6 @@ class OleFileIO:
if __name__ == "__main__": if __name__ == "__main__":
import sys
# [PL] display quick usage info if launched from command-line # [PL] display quick usage info if launched from command-line
if len(sys.argv) <= 1: if len(sys.argv) <= 1:
print(__doc__) print(__doc__)
@ -2001,89 +1999,89 @@ Options:
check_streams = False check_streams = False
for filename in sys.argv[1:]: for filename in sys.argv[1:]:
## try: #try:
# OPTIONS: # OPTIONS:
if filename == '-d': if filename == '-d':
# option to switch debug mode on: # option to switch debug mode on:
set_debug_mode(True) set_debug_mode(True)
continue continue
if filename == '-c': if filename == '-c':
# option to switch check streams mode on: # option to switch check streams mode on:
check_streams = True check_streams = True
continue continue
ole = OleFileIO(filename)#, raise_defects=DEFECT_INCORRECT) ole = OleFileIO(filename)#, raise_defects=DEFECT_INCORRECT)
print("-" * 68) print("-" * 68)
print(filename) print(filename)
print("-" * 68) print("-" * 68)
ole.dumpdirectory() 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(): for streamname in ole.listdir():
if streamname[-1][0] == "\005": # print name using repr() to convert binary chars to \xNN:
print(streamname, ": properties") print('-', repr('/'.join(streamname)),'-', end=' ')
props = ole.getproperties(streamname, convert_time=True) st_type = ole.get_type(streamname)
props = sorted(props.items()) if st_type == STGTY_STREAM:
for k, v in props: print('size %d' % ole.get_size(streamname))
#[PL]: avoid to display too large or binary values: # just try to read stream in memory:
if isinstance(v, (basestring, bytes)): ole.openstream(streamname)
if len(v) > 50: else:
v = v[:50] print('NOT a stream : type=%d' % st_type)
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() print()
# parse and display metadata: ## for streamname in ole.listdir():
meta = ole.get_metadata() ## # print name using repr() to convert binary chars to \xNN:
meta.dump() ## print('-', repr('/'.join(streamname)),'-', end=' ')
print() ## print(ole.getmtime(streamname))
#[PL] Test a few new methods: ## print()
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('Modification/Creation times of all directory entries:')
print('\nNon-fatal issues raised during parsing:') for entry in ole.direntries:
if ole.parsing_issues: if entry is not None:
for exctype, msg in ole.parsing_issues: print('- %s: mtime=%s ctime=%s' % (entry.name,
print('- %s: %s' % (exctype.__name__, msg)) entry.getmtime(), entry.getctime()))
else: print()
print('None')
# 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: ## except IOError as v:
## print("***", "cannot read", file, "-", v) ## print("***", "cannot read", file, "-", v)