Ñò
…n+Oc           @   sË  d  d k  Z  d  d k Z d d „ Z d d „ Z d Z d Z d Z d Z d Z d	 Z	 d
 Z
 d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d Z d  Z  d! Z! d" Z" d# Z# d$ Z$ d% Z% d& Z& d' Z' d( Z( d) Z) d* Z* d+ Z+ d, Z, d- Z- h  Z. x< e/ ƒ  i0 ƒ  D]+ \ Z1 Z2 e1 d  d. j o e1 e. e2 <n qBWd/ Z3 d0 e i f d1 „  ƒ  YZ4 d2 f  d3 „  ƒ  YZ5 d4 f  d5 „  ƒ  YZ6 e7 d6 j od  d k8 Z8 xñ e8 i9 d D]â Z: y¯ e6 e: ƒ Z; d7 d( GHe: GHd7 d( GHe; i< ƒ  x{ e; i= ƒ  D]m Z: e: d  d d8 j oR e: GHe; i> e: ƒ Z? e? i0 ƒ  Z? e? i@ ƒ  x! e? D] \ Z1 Z2 d9 Ge1 Ge2 GHqlWn q WWn* eA j
 o Z2 d: Gd; Ge: Gd7 Ge2 GHn XqÝWn d S(<   iÿÿÿÿNi    c         C   s$   t  |  | ƒ t  |  | d ƒ d >S(   Ni   i   (   t   ord(   t   ct   o(    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   i16*   s    c         C   sP   t  |  | ƒ t  |  | d ƒ d >t  |  | d ƒ d >t  |  | d ƒ d >S(   Ni   i   i   i   i   i   (   R    (   R   R   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   i32-   s    s   ÐÏà¡±ái   i   i   i   i   i   i   i   i	   i
   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i   i@   iA   iB   iC   iD   iE   iF   iG   iH   i   t   VT_s$   00020900-0000-0000-C000-000000000046t
   _OleStreamc           B   s   e  Z d  Z d „  Z RS(   sK  OLE2 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.
    c         C   s}   g  } xG | d j o9 | i  | | | ƒ | i | i | ƒ ƒ | | } q	 Wt i | d ƒ } t i i |  | |  ƒ d  S(   Niþÿÿÿt    (   t   seekt   appendt   readt   stringt   joint   StringIOt   __init__(   t   selft   fpt   sectt   sizet   offsett
   sectorsizet   fatt   data(    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR   c   s     (   t   __name__t
   __module__t   __doc__R   (    (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR   R   s   t   _OleDirectoryEntryc           B   s,   e  Z d  Z d „  Z d „  Z d d „ Z RS(   sº   OLE2 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.
    c         C   s  | | \ } } } } } } | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ g  |  _ | | d d } | d j oˆ|  i  g }	 | | d \ }
 } } x< |
 d j o. |	 i | ƒ |
 } | | d \ }
 } } q  Wx| |  i  j o|  i i t | | ƒ ƒ | | d \ }
 } } | d j oL | } x· | | d \ }
 } } |
 d j o Pn |	 i | ƒ |
 } q5qß xC |	 d } |	 d =| | d \ }
 } } | | j o Pn | } q{| | d \ }
 } } | | j o
 | } qß qß W|  i i	 ƒ  n d  S(   Ni   i   iÿÿÿÿ(
   t   sidt   namet   typeR   R   t   clsidt   kidsR	   R   t   sort(   R   t   sidlistR   R   R   R   R   t   sidsR   t   stackt   leftt   rightt   childt   ptr(    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR      sP    							  
	c         C   s   t  |  i | i ƒ S(   s   Compare entries by name(   t   cmpR   (   R   t   other(    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   __cmp__È   s    i    c         C   s³   d d d d d d g } d | t  |  i ƒ G| |  i G|  i d j o |  i Gd
 Gn H|  i d j o" |  i o d | d |  i GHn x" |  i D] } | i | d ƒ q” Wd S(   sA   Dump this entry, and all its subentries (for debug purposes only)s	   (invalid)s	   (storage)s   (stream)s   (lockbytes)s
   (property)s   (root)t    i   i   t   bytesi   s   {%s}N(   i   i   (   i   i   (   t   reprR   R   R   R   R   t   dump(   R   t   tabt   TYPESt   kid(    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR.   Í   s     
 (   R   R   R   R   R*   R.   (    (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR   x   s   	G	t	   OleFileIOc           B   s›   e  Z d  Z d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d „  Z d	 „  Z d
 „  Z d „  Z d d „ Z d „  Z d „  Z d „  Z RS(   s¡  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).
    c         C   s   | o |  i  | ƒ n d  S(   N(   t   open(   R   t   filename(    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR     s    c         C   s  t  | ƒ t  d ƒ j o t | d ƒ |  _ n
 | |  _ |  i i d ƒ } t | ƒ d j p | d  t j o t d ‚ n |  i | d d !ƒ } d t | d ƒ >|  _	 d t | d	 ƒ >|  _
 t | d
 ƒ |  _ |  i | ƒ |  i t | d ƒ ƒ d |  _ t | d ƒ |  _ d S(   s   Open an OLE2 fileR   t   rbi   i   s#   not an OLE2 structured storage filei   i   i   i    i8   i0   i<   N(   R   R3   R   R
   t   lent   MAGICt   IOErrort   _clsidR   R   t   minisectorsizeR   t   minisectorcutofft   loadfatt   loaddirectoryt   Nonet
   ministreamt   minifatsect(   R   R4   t   headerR   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR3   	  s    	$	c      	   C   s«   | d d !} g  } xˆ t  d t | ƒ d ƒ D]n } t | | ƒ } | d j p | d j o Pn |  i | ƒ } | t | d „ t  d t | ƒ d ƒ ƒ } q, W| |  _ d  S(   NiL   i   i    i   iþÿÿÿiÿÿÿÿc         S   s   t  | |  ƒ S(    (   R   (   t   it   s(    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   <lambda>6  s    (   t   rangeR6   R   t   getsectt   mapR   (   R   RA   R   R   RB   t   ixRC   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR<   *  s     /c         C   sF   |  i  |  i ƒ i ƒ  } t | d „ t d t | ƒ d ƒ ƒ |  _ d  S(   Nc         S   s   t  | |  ƒ S(    (   R   (   RB   RC   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyRD   ?  s    i    i   (   t   _openR@   R
   RG   RE   R6   t   minifat(   R   RC   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   loadminifat9  s    c         C   s.   |  i  i d |  i | ƒ |  i  i |  i ƒ S(   Ni   (   R   R   R   R
   (   R   R   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyRF   A  s    c         C   s   t  t | ƒ S(   N(   t   filterR    (   R   RC   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   _unicodeG  s    c   	   	   C   s  |  i  | ƒ } g  |  _ xÒ | i d ƒ } | p Pn t | d ƒ } |  i | d d t | d ƒ !ƒ } t | d ƒ t | d ƒ t | d ƒ f } t | d ƒ t | d	 ƒ } } |  i | d
 d !ƒ } |  i i | | | | | | f ƒ q t	 |  i d ƒ |  _
 d  S(   Ni€   iB   i    i@   iD   iH   iL   it   ix   iP   i`   (   RI   R!   R
   R    RM   R   R   R9   R	   R   t   root(	   R   R   R   t   entryR   R   t   ptrsR   R   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR=   N  s    	#*%c         C   s   |  i  i ƒ  d  S(   N(   RN   R.   (   R   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   dumpdirectorye  s    c         C   sj   | d t  | ƒ j o d Sd d d t | d ƒ t | d ƒ t | d ƒ f t t t | d d	 !ƒ ƒ S(
   Nt    R   s   %08X-%04X-%04X-%02X%02X-s   %02Xi   i    i   i   i   (   R6   R   R   t   tupleRG   R    (   R   R   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR9   j  s
    'c         C   sd   | | i  g } xM | i D]B } | i o |  i | | | ƒ q | i | d | i  g ƒ q Wd  S(   Ni   (   R   R   t   _listR	   (   R   t   filest   prefixt   nodeRO   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyRT   q  s    
 
c         C   sY   |  i  } xF | D]> } x/ | i D] } | i | j o Pq  q  Wt d ‚ | } q W| i S(   Ns   file not found(   RN   R   R   R8   R   (   R   R4   RW   R   R1   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   _find{  s    	 
 		
iÿÿÿc         C   sŠ   | |  i  j  oX |  i p+ |  i ƒ  |  i |  i d d ƒ |  _ n t |  i | | d |  i |  i ƒ St |  i | | d |  i	 |  i
 ƒ S(   Ni    i   i   (   R;   R?   RK   RI   R!   R   R:   RJ   R   R   R   (   R   t   startR   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyRI   ˆ  s    

!c         C   s    g  } |  i  | g  |  i ƒ | S(   s,   Return a list of streams stored in this file(   RT   RN   (   R   RU   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   listdirš  s    c   	      C   sX   |  i  | ƒ } |  i | \ } } } } } } | d j o t d ‚ n |  i | | ƒ S(   s(   Open a stream as a read-only file objecti   s   this file is not a stream(   RX   R!   R8   RI   (	   R   R4   t   slotR   R   R   R   R"   R   (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt
   openstream¤  s
    c      	   C   sh  |  i  | ƒ } h  } | i d ƒ } |  i | d d !ƒ } | i d ƒ } |  i | d  ƒ } | i t | d ƒ ƒ d | i t | i d ƒ ƒ d ƒ } xÉt t | d ƒ ƒ D]²} t | d | d ƒ } t | d | d ƒ }	 t | |	 ƒ }
 |
 t j o2 t | |	 d ƒ } | d	 j o | d
 } qVn'|
 t j o t | |	 d ƒ } n|
 t	 t
 f j o t | |	 d ƒ } nÙ|
 t j o t | |	 d ƒ } nµ|
 t t f j o4 t | |	 d ƒ } | |	 d |	 d | d !} nn|
 t j o0 t | |	 d ƒ } | |	 d |	 d | !} n1|
 t j o= t | |	 d ƒ } |  i | |	 d |	 d | d !ƒ } nç |
 t j oB t t | |	 d ƒ ƒ t t | |	 d ƒ ƒ d >} | d } n˜ |
 t j o t | |	 d ƒ } ns |
 t j o" |  i | |	 d |	 d !ƒ } nD |
 t j o0 t | |	 d ƒ } | |	 d |	 d | !} n d } | | | <q® W| S(   s(   Return properties described in substreami   i   i   i   i   s   ****i   i   i €  i   i   i   i    l   €1N(   R\   R
   R9   R   R   RE   t   VT_I2R   t   VT_UI2t   VT_I4t   VT_ERRORt   VT_UI4t   VT_BSTRt   VT_LPSTRt   VT_BLOBt	   VT_LPWSTRRM   t   VT_FILETIMEt   longt   VT_UI1R    t   VT_CLSIDt   VT_CFR>   (   R   R4   R   R   RC   R   t   fmtidRB   t   idR   R   t   valuet   count(    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   getproperties°  sZ    & !*4"N(   R   R   R   R>   R   R3   R<   RK   RF   RM   R=   RQ   R9   RT   RX   RI   RZ   R\   Ro   (    (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyR2   å   s    	!								
		
	t   __main__t   -s   s      s   ***s   cannot read(B   R   R   R   R   R7   t   VT_EMPTYt   VT_NULLR]   R_   t   VT_R4t   VT_R8t   VT_CYt   VT_DATERb   t   VT_DISPATCHR`   t   VT_BOOLt
   VT_VARIANTt
   VT_UNKNOWNt
   VT_DECIMALt   VT_I1Rh   R^   Ra   t   VT_I8t   VT_UI8t   VT_INTt   VT_UINTt   VT_VOIDt
   VT_HRESULTt   VT_PTRt   VT_SAFEARRAYt	   VT_CARRAYt   VT_USERDEFINEDRc   Re   Rf   Rd   t	   VT_STREAMt
   VT_STORAGEt   VT_STREAMED_OBJECTt   VT_STORED_OBJECTt   VT_BLOB_OBJECTRj   Ri   t	   VT_VECTORt   VTt   varst   itemst   kt   vt
   WORD_CLSIDR   R   R2   R   t   syst   argvt   filet   oleRQ   RZ   Ro   t   propsR    R8   (    (    (    s7   /usr/local/lib/python2.6/dist-packages/PIL/OleFileIO.pyt   <module>'   s˜                                    &mÿ  		
 
 