OleFileIO
index
/Library/Python/2.7/site-packages/PIL/OleFileIO.py

# THIS IS WORK IN PROGRESS
#
# The Python Imaging Library
# $Id$
#
# stuff to deal with OLE2 Structured Storage files.  this module is
# used by PIL to read Image Composer and FlashPix files, but can also
# be used to read other files of this type.
#
# History:
# 1997-01-20 fl   Created
# 1997-01-22 fl   Fixed 64-bit portability quirk
# 2003-09-09 fl   Fixed typo in OleFileIO.loadfat (noted by Daniel Haertle)
# 2004-02-29 fl   Changed long hex constants to signed integers
#
# Notes:
# FIXME: sort out sign problem (eliminate long hex constants)
# FIXME: change filename to use "a/b/c" instead of ["a", "b", "c"]
# FIXME: provide a glob mechanism function (using fnmatchcase)
#
# Literature:
#
# "FlashPix Format Specification, Appendix A", Kodak and Microsoft,
#  September 1996.
#
# Quotes:
#
# "If this document and functionality of the Software conflict,
#  the actual functionality of the Software represents the correct
#  functionality" -- Microsoft, in the OLE format specification
#
# Copyright (c) Secret Labs AB 1997.
# Copyright (c) Fredrik Lundh 1997.
#
# See the README file for information on usage and redistribution.
#

 
Modules
       
StringIO
string

 
Classes
       
OleFileIO

 
class OleFileIO
    OLE container object
 
This class encapsulates the interface to an OLE 2 structured
storage file.  Use the listdir and openstream methods to access
the contents of this file.
 
Object names are given as a list of strings, one for each subentry
level.  The root entry should be omitted.  For example, the following
code extracts all image streams from a Microsoft Image Composer file:
 
    ole = OleFileIO("fan.mic")
 
    for entry in ole.listdir():
        if entry[1:2] == "Image":
            fin = ole.openstream(entry)
            fout = open(entry[0:1], "wb")
            while 1:
                s = fin.read(8192)
                if not s:
                    break
                fout.write(s)
 
You can use the viewer application provided with the Python Imaging
Library to view the resulting files (which happens to be standard
TIFF files).
 
  Methods defined here:
__init__(self, filename=None)
dumpdirectory(self)
getproperties(self, filename)
Return properties described in substream
getsect(self, sect)
listdir(self)
Return a list of streams stored in this file
loaddirectory(self, sect)
loadfat(self, header)
loadminifat(self)
open(self, filename)
Open an OLE2 file
openstream(self, filename)
Open a stream as a read-only file object

 
Functions
       
i16(c, o=0)
i32(c, o=0)

 
Data
        MAGIC = '\xd0\xcf\x11\xe0\xa1\xb1\x1a\xe1'
VT = {0: 'VT_EMPTY', 1: 'VT_NULL', 2: 'VT_I2', 3: 'VT_I4', 4: 'VT_R4', 5: 'VT_R8', 6: 'VT_CY', 7: 'VT_DATE', 8: 'VT_BSTR', 9: 'VT_DISPATCH', ...}
VT_BLOB = 65
VT_BLOB_OBJECT = 70
VT_BOOL = 11
VT_BSTR = 8
VT_CARRAY = 28
VT_CF = 71
VT_CLSID = 72
VT_CY = 6
VT_DATE = 7
VT_DECIMAL = 14
VT_DISPATCH = 9
VT_EMPTY = 0
VT_ERROR = 10
VT_FILETIME = 64
VT_HRESULT = 25
VT_I1 = 16
VT_I2 = 2
VT_I4 = 3
VT_I8 = 20
VT_INT = 22
VT_LPSTR = 30
VT_LPWSTR = 31
VT_NULL = 1
VT_PTR = 26
VT_R4 = 4
VT_R8 = 5
VT_SAFEARRAY = 27
VT_STORAGE = 67
VT_STORED_OBJECT = 69
VT_STREAM = 66
VT_STREAMED_OBJECT = 68
VT_UI1 = 17
VT_UI2 = 18
VT_UI4 = 19
VT_UI8 = 21
VT_UINT = 23
VT_UNKNOWN = 13
VT_USERDEFINED = 29
VT_VARIANT = 12
VT_VECTOR = 4096
VT_VOID = 24
WORD_CLSID = '00020900-0000-0000-C000-000000000046'
k = 'VT_UNKNOWN'
v = 13