ó
¤ –Qc           @   si   d  Z  d d l Z d d l Z d d l Z d d l Z d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   sK   
Subclass of Archive that can be understood by a C program (see launch.c).
iÿÿÿÿNt   CTOCc           B   sS   e  Z d  Z d Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 RS(	   sy   
    A class encapsulating the table of contents of a CArchive.

    When written to disk, it is easily read from C.
    s   !iiiibcc         C   s   g  |  _  d  S(   N(   t   data(   t   self(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   __init__    s    c         C   s  t  j |  j ƒ } d } xö | t | ƒ k  rt  j |  j | | | | !ƒ \ } } } } } }	 | | }
 | | } t  j t |
 ƒ d | | | |
 !ƒ \ } | |
 } | j d ƒ } | d k  rç |  j j | | | | |	 | f ƒ q |  j j | | | | |	 | |  f ƒ q Wd S(   sa   
        Decode the binary string into an in memory list.

        S is a binary string.
        i    t   st    N(	   t   structt   calcsizet   ENTRYSTRUCTt   lent   unpackt   reprt   findR   t   append(   R   R   t   entrylent   pt   slent   dpost   dlent   ulent   flagt   typcdt   nmlent   nmt   pos(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt
   frombinary#   s    &

*
%c         C   sä   t  j |  j ƒ } g  } x¼ |  j D]± \ } } } } } } t | ƒ d }	 |	 | }
 |
 d d k rm d } n" d |
 d } d | } |	 | }	 | j t  j |  j t |	 ƒ d |	 | | | | | | | | ƒ ƒ q" Wd j | ƒ S(   s1   
        Return self as a binary string.
        i   i   i    R   R   t    (	   R   R   R   R   R	   R   t   packR   t   join(   R   R   t   rsltR   R   R   R   R   R   R   t   toclent   padt   padlen(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   tobinary?   s    "
	

 (c         C   sD   d d l  } | j j | ƒ } |  j j | | | | | | f ƒ d S(   sm  
        Add an entry to the table of contents.

        DPOS is data position.
        DLEN is data length.
        ULEN is the uncompressed data len.
        FLAG says if the data is compressed.
        TYPCD is the "type" of the entry (used by the C code)
        NM is the entry's name.

        This function is used only while creating an executable.
        iÿÿÿÿN(   t   os.patht   patht   normpathR   R   (   R   R   R   R   R   R   R   t   os(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   addZ   s    c         C   s   |  j  | S(   sJ   
        Return the table of contents entry (tuple) at index NDX.
        (   R   (   R   t   ndx(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   getp   s    c         C   s   |  j  | S(   N(   R   (   R   R'   (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   __getitem__v   s    c         C   s8   x1 t  |  j ƒ D]  \ } } | d | k r | Sq Wd S(   sc   
        Return the index of the toc entry with name NAME.

        Return -1 for failure.
        iÿÿÿÿ(   t	   enumerateR   (   R   t   namet   iR   (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyR   y   s    (   t   __name__t
   __module__t   __doc__R   R   R   R!   R&   R(   R)   R   (    (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyR       s   						t   CArchivec           B   s•   e  Z d  Z d Z d Z e Z d Z d d d d d „ Z	 d „  Z
 d „  Z d „  Z d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   sC  
    An Archive subclass that can hold arbitrary data.

    This class encapsulates all files that are bundled within an executable.
    It can contain ZlibArchive (Python .pyc files), dlls, Python C extensions
    and all other data files that are bundled in --onefile mode.

    Easily handled from C or from Python.
    s   MEI
i    i	   R   c         C   sV   | |  _  | |  _ d |  _ t j |  j ƒ |  _ d |  _ t t |  ƒ j	 | | ƒ d S(   s7  
        Constructor.

        archive_path path name of file (create empty CArchive if path is None).
        start        is the seekposition within PATH.
        len          is the length of the CArchive (if 0, then read till EOF).
        pylib_name   name of Python DLL which bootloader will use.
        s
   !8siiii64si    N(
   t   lengtht   _pylib_namet   _cookie_formatR   R   t   _cookie_sizet	   pkg_startt   superR0   R   (   R   t   archive_patht   startR1   t
   pylib_name(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyR   –   s    					c         C   sZ   |  j  j ƒ  |  j } |  j | ƒ |  j | ƒ |  j rI |  j | ƒ n  |  j  j ƒ  d S(   sâ   
        Finalize an archive which has been opened using _start_add_entries(),
        writing any needed padding and the table of contents.

        Overrides parent method because we need to save cookie and headers.
        N(   t   libt   tellR5   t   save_toct   save_cookiet   HDRLENt   update_headerst   close(   R   t   toc_pos(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt	   _finalize¶   s    	c         C   sœ   | j  |  _  | j  | j } d } | j j d ƒ x? | d k rs |  j j | j j t | | ƒ ƒ ƒ | | 8} q5 Wx! | j D] } |  j j | Œ  q~ Wd S(   sõ   
        Copy an entire archive into the current archive, updating TOC but
        NOT writing it, to allow additions of files to end of archive.
        Must be first action after _start_add_entries() since bootloader is
        first.
        i   i    N(	   R5   t   TOCPOSR:   t   seekt   writet   readt   mint   tocR&   (   R   t   archt   sizet   blksizet   tocentry(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt	   copy_fromÇ   s    %c         C   su  |  j  r) |  j j |  j |  j  d ƒ n |  j j d d ƒ |  j j ƒ  } |  j  r{ |  j j |  j |  j  |  j d ƒ n |  j j |  j d ƒ t j |  j |  j j	 |  j ƒ ƒ \ } } } } } } | |  j
 k rù t d |  j |  j j f ƒ ‚ n  | | |  _ |  j  rI| |  j  k s0|  j |  j k rIt d |  j ƒ ‚ qIn  | s^t d ƒ ‚ n  | | |  _ |  _ d S(   s¥   
        Verify that self is a valid CArchive.

        Magic signature is at end of the archive.

        This fuction is used by ArchiveViewer.py utility.
        i    i   s!   %s is not a valid %s archive files#   Problem with embedded archive in %ss/   Python library filename not defined in archive.N(   R1   R:   RD   R8   R;   R4   R   R
   R3   RF   t   MAGICt   RuntimeErrorR#   t	   __class__R-   R5   t   tocposR   (   R   t   filelent   magict   totallenRQ   R   t   pyversR9   (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt
   checkmagicÚ   s(    		 	'0	!c         C   sR   |  j  ƒ  |  _ |  j j |  j |  j ƒ |  j j |  j ƒ } |  j j | ƒ d S(   s9   
        Load the table of contents into memory.
        N(	   t   TOCTMPLTRH   R:   RD   R5   RQ   RF   R   R   (   R   t   tocstr(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   loadtocû   s    c   
      C   sÔ   t  | ƒ t  d ƒ k r= |  j j | ƒ } | d k rC d Sn | } |  j j | ƒ \ } } } } } } |  j j |  j | ƒ |  j j | ƒ }	 | d k r® t	 j
 |	 ƒ }	 n  | d k rÄ d |	 f S| d k |	 f S(   sù   
        Get the contents of an entry.

        NAME is an entry name OR the index to the TOC.

        Return the tuple (ispkg, contents).
        For non-Python resoures, ispkg is meaningless (and 0).
        Used by the import mechanism.
        R   iÿÿÿÿi   t   MN(   t   typeRH   R   t   NoneR(   R:   RD   R5   RF   t   zlibt
   decompress(
   R   R+   R'   R   R   R   R   R   R   R   (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   extract  s    
$
c         C   s=   g  } x0 |  j  D]% \ } } } } } } | j | ƒ q W| S(   s2   
        Return the names of the entries.
        (   RH   R   (   R   R   R   R   R   R   R   R   (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   contents   s    "c   
      C   sg  | d  \ } } } } yb | d k r4 d } d } nC | d k rb t  | d ƒ j ƒ  } | d } n t  | d	 ƒ j ƒ  } Wn) t k
 r£ d
 | | | | f GH‚  n Xt | ƒ } | t d ƒ k sÈ t ‚ | d k rì t j | |  j ƒ } n  t | ƒ } |  j	 j
 ƒ  }	 | d k r4| j d ƒ d k r4d } q4n  |  j j |	 | | | | | ƒ |  j	 j | ƒ d S(   sc  
        Add an ENTRY to the CArchive.

        ENTRY must have:
          entry[0] is name (under which it will be saved).
          entry[1] is fullpathname of the file.
          entry[2] is a flag for it's storage format (0==uncompressed,
          1==compressed)
          entry[3] is the entry's type code.
          Version 5:
            If the type code is 'o':
              entry[0] is the runtime option
              eg: v  (meaning verbose imports)
                  u  (menaing unbuffered)
                  W arg (warning option arg)
                  s  (meaning do site.py processing.
        i   t   ot   dR   i    R   t   rUs   
 t   rbs"   Cannot find ('%s', '%s', %s, '%s')i   i   t   ms   .__init__.pyiÿÿÿÿRZ   N(   Ra   Rb   (   t   openRF   t   IOErrorR	   t   ranget   AssertionErrorR]   t   compresst   LEVELR:   R;   R   RH   R&   RE   (
   R   t   entryR   t   pathnmR   R   R   R   R   t   where(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyR&   )  s.    	c         C   s;   | |  _  |  j j ƒ  } t | ƒ |  _ |  j j | ƒ d S(   s5   
        Save the table of contents to disk.
        N(   RQ   RH   R!   R	   R   R:   RE   (   R   RQ   RX   (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyR<   Z  s    	c         C   sq   | |  j  |  j } t j d d t j d } t j |  j |  j | | |  j  | |  j ƒ } |  j	 j
 | ƒ d S(   s™   
        Save the cookie for the bootlader to disk.

        CArchives can be opened from the end - the cookie points
        back to the start.
        i    i
   i   N(   R   R4   t   syst   version_infoR   R   R3   RN   R2   R:   RE   (   R   RQ   RT   RU   t   cookie(    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyR=   c  s
    c   	      C   s‘   |  j  j | ƒ } | d k r: t d | |  j f ƒ ‚ n  |  j  j | ƒ \ } } } } } } | rw t d | ƒ ‚ n  t |  j |  j | | ƒ S(   sˆ   
        Open a CArchive of name NAME embedded within this CArchive.

        This fuction is used by ArchiveViewer.py utility.
        iÿÿÿÿs   Member '%s' not found in %ss*   Cannot open compressed archive %s in place(   RH   R   t   KeyErrorR#   R(   t
   ValueErrorR0   R5   (	   R   R+   R'   R   R   R   R   R   R   (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   openEmbeddedr  s    $N(   R-   R.   R/   RN   R>   R    RW   Rk   R\   R   RB   RM   RV   RY   R_   R`   R&   R<   R=   Rt   (    (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyR0   …   s    	 			!						1			(	   R/   R   Ro   R]   t   pyi_archivet   objectR    t   ArchiveR0   (    (    (    sb   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\loader\pyi_carchive.pyt   <module>   s   m