
6	Pc        	   @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l	 Z	 d d l
 Z
 y d d l Z e j Z Wn  e k
 r e Z e j Z n Xd d d d d d d	 d
 d g	 Z d e f d     YZ d e f d     YZ e Z d d >d Z d d >Z d d >d Z d Z d Z d Z d Z e j e  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( e j e'  Z) d Z* d Z+ d Z, d Z- d Z. d Z/ d Z0 d Z1 d Z2 d Z3 d Z4 d Z5 d  Z6 d! Z7 d" Z8 d# Z9 d Z: d$ Z; d% Z< d& Z= d' Z> e j e=  Z? d Z@ d ZA d ZB d ZC d ZD d ZE d ZF d ZG d ZH d ZI d ZJ d ZK d( ZL d) ZM e j eL  ZN d* ZO d+ ZP e j eO  ZQ d ZR d ZS d ZT d ZU d ZV d ZW d ZX d ZY d ZZ d Z[ d,   Z\ d-   Z] d.   Z^ d/   Z_ d e` f d0     YZa d1 f  d2     YZb d3 e	 jc f d4     YZd d	 f  d5     YZe d
 ee f d6     YZf e d7  Zg eh d8 k reg   n  d S(9   s   
Read and write ZIP files.
iNt
   BadZipfilet   errort
   ZIP_STOREDt   ZIP_DEFLATEDt
   is_zipfilet   ZipInfot   ZipFilet	   PyZipFilet   LargeZipFilec           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s   /usr/lib/python2.7/zipfile.pyR       s   c           B   s   e  Z d  Z RS(   su   
    Raised when writing a zipfile, the zipfile requires ZIP64 extensions
    and those extensions are disabled.
    (   R	   R
   t   __doc__(    (    (    s   /usr/lib/python2.7/zipfile.pyR      s   i   i   i   i    i   s   <4s4H2LHs   PKi   i   i   i   i   i   i	   s   <4s4B4HL2L5H2Ls   PKi
   i   i   i   i   i   i   i   s   <4s2B4HL2L2Hs   PKs   <4sLQLs   PKs
   <4sQ2H2L4Qs   PKc         C   s,   y t  |   r t SWn t k
 r' n Xt S(   N(   t   _EndRecDatat   Truet   IOErrort   False(   t   fp(    (    s   /usr/lib/python2.7/zipfile.pyt   _check_zipfile   s    c         C   sg   t  } yI t |  d  r* t d |   } n$ t |  d   } t |  } Wd QXWn t k
 rb n X| S(   s   Quickly see if a file is a ZIP file by checking the magic number.

    The filename argument may be a file or file-like object too.
    t   readR   t   rbN(   R   t   hasattrR   t   openR   (   t   filenamet   resultR   (    (    s   /usr/lib/python2.7/zipfile.pyR      s    c         C   sB  y |  j  | t d  Wn t k
 r, | SX|  j t  } t j t |  \ } } } } | t k rj | S| d k s | d k r t d   n  |  j  | t t	 d  |  j t	  } t j t
 |  \
 } } }	 }
 } } } } } } | t k r | S| | t <| | t <| | t <| | t <| | t <| | t <| | t <| S(   sM   
    Read the ZIP64 end-of-archive records and use that to update endrec
    i   i    i   s3   zipfiles that span multiple disks are not supported(   t   seekt   sizeEndCentDir64LocatorR   R   t   structt   unpackt   structEndArchive64Locatort   stringEndArchive64LocatorR    t   sizeEndCentDir64t   structEndArchive64t   stringEndArchive64t   _ECD_SIGNATUREt   _ECD_DISK_NUMBERt   _ECD_DISK_STARTt   _ECD_ENTRIES_THIS_DISKt   _ECD_ENTRIES_TOTALt	   _ECD_SIZEt   _ECD_OFFSET(   t   fpint   offsett   endrect   datat   sigt   disknot   relofft   diskst   szt   create_versiont   read_versiont   disk_numt   disk_dirt   dircountt	   dircount2t   dirsizet	   diroffset(    (    s   /usr/lib/python2.7/zipfile.pyt   _EndRecData64   s.    0






c   	      C   s  |  j  d d  |  j   } y |  j  t d  Wn t k
 rE d	 SX|  j   } | d d !t k r | d d k r t j t	 |  } t
 |  } | j d  | j | t  t |  t |  St | d
 t d  } |  j  | d  |  j   } | j t  } | d k r| | | t !} t
 t j t	 |   } | t } | | t | t | !} | j |  | j | |  t |  | | | |  Sd	 S(   s   Return data from the "End of Central Directory" record, or None.

    The data is a list of the nine items in the ZIP "End of central dir"
    record followed by a tenth item, the file seek offset of this record.i    i   i   it     t    i   i   Ni   (   R   t   tellt   sizeEndCentDirR   t   NoneR   t   stringEndArchiveR   R   t   structEndArchivet   listt   appendR9   t   maxt   rfindt   _ECD_COMMENT_SIZE(	   R(   t   filesizeR+   R*   t   maxCommentStartt   startt   recDatat   commentSizet   comment(    (    s   /usr/lib/python2.7/zipfile.pyR      s6    #
c           B   sG   e  Z d  Z d Z d d d  Z d   Z d   Z d   Z d   Z RS(   s>   Class with attributes describing each file in the ZIP archive.t   orig_filenameR   t	   date_timet   compress_typeRK   t   extrat   create_systemR1   t   extract_versiont   reservedt	   flag_bitst   volumet   internal_attrt   external_attrt   header_offsett   CRCt   compress_sizet	   file_sizet	   _raw_timet   NoNamei  i   i    c         C   s  | |  _  | j t d   } | d k r: | d | !} n  t j d k rp t j | k rp | j t j d  } n  | |  _ | |  _ t |  _	 d |  _
 d |  _ t j d k r d |  _ n	 d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d  S(   Ni    t   /R;   t   win32i   i   (   RL   t   findt   chrt   ost   sept   replaceR   RM   R   RN   RK   RO   t   syst   platformRP   R1   RQ   RR   RS   RT   RU   RV   (   t   selfR   RM   t	   null_byte(    (    s   /usr/lib/python2.7/zipfile.pyt   __init__  s*    													c         C   s  |  j  } | d d d >| d d >B| d B} | d d >| d	 d >B| d d B} |  j d
 @rs d } } } n |  j } |  j } |  j } |  j } | t k s | t k rd } | t j | d t j	 |  d	 | |  } d } d } t
 d |  j  |  _ t
 d |  j  |  _ n  |  j   \ }	 }
 t j t t |  j |  j |
 |  j | | | | | t |	  t |   } | |	 | S(   s'   Return the per-file header as a string.i    i  i	   i   i   i   i   i   i   i   s   <HHQQl    i-   (   RM   RS   RX   RY   RZ   RO   t   ZIP64_LIMITR   t   packt   calcsizeRC   RQ   R1   t   _encodeFilenameFlagst   structFileHeadert   stringFileHeaderRR   RN   t   len(   Rf   t   dtt   dosdatet   dostimeRX   RY   RZ   RO   t   fmtR   RS   t   header(    (    s   /usr/lib/python2.7/zipfile.pyt
   FileHeader;  s0    	&&				 c         C   st   t  |  j t  r` y |  j j d  |  j f SWqp t k
 r\ |  j j d  |  j d Bf SXn |  j |  j f Sd  S(   Nt   asciis   utf-8i   (   t
   isinstanceR   t   unicodet   encodeRS   t   UnicodeEncodeError(   Rf   (    (    s   /usr/lib/python2.7/zipfile.pyRl   ]  s    !c         C   s(   |  j  d @r |  j j d  S|  j Sd  S(   Ni   s   utf-8(   RS   R   t   decode(   Rf   (    (    s   /usr/lib/python2.7/zipfile.pyt   _decodeFilenamef  s    c         C   sw  |  j  } t j } x^| rr| d | d   \ } } | d k ra| d k re | d | d d ! } no | d k r | d | d d	 ! } nJ | d
 k r | d | d d ! } n% | d k r d } n t d | f  d } |  j d k r| | |  _ | d 7} n  |  j d k r,| | |  _ | d 7} n  |  j d k ra|  j } | | |  _ | d 7} qan  | | d } q Wd  S(   Ns   <HHi   i   i   s   <QQQi   i   s   <QQi   i   s   <Qi   i    s   Corrupt extra field %sl    l    (    (   l    l    (   RO   R   R   t   RuntimeErrorRZ   RY   RW   (   Rf   RO   R   t   tpt   lnt   countst   idxt   old(    (    s   /usr/lib/python2.7/zipfile.pyt   _decodeExtral  s4    					(   s   orig_filenames   filenames	   date_times   compress_types   comments   extras   create_systems   create_versions   extract_versions   reserveds	   flag_bitss   volumes   internal_attrs   external_attrs   header_offsets   CRCs   compress_sizes	   file_sizes	   _raw_time(   i  i   i   i    i    i    (	   R	   R
   R   t	   __slots__Rh   Ru   Rl   R|   R   (    (    (    s   /usr/lib/python2.7/zipfile.pyR      s2                     &	"			t   _ZipDecrypterc           B   sD   e  Z d  Z d   Z e   Z d   Z d   Z d   Z d   Z RS(   s  Class to handle decryption of files stored within a ZIP archive.

    ZIP supports a password-based form of encryption. Even though known
    plaintext attacks have been found against it, it is still useful
    to be able to get data out of such a file.

    Usage:
        zd = _ZipDecrypter(mypwd)
        plain_char = zd(cypher_char)
        plain_text = map(zd, cypher_text)
    c          C   s   d }  d g d } xh t  d  D]Z } | } xA t  d  D]3 } | d @r^ | d ?d @|  A} q9 | d ?d @} q9 W| | | <q  W| S(   s   Generate a CRC-32 table.

        ZIP encryption uses the CRC32 one-byte primitive for scrambling some
        internal keys. We noticed that a direct implementation is faster than
        relying on binascii.crc32().
        l    q[ i    i   i   i   i(   t   range(   t   polyt   tablet   it   crct   j(    (    s   /usr/lib/python2.7/zipfile.pyt   _GenerateCRCTable  s    
c         C   s%   | d ?d @|  j  | t |  Ad @AS(   s(   Compute the CRC32 primitive on one byte.i   i i   (   t   crctablet   ord(   Rf   t   chR   (    (    s   /usr/lib/python2.7/zipfile.pyt   _crc32  s    c         C   s=   d |  _  d |  _ d |  _ x | D] } |  j |  q" Wd  S(   NixV4igE#ixV4(   t   key0t   key1t   key2t   _UpdateKeys(   Rf   t   pwdt   p(    (    s   /usr/lib/python2.7/zipfile.pyRh     s
    			c         C   sx   |  j  | |  j  |  _ |  j |  j d @d @|  _ |  j d d d @|  _ |  j  t |  j d ?d @ |  j  |  _ d  S(   Ni   l    ii   i   (   R   R   R   R`   R   (   Rf   t   c(    (    s   /usr/lib/python2.7/zipfile.pyR     s    c         C   sP   t  |  } |  j d B} | | | d Ad ?d @A} t |  } |  j |  | S(   s   Decrypt a single character.i   i   i   i   (   R   R   R`   R   (   Rf   R   t   k(    (    s   /usr/lib/python2.7/zipfile.pyt   __call__  s    (	   R	   R
   R   R   R   R   Rh   R   R   (    (    (    s   /usr/lib/python2.7/zipfile.pyR     s   					t
   ZipExtFilec           B   sx   e  Z d  Z d d >Z d Z e j d  Z d d  Z	 d d  Z
 d d  Z d	   Z d d
  Z d   Z d   Z RS(   sZ   File-like object for reading an archive member.
       Is returned by ZipFile.open().
    i   i   i   s*   ^(?P<chunk>[^\r\n]+)|(?P<newline>\n|\r\n?)c         C   s  | |  _  | |  _ | j |  _ | j |  _ | j |  _ |  j t k rZ t j	 d  |  _
 n  d |  _ d |  _ d |  _ d | k |  _ d  |  _ |  j d  k	 r |  j d 8_ n  | |  _ | j |  _ t | d  r | j |  _ t d  d @|  _ n	 d  |  _ d  S(   NiR;   i    t   Ui   RX   l    (   t   _fileobjt
   _decrypterRN   t   _compress_typeRY   t   _compress_sizet   _compress_leftR   t   zlibt   decompressobjt   _decompressort   _unconsumedt   _readbuffert   _offsett
   _universalR>   t   newlinest   modeR   t   nameR   RX   t   _expected_crct   crc32t   _running_crc(   Rf   t   fileobjR   t   zipinfot	   decrypter(    (    s   /usr/lib/python2.7/zipfile.pyRh     s(    							ic         C   s  |  j  ra | d k  ra |  j j d |  j  d } | d k ra |  j |  j | !} | |  _ | Sn  |  j  s} t j j |  |  Sd } x| d k  s t |  | k  r|  j d  } | d k r | S|  j	 j
 |  } | j d  } | d k	 rJ|  j d k rg  |  _ n  | |  j k r-|  j j |  n  |  j t |  7_ | d S| j d  } | d k r|| | t |   } n  |  j t |  7_ | | 7} q W| S(	   sr   Read and return a line from the stream.

        If limit is specified, at most limit bytes will be read.
        i    s   
i   R;   i   t   newlinet   chunkN(   R   R   R_   R   t   iot   BufferedIOBaset   readlineRo   t   peekt   PATTERNt   searcht   groupR>   R   RB   (   Rf   t   limitR   t   linet	   readaheadt   matchR   R   (    (    s   /usr/lib/python2.7/zipfile.pyR     s8    		!
c         C   s[   | t  |  j  |  j k rC |  j |  } |  j t  |  8_ n  |  j |  j |  j d !S(   s6   Returns buffered bytes without advancing the position.i   (   Ro   R   R   R   (   Rf   t   nR   (    (    s   /usr/lib/python2.7/zipfile.pyR   ,  s    c         C   s   t  S(   N(   R   (   Rf   (    (    s   /usr/lib/python2.7/zipfile.pyt   readable5  s    c         C   s   d } | d k r d } n  xz t r | d k  rB |  j |  } n2 | t |  k rp |  j | t |   } n | St |  d k r | S| | 7} q Wd S(   s   Read and return up to n bytes.
        If the argument is omitted, None, or negative, data is read and returned until EOF is reached..
        R;   ii    N(   R>   R   t   read1Ro   (   Rf   R   t   bufR+   (    (    s   /usr/lib/python2.7/zipfile.pyR   8  s    		c         C   s^   |  j  d  k r d  St | |  j  d @|  _ | rZ |  j |  j  k rZ t d |  j   n  d  S(   Nl    s   Bad CRC-32 for file %r(   R   R>   R   R   R    R   (   Rf   t   newdatat   eof(    (    s   /usr/lib/python2.7/zipfile.pyt   _update_crcJ  s
    c      
   C   sg  | d k  s | d k r$ |  j } n  t |  j  |  j } |  j d k rW| | t |  j  k rW| | t |  j  } t | |  j  } t	 | |  j  } |  j
 j |  } |  j t |  8_ | r |  j d k	 r d j t |  j |   } n  |  j t k rE|  j | d |  j d k |  j |  j | |  _ d |  _ qW|  j | 7_ n  t |  j  d k r4| | k r4|  j t k r4|  j j |  j t | | |  j   } |  j j |  _ t |  j  d k o|  j d k } | r| |  j j   7} n  |  j | d | |  j |  j | |  _ d |  _ n  |  j |  j |  j | !} |  j t |  7_ | S(   s7   Read up to n bytes with at most one read() system call.i    R;   R   N(   R>   t   MAX_NRo   R   R   R   R   RC   t   MIN_READ_SIZEt   minR   R   R   t   joint   mapR   R   R   R   R   t
   decompresst   unconsumed_tailt   flush(   Rf   R   t   len_readbuffert   nbytesR+   R   (    (    s   /usr/lib/python2.7/zipfile.pyR   T  s>    (!	$i   N(   R	   R
   R   R   R   t   ret   compileR   R>   Rh   R   R   R   R   R   R   (    (    (    s   /usr/lib/python2.7/zipfile.pyR     s   
 2			
c           B   s   e  Z d  Z d Z d e e 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 d d  Z d d d  Z d d d d  Z d   Z d   Z d d d  Z d d  Z d   Z d   Z RS(   sd   Class with methods to open, read, write, close, list zip files.

    z = ZipFile(file, mode="r", compression=ZIP_STORED, allowZip64=False)

    file: Either the path to the file, or a file-like object.
          If it is a path, the file will be opened and closed by ZipFile.
    mode: The mode can be either read "r", write "w" or append "a".
    compression: ZIP_STORED (no compression) or ZIP_DEFLATED (requires zlib).
    allowZip64: if True ZipFile will create files with ZIP64 extensions when
                needed, otherwise it will raise an exception when this would
                be necessary.

    t   rc         C   sB  | d k r t  d   n  | t k r* n* | t k rK t sT t  d  qT n	 t  d  | |  _ t |  _ d |  _ i  |  _ g  |  _	 | |  _
 | j d d	  d |  _ } d |  _ d	 |  _ t | t  rXd |  _ | |  _ i d
 d 6d d 6d d 6} y t | | |  |  _ Wqt k
 rT| d k rNd } } t | | |  |  _ qU  qXn' d |  _ | |  _ t | d d  |  _ | d k r|  j   n | d k rt |  _ n | d k ry$ |  j   |  j j |  j d  Wq>t k
 r|  j j d d  t |  _ q>Xn+ |  j s5|  j j   d |  _ n  t  d  d S(   s>   Open the ZIP file with mode read "r", write "w" or append "a".R   t   wt   as(   ZipFile() requires mode "r", "w", or "a"s.   Compression requires the (missing) zlib modules(   That compression method is not supportedi    t   bR;   R   t   wbs   r+bi   R   i   s   Mode must be "r", "w" or "a"N(   R   R   R   (   R}   R   R   R   t   _allowZip64R   t
   _didModifyt   debugt
   NameToInfot   filelistt   compressionRc   R   R>   R   RK   Rw   t
   basestringt   _filePassedR   R   R   R   t   getattrt   _GetContentsR   t   _RealGetContentsR   t	   start_dirR    t   close(   Rf   t   fileR   R   t
   allowZip64t   keyt   modeDict(    (    s   /usr/lib/python2.7/zipfile.pyRh     s^    											

		
	c         C   s   |  S(   N(    (   Rf   (    (    s   /usr/lib/python2.7/zipfile.pyt	   __enter__  s    c         C   s   |  j    d  S(   N(   R   (   Rf   t   typet   valuet	   traceback(    (    s   /usr/lib/python2.7/zipfile.pyt   __exit__  s    c         C   sK   y |  j    Wn6 t k
 rF |  j s@ |  j j   d |  _ n    n Xd S(   sO   Read the directory, making sure we close the file if the format
        is bad.N(   R   R    R   R   R   R>   (   Rf   (    (    s   /usr/lib/python2.7/zipfile.pyR     s    	c         C   s'  |  j  } y t |  } Wn t k
 r8 t d   n X| sK t d  n  |  j d k rb | GHn  | t } | t } | t |  _ | t	 | | } | t
 t k r | t t 8} n  |  j d k r | | } d G| G| G| GHn  | | |  _ | j |  j d  | j |  } t j |  } d } x| | k  r"| j t  }	 |	 d d !t k rdt d  n  t j t |	  }	 |  j d k r|	 GHn  | j |	 t  }
 t |
  } | j |	 t  | _ | j |	 t  | _ |	 t | _ |	 d d !\ | _ | _  | _! | _" | _# | _$ } } | _% | _& | _' |	 d	 d
 !\ | _( | _) | _* | | _+ | d ?d | d ?d	 @| d @| d ?| d ?d @| d @d f | _, | j-   | j | | _ | j.   | _/ |  j0 j1 |  | |  j2 | j/ <| t |	 t |	 t |	 t } |  j d k r*d G| GHq*q*Wd S(   s/   Read in the table of contents for the ZIP file.s   File is not a zip filei   i   s   given, inferred, offseti    i   s&   Bad magic number for central directoryi   i   i   i	   i  i   i   i   i?   t   totalN(3   R   R   R   R    R   R&   R'   t   _ECD_COMMENTRK   t   _ECD_LOCATIONR!   R    R   R   R   R   R   t	   cStringIOt   StringIOt   sizeCentralDirt   stringCentralDirR   R   t   structCentralDirt   _CD_FILENAME_LENGTHR   t   _CD_EXTRA_FIELD_LENGTHRO   t   _CD_COMMENT_LENGTHt   _CD_LOCAL_HEADER_OFFSETRW   R1   RP   RQ   RR   RS   RN   RX   RY   RZ   RT   RU   RV   R[   RM   R   R|   R   R   RB   R   (   Rf   R   R*   t   size_cdt	   offset_cdt   concatt   inferredR+   R   t   centdirR   t   xt   tt   d(    (    s   /usr/lib/python2.7/zipfile.pyR     s`    	


I	&
"c         C   s.   g  } x! |  j  D] } | j | j  q W| S(   s+   Return a list of file names in the archive.(   R   RB   R   (   Rf   t   lR+   (    (    s   /usr/lib/python2.7/zipfile.pyt   namelist2  s    c         C   s   |  j  S(   sJ   Return a list of class ZipInfo instances for files in the
        archive.(   R   (   Rf   (    (    s   /usr/lib/python2.7/zipfile.pyt   infolist9  s    c         C   sJ   d d	 GHx: |  j  D]/ } d | j d  } d | j | | j f GHq Wd S(
   s+   Print a table of contents for the zip file.s   %-46s %19s %12ss	   File Names   Modified    t   Sizes   %d-%02d-%02d %02d:%02d:%02di   s   %-46s %s %12dN(   s	   File Names   Modified    R  (   R   RM   R   RZ   (   Rf   t   zinfot   date(    (    s   /usr/lib/python2.7/zipfile.pyt   printdir>  s    	c         C   se   d } xX |  j  D]M } y/ |  j | j d  } x | j |  rC q1 WWq t k
 r\ | j SXq Wd S(   s%   Read all the files and check the CRC.i   i   R   Ni   (   R   R   R   R   R    (   Rf   t
   chunk_sizeR  t   f(    (    s   /usr/lib/python2.7/zipfile.pyt   testzipE  s    c         C   s5   |  j  j |  } | d k r1 t d |   n  | S(   s,   Return the instance of ZipInfo given 'name'.s(   There is no item named %r in the archiveN(   R   t   getR>   t   KeyError(   Rf   R   t   info(    (    s   /usr/lib/python2.7/zipfile.pyt   getinfoR  s
    c         C   s   | |  _  d S(   s)   Set default password for encrypted files.N(   R   (   Rf   R   (    (    s   /usr/lib/python2.7/zipfile.pyt   setpassword[  s    c         C   s   |  j  | d |  j   S(   s)   Return file bytes (as a string) for name.R   (   R   R   (   Rf   R   R   (    (    s   /usr/lib/python2.7/zipfile.pyR   _  s    c         C   s	  | d k r t  d  n  |  j s- t  d  n  |  j rB |  j } n t |  j d  } t | t  rl | } n |  j |  } | j | j	 d  | j
 t  } | d d !t k r t d	  n  t j t |  } | j
 | t  } | t r | j
 | t  n  | | j k r't d
 | j | f  n  | j d @} d }	 | r| sR|  j } n  | sht  d |  n  t |  }	 | j
 d  }
 t |	 |
 d d ! } | j d @r| j d ?d @} n | j d ?d @} t | d  | k rt  d |   qn  t | | | |	  S(   s#   Return file-like object for 'name'.R   R   t   rUs&   open() requires mode "r", "U", or "rU"s3   Attempt to read ZIP archive that was already closedR   i    i   s    Bad magic number for file headers3   File name in directory "%s" and header "%s" differ.i   s6   File %s is encrypted, password required for extractioni   i   i   i   i   s   Bad password for file(   R   R   s   rUN(   R}   R   R   R   R   Rw   R   R  R   RW   R   t   sizeFileHeaderRn   R    R   R   Rm   t   _FH_FILENAME_LENGTHt   _FH_EXTRA_FIELD_LENGTHRL   RS   R>   R   R   R   R[   RX   R   R   (   Rf   R   R   R   t   zef_fileR  t   fheadert   fnamet   is_encryptedt   zdt   bytest   ht
   check_byte(    (    s   /usr/lib/python2.7/zipfile.pyR   c  sP    				

c         C   sO   t  | t  s! |  j |  } n  | d k r< t j   } n  |  j | | |  S(   s#  Extract a member from the archive to the current working directory,
           using its full name. Its file information is extracted as accurately
           as possible. `member' may be a filename or a ZipInfo object. You can
           specify a different directory using `path'.
        N(   Rw   R   R  R>   Ra   t   getcwdt   _extract_member(   Rf   t   membert   pathR   (    (    s   /usr/lib/python2.7/zipfile.pyt   extract  s
    c         C   sC   | d k r |  j   } n  x! | D] } |  j | | |  q" Wd S(   s   Extract all members from the archive to the current working
           directory. `path' specifies a different directory to extract to.
           `members' is optional and must be a subset of the list returned
           by namelist().
        N(   R>   R  R  (   Rf   R  t   membersR   R   (    (    s   /usr/lib/python2.7/zipfile.pyt
   extractall  s    c         C   sm  | d t  j j t  j j f k rQ t t  j j |  d  d k rQ | d  } n  | j d d k r t  j j | | j d  } n t  j j | | j  } t  j j |  } t  j j	 |  } | r t  j j
 |  r t  j |  n  | j d d k r!t  j j |  st  j |  n  | S|  j | d | } t | d  } t j | |  | j   | j   | S(   sb   Extract the ZipInfo object 'member' to a physical
           file on the path targetpath.
        ii   i    R]   R   R   (   Ra   R  Rb   t   altsepRo   t
   splitdriveR   R   t   normpatht   dirnamet   existst   makedirst   isdirt   mkdirR   R   t   shutilt   copyfileobjR   (   Rf   R  t
   targetpathR   t	   upperdirst   sourcet   target(    (    s   /usr/lib/python2.7/zipfile.pyR    s(    ""

c         C   s   | j  |  j k r- |  j r- d G| j  GHq- n  |  j d k rH t d  n  |  j s] t d  n  | j t k r t r t d  n  | j t	 t f k r t d  n  | j
 t k r |  j s t d   q n  | j t k r |  j s t d	   q n  d
 S(   s6   Check for errors before writing a file to the archive.s   Duplicate name:R   R   s    write() requires mode "w" or "a"s4   Attempt to write ZIP archive that was already closeds.   Compression requires the (missing) zlib modules(   That compression method is not supporteds'   Filesize would require ZIP64 extensionss+   Zipfile size would require ZIP64 extensionsN(   R   R   (   R   R   R   R   R}   R   RN   R   R   R   RZ   Ri   R   R   RW   (   Rf   R  (    (    s   /usr/lib/python2.7/zipfile.pyt   _writecheck  s(    							c         C   s  |  j  s t d   n  t j |  } t j | j  } t j | j  } | d d !} | d k rm | } n  t j
 j t j
 j |  d  } x* | d t j t j f k r | d } q W| r | d 7} n  t | |  } | d d @d >| _ | d k r|  j | _ n	 | | _ | j | _ d | _ |  j  j   | _ |  j |  t |  _ | rd | _ d | _ d | _ |  j j |  | |  j | j  <|  j  j! | j"    d St# | d	   }	 d | _ }
 d | _ } d | _ } |  j  j! | j"    | j t$ k r+t% j& t% j' t% j( d
  } n d } xw |	 j) d  } | sMPn  | t* |  } t+ | |
  d @}
 | r| j, |  } | t* |  } n  |  j  j! |  q4Wd QX| r| j-   } | t* |  } |  j  j! |  | | _ n	 | | _ |
 | _ | | _ |  j  j   } |  j  j. | j d d  |  j  j! t/ j0 d | j | j | j   |  j  j. | d  |  j j |  | |  j | j  <d S(   sL   Put the bytes from filename into the archive under the name
        arcname.s7   Attempt to write to ZIP archive that was already closedi    i   i   R]   i  l    NR   ii   i   l    i   s   <LLLi    (1   R   R}   Ra   t   statt   S_ISDIRt   st_modet   timet	   localtimet   st_mtimeR>   R  R$  R#  Rb   R"  R   RV   R   RN   t   st_sizeRZ   RS   R<   RW   R0  R   R   RY   RX   R   RB   R   R   t   writeRu   R   R   R   t   compressobjt   Z_DEFAULT_COMPRESSIONt   DEFLATEDR   Ro   R   t   compressR   R   R   Rj   (   Rf   R   t   arcnameRN   t   stR(  t   mtimeRM   R  R   RX   RY   RZ   t   cmprR   t   position(    (    s   /usr/lib/python2.7/zipfile.pyR8    s    		"									c         C   s  t  | t  sO t d | d t j t j    d   } |  j | _ d | _ n | } |  j sm t d   n  | d k	 r | | _ n  t
 |  | _ |  j j   | _ |  j |  t |  _ t |  d @| _ | j t k r$t j t j t j d  } | j |  | j   } t
 |  | _ n | j | _ |  j j   | _ |  j j | j    |  j j |  |  j j   | j d	 @r|  j j t j d
 | j | j | j   n  |  j  j! |  | |  j" | j# <d S(   s   Write a file into the archive.  The contents is the string
        'bytes'.  'zinfo_or_arcname' is either a ZipInfo instance or
        the name of the file in the archive.R   RM   i   i  i   s7   Attempt to write to ZIP archive that was already closedl    ii   s   <LLLNi  ($   Rw   R   R4  R5  R   RN   RV   R   R}   R>   Ro   RZ   R<   RW   R0  R   R   R   RX   R   R   R9  R:  R;  R<  R   RY   R8  Ru   RS   R   Rj   R   RB   R   R   (   Rf   t   zinfo_or_arcnameR  RN   R  t   co(    (    s   /usr/lib/python2.7/zipfile.pyt   writestrO  s>    		c         C   s   |  j    d S(   s2   Call the "close()" method in case the user forgot.N(   R   (   Rf   (    (    s   /usr/lib/python2.7/zipfile.pyt   __del__z  s    c         C   s  |  j  d k r d S|  j d k r|  j rd } |  j  j   } x|  j D]} | d } | j } | d d d >| d d >B| d	 B} | d
 d >| d d >B| d d	 B} g  } | j t k s | j	 t k r| j
 | j  | j
 | j	  d } d }	 n | j } | j	 }	 | j t k r<| j
 | j  d }
 n	 | j }
 | j } | rt j d d t |  d d t |  |  | } t d | j  } t d | j  } n | j } | j } y | j   \ } } t j t t | | j | | j | | j | | | j |	 | t |  t |  t | j  d | j | j |
  } Wn t k
 rt j t t | | j | | j | j  | j | | | j |	 | t | j!  t |  t | j  d | j | j |
 f IJ  n X|  j  j" |  |  j  j" |  |  j  j" |  |  j  j" | j  qJ W|  j  j   } | } | | } | } | t# k sc| t k sc| t k rt j t$ t% d d d d d | | | |  } |  j  j" |  t j t& t' d | d  } |  j  j" |  t( | d  } t( | d  } t( | d  } n  t |  j  t) k r?|  j* d k r,d t) } n  |  j t)  |  _ n  t j t+ t, d d | | | | t |  j  	 } |  j  j" |  |  j  j" |  j  |  j  j-   n  |  j. s|  j  j/   n  d |  _  d S(   sJ   Close the file, and for mode "w" and "a" write the ending
        records.NR   R   i    i   i  i	   i   i   i   i   i   l    s   <HHt   Qi   i-   i,   i  s3   Archive comment is too long; truncating to %d bytes(   R   R   (0   R   R>   R   R   R<   R   RM   RZ   Ri   RY   RB   RW   RO   R   Rj   Ro   RC   RQ   R1   Rl   R   R   RP   RR   RN   RX   RK   RU   RV   t   DeprecationWarningRd   t   stderrRS   R   R8  t   ZIP_FILECOUNT_LIMITR   R    R   R   R   t   ZIP_MAX_COMMENTR   R@   R?   R   R   R   (   Rf   t   countt   pos1R  Rp   Rq   Rr   RO   RZ   RY   RW   t
   extra_dataRQ   R1   R   RS   R   t   pos2t   centDirCountt   centDirSizet   centDirOffsett   zip64endrect   zip64locrect   msgR*   (    (    s   /usr/lib/python2.7/zipfile.pyR   ~  s    
	&&									
!	

	N(   R	   R
   R   R>   R   R   R   Rh   R   R   R   R   R  R  R  R	  R  R  R   R   R  R!  R  R0  R8  RD  RE  R   (    (    (    s   /usr/lib/python2.7/zipfile.pyR     s.   C				C							E	%	Q+	c           B   s#   e  Z d  Z d d  Z d   Z RS(   sD   Class to create ZIP archives with Python library files and packages.R;   c         C   s  t  j j |  \ } } t  j j |  r|t  j j | d  } t  j j |  r| rj d | | f } n | } |  j r d G| Gd G| GHn  |  j | d d !|  \ } } |  j r d G| GHn  |  j | |  t  j	 |  } | j
 d  x| D] }	 t  j j | |	  }
 t  j j |	  \ } } t  j j |
  rpt  j j t  j j |
 d   r|  j |
 |  qq | d k r |  j |
 d d !|  \ } } |  j rd G| GHn  |  j | |  q q Wq|  j rd	 G| GHn  x t  j	 |  D] }	 t  j j | |	  }
 t  j j |	  \ } } | d k r|  j |
 d d !|  \ } } |  j rbd G| GHn  |  j | |  qqWn` | d d k rt d
  n  |  j | d d !|  \ } } |  j rd G| GHn  |  j | |  d S(   s,  Add all files from "pathname" to the ZIP archive.

        If pathname is a package directory, search the directory and
        all package subdirectories recursively for all *.py and enter
        the modules into the archive.  If pathname is a plain
        directory, listdir *.py and enter all modules.  Else, pathname
        must be a Python *.py file and the module will be put into the
        archive.  Added modules are always module.pyo or module.pyc.
        This method will compile the module.py into module.pyc if
        necessary.
        s   __init__.pys   %s/%ss   Adding package int   asi    it   Addings   .pys   Adding files from directorys.   Files added with writepy() must end with ".py"s   Adding fileN(   Ra   R  t   splitR(  R   t   isfileR   t   _get_codenameR8  t   listdirt   removet   splitextt   writepyR}   (   Rf   t   pathnamet   basenamet   dirR   t   initnameR  R=  t   dirlistR   R  t   roott   ext(    (    s   /usr/lib/python2.7/zipfile.pyR]    sZ    		!					c   
      C   s8  | d } | d } | d } t  j j |  r] t  j |  j t  j |  j k r] | } n t  j j |  s t  j |  j t  j |  j k  r d d l } |  j r d G| GHn  y | j | | d t	  Wn | j
 k
 r } | j GHn X| } n | } t  j j |  d }	 | r.d | |	 f }	 n  | |	 f S(	   s   Return (filename, archivename) for the path.

        Given a module name path, return the correct file path and
        archive name, compiling if necessary.  For example, given
        /python/lib/string, return (/python/lib/string.pyc, string).
        s   .pys   .pycs   .pyoiNt	   Compilingi   s   %s/%s(   Ra   R  RX  R1  R6  t
   py_compileR   R   R>   R   t   PyCompileErrorRT  RW  (
   Rf   R^  R_  t   file_pyt   file_pyct   file_pyoR  Rf  t   errt   archivename(    (    s   /usr/lib/python2.7/zipfile.pyRY  1  s*    


$	$		(   R	   R
   R   R]  RY  (    (    (    s   /usr/lib/python2.7/zipfile.pyR     s   Ac      	      s  d d  l  } | j d  } |  d  k r7 t j d }  n  |  sN |  d d k rc | GHt j d  n  |  d d k r t |   d	 k r | GHt j d  n  t |  d d
  } | j   | j	   n,|  d d k r9t |   d	 k r | GHt j d  n  t |  d d
  } | j
   } | r1d j |  GHn  d GHn|  d d k rSt |   d k rp| GHt j d  n  t |  d d
  } |  d	 } x | j   D] } | j d  rt j j | | d	  } n t j j | |  } t j j |  } t j j |  st j |  n  t | d   }	 |	 j | j |   Wd  QXqW| j	   n |  d d k rt |   d k  r| GHt j d  n    f d     t |  d d d t } x. |  d	 D]" }
   | |
 t j j |
   qW| j	   n  d  S(   NisE          Usage:
            zipfile.py -l zipfile.zip        # Show listing of a zipfile
            zipfile.py -t zipfile.zip        # Test if a zipfile is valid
            zipfile.py -e zipfile.zip target # Extract zipfile into target dir
            zipfile.py -c zipfile.zip src ... # Create zipfile from sources
        i   i    s   -ls   -cs   -es   -ti   R   s.   The following enclosed file is corrupted: {!r}s   Done testingi   s   ./R   c            s   t  j j |  r( |  j | | t  n] t  j j |  r xH t  j |  D]4 }   |  t  j j | |  t  j j | |   qJ Wn  d  S(   N(   Ra   R  RX  R8  R   R(  RZ  R   (   t   zfR  t   zippatht   nm(   t   addToZip(    s   /usr/lib/python2.7/zipfile.pyRp    s    R   R   (   s   -ls   -cs   -es   -t(   t   textwrapt   dedentR>   Rd   t   argvt   exitRo   R   R  R   R	  t   formatR  t
   startswithRa   R  R   R%  R&  R'  R   R8  R   R   R_  (   t   argsRq  t   USAGERm  t   badfilet   outR  t   tgtt   tgtdirR   t   src(    (   Rp  s   /usr/lib/python2.7/zipfile.pyt   mainP  sb    	

 	 t   __main__(i   R   R   Ra   R4  Rd   R*  t   binasciiR   R1  R   R   R   R   t   ImportErrorR>   t   __all__t	   ExceptionR    R   R   Ri   RI  RJ  R   R   R@   R?   Rk   R=   R!   R"   R#   R$   R%   R&   R'   RE   R   R   R   R   R   t   _CD_SIGNATUREt   _CD_CREATE_VERSIONt   _CD_CREATE_SYSTEMt   _CD_EXTRACT_VERSIONt   _CD_EXTRACT_SYSTEMt   _CD_FLAG_BITSt   _CD_COMPRESS_TYPEt   _CD_TIMEt   _CD_DATEt   _CD_CRCt   _CD_COMPRESSED_SIZEt   _CD_UNCOMPRESSED_SIZER   R   R   t   _CD_DISK_NUMBER_STARTt   _CD_INTERNAL_FILE_ATTRIBUTESt   _CD_EXTERNAL_FILE_ATTRIBUTESR   Rm   Rn   R  t   _FH_SIGNATUREt   _FH_EXTRACT_VERSIONt   _FH_EXTRACT_SYSTEMt   _FH_GENERAL_PURPOSE_FLAG_BITSt   _FH_COMPRESSION_METHODt   _FH_LAST_MOD_TIMEt   _FH_LAST_MOD_DATEt   _FH_CRCt   _FH_COMPRESSED_SIZEt   _FH_UNCOMPRESSED_SIZER  R  R   R   R   R   R    R   t   _CD64_SIGNATUREt   _CD64_DIRECTORY_RECSIZEt   _CD64_CREATE_VERSIONt   _CD64_EXTRACT_VERSIONt   _CD64_DISK_NUMBERt   _CD64_DISK_NUMBER_STARTt   _CD64_NUMBER_ENTRIES_THIS_DISKt   _CD64_NUMBER_ENTRIES_TOTALt   _CD64_DIRECTORY_SIZEt   _CD64_OFFSET_START_CENTDIRR   R   R9   R   t   objectR   R   R   R   R   R   R~  R	   (    (    (    s   /usr/lib/python2.7/zipfile.pyt   <module>   s   <$
			'	8;  ecJ