*ec@sddlmZddlZddlZddlmZeek rMeZ nej Z ej Z ej ZdZdZdZdZdZd Zd Zd Zd Zd ZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(dZ)dZ*d Z+d!Z,d"Z-d#Z.d$Z/d%Z0d&Z1d'Z2d(Z3d)Z4d*Z5d+Z6d,Z7d-Z8iZ9x@e:e;j<D])\Z=Z>e=d d.kre=e9e>eHd9e=e>qWnqjWWn)eNk r Z>eHd:d;eFd7e>nXqWndS(<i(tprint_functionN(t_binarysࡱiiiiiiiiii i i i i iiiiiiiiiiiiiiiiii@iAiBiCiDiEiFiGiHitVT_s$00020900-0000-0000-C000-000000000046t _OleStreamcBseZdZdZRS(sKOLE2 Stream Returns a read-only file object which can be used to read the contents of a OLE stream. To open a stream, use the openstream method in the OleFile class. This function can be used with either ordinary streams, or ministreams, depending on the offset, sectorsize, and fat table arguments. cCsxg}xE|dkrM|j||||j|j|||}q Wdj|}tjj||| dS(Nit(tseektappendtreadtjointiotBytesIOt__init__(tselftfptsecttsizetoffsett sectorsizetfattdata((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyR gs(t__name__t __module__t__doc__R (((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyRVs t_OleDirectoryEntrycBs,eZdZdZdZddZRS(sOLE2 Directory Entry Encapsulates a stream directory entry. Note that the constructor builds a tree of all subentries, so we only have to call it with the root object. cCs||\}}}}}}||_||_||_||_||_||_g|_||dd}|dkr|jg} ||d\} } } x:| dkr| j|| }||d\} } } qWx||jkr|jjt||||d\} } } | dkrw| }xt rs||d\} } } | dkr]Pn| j|| }q0WqxHt r| d} | d=|| d\} } } | |krPn| }qzW||d\} } } | | kr| }qqW|jj ndS(Niii( tsidtnamettypeRRtclsidtkidsRRtTruetsort(R tsidlistRRRRRtsidsRtstacktlefttrighttchildtptr((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyR sL                     cCst|j|jS(sCompare entries by name(tcmpR(R tother((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyt__cmp__sicCsddddddg}td|t|j||jdd|jdkrkt|jd ddnt|jdkr|jrtd|d |jnx"|jD]}|j|d qWdS(sADump this entry, and all its subentries (for debug purposes only)s (invalid)s (storage)s(stream)s (lockbytes)s (property)s(root)t tendiitbytesis{%s}N(ii(ii(tprinttreprRRRRRtdump(R ttabtTYPEStkid((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyR.s  +(RRRR R(R.(((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyR|s G t OleFileIOcBseZdZddZdZdZdZdZdZ dZ dZ d Z d Z d Zd d ZdZdZdZRS(sOLE 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). cCs|r|j|ndS(N(topen(R tfilename((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyR scCst|tr$t|d|_n ||_|jjd}t|dksa|d tkrptdn|j|dd!}dt |d>|_ dt |d>|_ t |d |_ |j||jt |d d |_t |d |_d S( sOpen an OLE2 filetrbiis#not an OLE2 structured storage fileiiii i8i0i<N(t isinstancetstrR3R RtlentMAGICtIOErrort_clsidti16Rtminisectorsizeti32tminisectorcutofftloadfatt loaddirectorytNonet ministreamt minifatsect(R R4theaderR((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyR3 s "  cCs|dd!}g}xtdt|dD]x}t||}|dksY|dkr]Pn|j|}|gtdt|dD]}t||^q}q,W||_dS(NiLiiiii(trangeR8R>tgetsectR(R RERRtitixts((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyR@.s <cCsS|j|jj}gtdt|dD]}t||^q1|_dS(Nii(t_openRDRRFR8R>tminifat(R RJRH((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyt loadminifat=scCs.|jjd|j||jj|jS(Ni(R RRR(R R((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyRGEscCs6ttkr%|jdjddS|jdSdS(Nsutf-16slatin-1treplace(R+R7tdecodetencode(R RJ((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyt_unicodeKs c Cs |j|}g|_xtr|jd}|s:Pnt|d}|j|ddt|d!}t|dt|dt|df}t|dt|d }}|j|d d !}|jj ||||||fqWt |jd|_ dS( NiiBii@iDiHiLitixiPi`( RKRRRti8RQR<R>R;RRtroot( R RR tentryRRtptrsRR((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyRAUs  #*&cCs|jjdS(N(RSR.(R ((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyt dumpdirectorylscCsh|dt|krdSdddt|dt|dt|dfttt|dd !S( NtRs%08X-%04X-%04X-%02X%02X-s%02Xiiiii(R8R>R<ttupletmapRR(R R((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyR;qs  'cCsb||jg}xK|jD]@}|jr?|j|||q|j|d|jgqWdS(Ni(RRt_listR(R tfilestprefixtnodeRT((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyRZxs  cCsZ|j}xG|D]?}x0|jD]}|j|kr Pq q Wtd|}qW|jS(Nsfile not found(RSRRR:R(R R4R]RR1((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyt_finds    icCs||jkrd|jsB|j|j|jdd|_nt|j||d|j|jSt|j||d|j |j S(Niii( R?RCRMRKRRR=RLR RR(R tstartR((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyRKs   cCs g}|j|g|j|S(s,Return a list of streams stored in this file(RZRS(R R[((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pytlistdirsc CsY|j|}|j|\}}}}}}|dkrItdn|j||S(s(Open a stream as a read-only file objectisthis file is not a stream(R^RR:RK( R R4tslotRRRRR R((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyt openstreams  c CsP|j|}i}|jd}|j|dd!}|jd}|j|d }|jt|dd|jt|jdd}xtt|dD]}t|d|d}t|d|d} t|| } | tkr,t|| d} | d kr>| d } q>n| tkrNt|| d} n| t t fkrvt|| d} n| t krt|| d} n| t t fkrt|| d} || d| d| d !} na| tkrt|| d} || d| d| !} n&| tkr`t|| d} |j|| d| d| d !} n| tkrtt|| dtt|| dd >} | d} n| tkrt|| d} nn| tkr|j|| d| d!} nA| tkr8t|| d} || d| d| !} nd} | ||RFtVT_I2R<tVT_UI2tVT_I4tVT_ERRORtVT_UI4tVT_BSTRtVT_LPSTRtVT_BLOBt VT_LPWSTRRQt VT_FILETIMEtlongtVT_UI1RRtVT_CLSIDtVT_CFRB( R R4R RRJRtfmtidRHtidRRtvaluetcount((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyt getpropertiessX&       ) 4   ! N(RRRRBR R3R@RMRGRQRARVR;RZR^RKR`RbRu(((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyR2s   !        t__main__t-ss s***s cannot read(Ot __future__RR tsystPILRR7R+tintRmRRti16leR<ti32leR>R9tVT_EMPTYtVT_NULLRcRetVT_R4tVT_R8tVT_CYtVT_DATERht VT_DISPATCHRftVT_BOOLt VT_VARIANTt VT_UNKNOWNt VT_DECIMALtVT_I1RnRdRgtVT_I8tVT_UI8tVT_INTtVT_UINTtVT_VOIDt VT_HRESULTtVT_PTRt VT_SAFEARRAYt VT_CARRAYtVT_USERDEFINEDRiRkRlRjt VT_STREAMt VT_STORAGEtVT_STREAMED_OBJECTtVT_STORED_OBJECTtVT_BLOB_OBJECTRpRot VT_VECTORtVTtlisttvarstitemstktvt WORD_CLSIDR RRR2RtargvtfiletoleR,RVR`RutpropstsortedR:(((s3/usr/lib64/python2.7/site-packages/PIL/OleFileIO.pyt's       "&m