
sWc        	   @   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
 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 >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 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> d' Z? e j e>  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 d) ZN e j eM  ZO d* ZP d+ ZQ e j eP  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/   Z` d ea f d0     YZb d1 f  d2     YZc i d3 d 6d4 d 6d5 d 6d5 d 6d5 d 6d5 d 6d6 d 6d7 d 6d8 d 6d9 d 6d6 d 6d: d  6d; d" 6d< d% 6d= d> 6d? d@ 6dA dB 6Zd dC e	 je f dD     YZf d	 ea f dE     YZg d
 eg f dF     YZh e dG  Zi ej dH k r9ei   n  d S(I   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   sn  y |  j  | t d  Wn t k
 r, | SX|  j t  } t |  t k rR | St j t |  \ } } } } | t k r | S| d k s | d k r t	 d   n  |  j  | t t
 d  |  j t
  } t |  t
 k r | St 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   lent   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   s6    0






c   	      C   s  |  j  d d  |  j   } y |  j  t d  Wn t k
 rE d	 SX|  j   } t |  t k r | 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 k rId	 St 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   R   t   stringEndArchiveR   R   t   structEndArchivet   listt   appendR:   t   maxt   rfindt   _ECD_COMMENT_SIZE(	   R)   t   filesizeR,   R+   t   maxCommentStartt   startt   recDatat   commentSizet   comment(    (    s   /usr/lib/python2.7/zipfile.pyR      s>    
c           B   sJ   e  Z d  Z d Z d d d  Z d 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_typeRL   t   extrat   create_systemR2   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  | |  _ | |  _ | d d k  r t d   n  t	 |  _
 d |  _ d |  _ t j d k r d |  _ n	 d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d |  _ d  S(	   Ni    t   /i  s+   ZIP does not support timestamps before 1980R<   t   win32i   i   (   RM   t   findt   chrt   ost   sept   replaceR   RN   t
   ValueErrorR   RO   RL   RP   t   syst   platformRQ   R2   RR   RS   RT   RU   RV   RW   (   t   selfR   RN   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 } | d k r | t k p | t k } n  | r d }	 | t j	 |	 d t j
 |	  d	 | |  } n  | t k s| t k r_| s&t d   n  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   <HHQQs'   Filesize would require ZIP64 extensionsI    i-   N(   RN   RT   RY   RZ   R[   RP   R?   t   ZIP64_LIMITR   t   packt   calcsizeR   RD   RR   R2   t   _encodeFilenameFlagst   structFileHeadert   stringFileHeaderRS   RO   R   (   Rh   t   zip64t   dtt   dosdatet   dostimeRY   RZ   R[   RP   t   fmtR   RT   t   header(    (    s   /usr/lib/python2.7/zipfile.pyt
   FileHeaderI  s:    	&&				#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   encodeRT   t   UnicodeEncodeError(   Rh   (    (    s   /usr/lib/python2.7/zipfile.pyRn   p  s    !c         C   s(   |  j  d @r |  j j d  S|  j Sd  S(   Ni   s   utf-8(   RT   R   t   decode(   Rh   (    (    s   /usr/lib/python2.7/zipfile.pyt   _decodeFilenamey  s    c         C   s  |  j  } t j } xjt |  d k r~| d | d   \ } } | d k rm| d k rq | 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 r8| | |  _ | d 7} n  |  j d k rm|  j } | | |  _ | d 7} qmn  | | d } q Wd  S(   Ni   s   <HHi   i   s   <QQQi   i   s   <QQi   i   s   <Qi   i    s   Corrupt extra field %sl    l    (    (   l    l    (   RP   R   R   R   t   RuntimeErrorR[   RZ   RX   (   Rh   RP   R   t   tpt   lnt   countst   idxt   old(    (    s   /usr/lib/python2.7/zipfile.pyt   _decodeExtra  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    N(
   R	   R
   R   t	   __slots__Rj   R?   Rw   Rn   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().
        I     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(   Rh   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(   Rh   t   pwdt   p(    (    s   /usr/lib/python2.7/zipfile.pyRj     s
    			c         C   sx   |  j  | |  j  |  _ |  j |  j d @d @|  _ |  j d d d @|  _ |  j  t |  j d ?d @ |  j  |  _ d  S(   Ni   I    ii   i   (   R   R   R   Ra   R   (   Rh   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   Ra   R   (   Rh   R   t   k(    (    s   /usr/lib/python2.7/zipfile.pyt   __call__  s    (	   R	   R
   R   R   R   R   Rj   R   R   (    (    (    s   /usr/lib/python2.7/zipfile.pyR     s   					t   storet   shrinkt   reducet   implodet   tokenizet   deflatet	   deflate64t   bzip2t   lzmat   terset   lz77i   t   wavpackia   t   ppmdib   t
   ZipExtFilec           B   s   e  Z d  Z d d >Z d Z e j d  Z d e	 d  Z
 d d  Z d d  Z d	   Z d d
  Z 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   sf  | |  _  | |  _ | |  _ | j |  _ | j |  _ | j |  _ |  j t k rc t	 j
 d  |  _ n\ |  j t k r t j |  j  } | r t d |  j | f   q t d |  j f   n  d |  _ d |  _ d |  _ d | k |  _ d  |  _ |  j d  k	 r|  j d 8_ n  | |  _ | j |  _ t | d  rY| j |  _ t d  d	 @|  _ n	 d  |  _ d  S(
   Nis   compression type %d (%s)s   compression type %dR<   i    t   Ui   RY   I    (   t   _fileobjt
   _decryptert   _close_fileobjRO   t   _compress_typeRZ   t   _compress_sizet   _compress_leftR   t   zlibt   decompressobjt   _decompressorR   t   compressor_namest   gett   NotImplementedErrort   _unconsumedt   _readbuffert   _offsett
   _universalR?   t   newlinest   modeR   t   nameR   RY   t   _expected_crct   crc32t   _running_crc(   Rh   t   fileobjR   t   zipinfot	   decryptert   close_fileobjt   descr(    (    s   /usr/lib/python2.7/zipfile.pyRj     s4    								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   readlineR   t   peekt   PATTERNt   searcht   groupR?   R   RC   (   Rh   t   limitR   t   linet	   readaheadt   matchR   R   (    (    s   /usr/lib/python2.7/zipfile.pyR   +  s8    		!
c         C   s   | t  |  j  |  j k r{ |  j |  } t  |  |  j k rc | |  j |  j |  _ d |  _ q{ |  j t  |  8_ n  |  j |  j |  j d !S(   s6   Returns buffered bytes without advancing the position.i    i   (   R   R   R   R   (   Rh   t   nR   (    (    s   /usr/lib/python2.7/zipfile.pyR   ]  s    c         C   s   t  S(   N(   R   (   Rh   (    (    s   /usr/lib/python2.7/zipfile.pyt   readablej  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   read1R   (   Rh   R   t   bufR,   (    (    s   /usr/lib/python2.7/zipfile.pyR   m  s    		c         C   s^   |  j  d  k r d  St | |  j  d @|  _ | rZ |  j |  j  k rZ t d |  j   n  d  S(   NI    s   Bad CRC-32 for file %r(   R   R?   R   R   R    R   (   Rh   t   newdatat   eof(    (    s   /usr/lib/python2.7/zipfile.pyt   _update_crc  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_NR   R   R   R   R   RD   t   MIN_READ_SIZEt   minR   R   R   t   joint   mapR   R   R   R   R   t
   decompresst   unconsumed_tailt   flush(   Rh   R   t   len_readbuffert   nbytesR,   R   (    (    s   /usr/lib/python2.7/zipfile.pyR     s>    (!	$c         C   s8   z |  j  r |  j j   n  Wd  t t |   j   Xd  S(   N(   R   R   t   closet   superR   (   Rh   (    (    s   /usr/lib/python2.7/zipfile.pyR     s    	i   N(   R	   R
   R   R   R   t   ret   compileR   R?   R   Rj   R   R   R   R   R   R   R   (    (    (    s   /usr/lib/python2.7/zipfile.pyR     s   
'2		
	4c           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 e d    Z e j 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   s\  | 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  |  _ y | d k r|  j   n | d k rt |  _ no | d k ry$ |  j   |  j j |  j d  Wq"t k
 r|  j j d d  t |  _ q"Xn t  d   Wn2 |  j } d |  _ |  j sQ| j   n    n Xd 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   compressionRd   R   R?   R   t   _commentRy   t
   basestringt   _filePassedR   R   R   R   t   getattrt   _RealGetContentsR   R   t	   start_dirR    R   (   Rh   t   fileR   R   t
   allowZip64t   keyt   modeDictR   (    (    s   /usr/lib/python2.7/zipfile.pyRj     sf    											

		
			c         C   s   |  S(   N(    (   Rh   (    (    s   /usr/lib/python2.7/zipfile.pyt	   __enter__  s    c         C   s   |  j    d  S(   N(   R   (   Rh   t   typet   valuet	   traceback(    (    s   /usr/lib/python2.7/zipfile.pyt   __exit__   s    c         C   sH  |  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  rC| j t  }	 t |	  t k rft d   n  t j t |	  }	 |	 t t k rt d   n  |  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 | _/ | j0   | j! | | _! | j1   | _2 |  j3 j4 |  | |  j5 | j2 <| 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    s   Truncated central directorys&   Bad magic number for central directoryi   i   i   i	   i  i   i   i   i?   t   totalN(6   R   R   R   R    R   R'   R(   t   _ECD_COMMENTR   t   _ECD_LOCATIONR"   R!   R   R   R   R   R   t	   cStringIOt   StringIOt   sizeCentralDirR   R   R   t   structCentralDirt   _CD_SIGNATUREt   stringCentralDirt   _CD_FILENAME_LENGTHR   t   _CD_EXTRA_FIELD_LENGTHRP   t   _CD_COMMENT_LENGTHRL   t   _CD_LOCAL_HEADER_OFFSETRX   R2   RQ   RR   RS   RT   RO   RY   RZ   R[   RU   RV   RW   R\   RN   R   R~   R   R   RC   R   (   Rh   R   R+   t   size_cdt	   offset_cdt   concatt   inferredR,   R  t   centdirR   t   xt   tt   d(    (    s   /usr/lib/python2.7/zipfile.pyR   #  sd    	


I	&
"c         C   s.   g  } x! |  j  D] } | j | j  q W| S(   s+   Return a list of file names in the archive.(   R   RC   R   (   Rh   t   lR,   (    (    s   /usr/lib/python2.7/zipfile.pyt   namelisth  s    c         C   s   |  j  S(   sJ   Return a list of class ZipInfo instances for files in the
        archive.(   R   (   Rh   (    (    s   /usr/lib/python2.7/zipfile.pyt   infolisto  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   RN   R   R[   (   Rh   t   zinfot   date(    (    s   /usr/lib/python2.7/zipfile.pyt   printdirt  s    	c         C   sn   d } xa |  j  D]V } y8 |  j | j d   } x | j |  rF q4 WWd QXWq t k
 re | j SXq Wd S(   s%   Read all the files and check the CRC.i   i   R   Ni   (   R   R   R   R   R    (   Rh   t
   chunk_sizeR  t   f(    (    s   /usr/lib/python2.7/zipfile.pyt   testzip{  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   R   R?   t   KeyError(   Rh   R   t   info(    (    s   /usr/lib/python2.7/zipfile.pyt   getinfo  s
    c         C   s   | |  _  d S(   s)   Set default password for encrypted files.N(   R   (   Rh   R   (    (    s   /usr/lib/python2.7/zipfile.pyt   setpassword  s    c         C   s   |  j  S(   s.   The comment text associated with the ZIP file.(   R   (   Rh   (    (    s   /usr/lib/python2.7/zipfile.pyRL     s    c         C   sX   t  |  t k rB d d  l } | j d t d d | t  } n  | |  _ t |  _ d  S(   Nis3   Archive comment is too long; truncating to %d bytest
   stackleveli   (   R   t   ZIP_MAX_COMMENTt   warningst   warnR   R   R   (   Rh   RL   R'  (    (    s   /usr/lib/python2.7/zipfile.pyRL     s    		c         C   s   |  j  | d |  j   S(   s)   Return file bytes (as a string) for name.R   (   R   R   (   Rh   R   R   (    (    s   /usr/lib/python2.7/zipfile.pyR     s    c         C   sd  | d k r t  d  n  |  j s- t  d  n  |  j rH |  j } t } n t |  j d  } t } yt | t  r{ | } n |  j	 |  } | j
 | j d  | j t  } t |  t k r t d   n  t j t |  } | t t k r t d	   n  | j | t  } | t r/| j | t  n  | | j k rWt d
 | j | f  n  | j d @}	 d }
 |	 r&| s|  j } n  | s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  | | | |
 d | SWn | rY| j!   n    n Xd 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    s   Truncated file headers    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 fileR   N(   R   R   s   rU("   R   R   R   R   R   R   R   Ry   R   R#  R   RX   R   t   sizeFileHeaderR   R    R   R   Ro   t   _FH_SIGNATURERp   t   _FH_FILENAME_LENGTHt   _FH_EXTRA_FIELD_LENGTHRM   RT   R?   R   R   R   R\   RY   R   R   R   (   Rh   R   R   R   t   zef_filet   should_closeR  t   fheadert   fnamet   is_encryptedt   zdt   bytest   ht
   check_byte(    (    s   /usr/lib/python2.7/zipfile.pyR     sd    						

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(   Ry   R   R#  R?   Rb   t   getcwdt   _extract_member(   Rh   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;  (   Rh   R:  t   membersR   R   (    (    s   /usr/lib/python2.7/zipfile.pyt
   extractall  s    c   
      C   s  | j  j d t j j  } t j j rH | j t j j t j j  } n  t j j |  d } t j j j d   | j t j j  D  } t j j d k r2d } t	 | t
  r d   | D } n t j | d t |   } | j |  } d   | j t j j  D } t j j j d	   | D  } n  t 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 | |	  Wd QXWd QX| S(   sb   Extract the ZipInfo object 'member' to a physical
           file on the path targetpath.
        R^   i   c         s   s6   |  ], } | d  t  j j t  j j f k r | Vq d S(   R<   N(   Rb   R:  t   curdirt   pardir(   t   .0R  (    (    s   /usr/lib/python2.7/zipfile.pys	   <genexpr>  s    s   \s   :<>|"?*c         S   s%   i  |  ] } t  d   t  |   q S(   t   _(   R   (   R@  R   (    (    s   /usr/lib/python2.7/zipfile.pys
   <dictcomp>%  s   	 RA  c         s   s   |  ] } | j  d   Vq d S(   t   .N(   t   rstrip(   R@  R  (    (    s   /usr/lib/python2.7/zipfile.pys	   <genexpr>*  s    c         s   s   |  ] } | r | Vq d  S(   N(    (   R@  R  (    (    s   /usr/lib/python2.7/zipfile.pys	   <genexpr>+  s    iR   R   N(   R   Rd   Rb   R:  Rc   t   altsept
   splitdriveR   t   splitRy   Rz   t   stringt	   maketransR   t	   translatet   normpatht   dirnamet   existst   makedirst   isdirt   mkdirR   R   t   shutilt   copyfileobj(
   Rh   R9  t
   targetpathR   t   arcnamet   illegalR   t	   upperdirst   sourcet   target(    (    s   /usr/lib/python2.7/zipfile.pyR8    s4    !."c         C   s+  | j  |  j k r; d d l } | j d | j  d d n  |  j d k rV t d  n  |  j sk t d	  n  | j t k r t	 r t d
  n  | j t
 t f k r t d  n  |  j s'd } t |  j  t k r d } n0 | j t k r d } n | j t k rd } n  | r't | d   q'n  d S(   s6   Check for errors before writing a file to the archive.iNs   Duplicate name: %rR%  i   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   Files countt   Filesizes   Zipfile sizes    would require ZIP64 extensions(   R   R   (   R   R   R'  R(  R   R   R   RO   R   R   R   R   R?   R   R   t   ZIP_FILECOUNT_LIMITR[   Rk   RX   R   (   Rh   R  R'  t   requires_zip64(    (    s   /usr/lib/python2.7/zipfile.pyt   _writecheck@  s2    								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 d O_ |  j j |  | |  j | j  <|  j  j! | j" t#   d	 St$ | d
  	}	 d | _ }
 d | _ } |  j% o| j d t& k } |  j  j! | j" |   | j t' k rOt( j) t( j* t( j+ d  } n d	 } d } xw |	 j, d  } | swPn  | t- |  } t. | |
  d @}
 | r| j/ |  } | t- |  } n  |  j  j! |  q^Wd	 QX| r| j0   } | t- |  } |  j  j! |  | | _ n	 | | _ |
 | _ | | _ | r}|  j% r}| t& k r_t d   n  | t& k r}t d   q}n  |  j  j   } |  j  j1 | j d  |  j  j! | j" |   |  j  j1 | 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    i   NR   g?ii   i   I    s*   File size has increased during compressings-   Compressed size larger than uncompressed sizei    (2   R   R   Rb   t   statt   S_ISDIRt   st_modet   timet	   localtimet   st_mtimeR?   R:  RJ  RE  Rc   RD  R   RW   R   RO   t   st_sizeR[   RT   R=   RX   R[  R   R   RZ   RY   R   RC   R   R   t   writeRw   R   R   R   Rk   R   R   t   compressobjt   Z_DEFAULT_COMPRESSIONt   DEFLATEDR   R   R   t   compressR   R   (   Rh   R   RS  RO   t   stRN  t   mtimeRN   R  R   RY   RZ   Rq   t   cmprR[   R   t   position(    (    s   /usr/lib/python2.7/zipfile.pyRc  \  s    		"										c         C   sB  t  | t  s} t d | d t j t j    d   } |  j | _ | j d d k rq d | _ | j d O_ q d | _ n | } |  j s t	 d	   n  | d k	 r | | _ n  t |  | _ |  j j   | _ |  j |  t |  _ t |  d
 @| _ | j t k rRt j t j t j d  } | j |  | j   } t |  | _ n | j | _ | j t k py| j t k } | r|  j rt d   n  |  j j | j  |   |  j j |  | j! d @r| rd n d } |  j j t" j# | | j | j | j   n  |  j j   |  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   RN   i   iR^   iA  i   i  s7   Attempt to write to ZIP archive that was already closedI    is'   Filesize would require ZIP64 extensionsi   s   <LQQs   <LLLNi  Ai  ('   Ry   R   R_  R`  R   RO   R   RW   R   R   R?   R   R[   R=   RX   R[  R   R   R   RY   R   R   Rd  Re  Rf  Rg  R   RZ   Rk   R   R   Rc  Rw   RT   R   Rl   R   RC   R   (   Rh   t   zinfo_or_arcnameR4  RO   R  t   coRq   Ru   (    (    s   /usr/lib/python2.7/zipfile.pyt   writestr  sL    			c         C   s   |  j    d S(   s2   Call the "close()" method in case the user forgot.N(   R   (   Rh   (    (    s   /usr/lib/python2.7/zipfile.pyt   __del__  s    c         C   s  |  j  d k r d Sz|  j d k r|  j r|  j  j   } x|  j 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  qG W|  j  j   } t |  j  } | | } | } d } | t# k rVd } n* | t k rkd } n | t k rd } n  | r:|  j$ st% | d   n  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+ t, d d | | | | t |  j-  	 } |  j  j" |  |  j  j" |  j-  |  j  j.   n  Wd |  j  } d |  _  |  j/ s| j0   n  Xd 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   I    l    s   <HHt   Qi   i-   s   Files counts   Central directory offsets   Central directory sizes    would require ZIP64 extensionsi,   i  (   R   R   (1   R   R?   R   R   R=   R   RN   R[   Rk   RZ   RC   RX   RP   R   Rl   R   RD   RR   R2   Rn   R  R
  RQ   RS   RO   RY   RL   RV   RW   t   DeprecationWarningRf   t   stderrRT   R   Rc  RY  R   R   R    R!   R   R   R   RA   R@   R   R   R   R   (   Rh   t   pos1R  Rr   Rs   Rt   RP   R[   RZ   RX   t
   extra_dataRR   R2   R   RT   R  t   pos2t   centDirCountt   centDirSizet   centDirOffsetRZ  t   zip64endrect   zip64locrecR+   R   (    (    s   /usr/lib/python2.7/zipfile.pyR     s    	&&									
!	
							N(   R	   R
   R   R?   R   R   R   Rj   R   R  R   R  R  R  R   R#  R$  t   propertyRL   t   setterR   R   R;  R=  R8  R[  Rc  Rn  Ro  R   (    (    (    s   /usr/lib/python2.7/zipfile.pyR     s0   G			E							O	.	Z3	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(   Rb   R:  RF  RN  R   t   isfileR   t   _get_codenameRc  t   listdirt   removet   splitextt   writepyR   (   Rh   t   pathnamet   basenamet   dirR   t   initnameR1  RS  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(   Rb   R:  R  R\  Ra  t
   py_compileR   R   R?   R   t   PyCompileErrort   msgRF  (
   Rh   R  R  t   file_pyt   file_pyct   file_pyoR1  R  t   errt   archivename(    (    s   /usr/lib/python2.7/zipfile.pyR    s*    


$	$		(   R	   R
   R   R  R  (    (    (    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   Wd  QXn|  d d k rAt |   d	 k r | GHt j d  n  t |  d d
   } | j	   } Wd  QX| r9d j
 |  GHn  d GHnT|  d d k rt |   d k rx| GHt j d  n  t |  d d
   } | j |  d	  Wd  QXn |  d d k rt |   d k  r| GHt j d  n    f d     t |  d d d t  } x |  d	 D]s } t j j |  } | sTt j j t j j |   } n  | d t j t j f k rxd } n    | | |  qWWd  QXn  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   c            s   t  j j |  r( |  j | | t  nv t  j j |  r | rS |  j | |  n  xH t  j |  D]4 }   |  t  j j | |  t  j j | |   qc Wn  d  S(   N(   Rb   R:  R  Rc  R   RN  R  R   (   t   zfR:  t   zippatht   nm(   t   addToZip(    s   /usr/lib/python2.7/zipfile.pyR    s    R   R   R<   (   s   -ls   -cs   -es   -t(   t   textwrapt   dedentR?   Rf   t   argvt   exitR   R   R  R   t   formatR=  R   Rb   R:  R  RK  R>  R?  (   t   argsR  t   USAGER  t   badfileR:  R  (    (   R  s   /usr/lib/python2.7/zipfile.pyt   main  sT    	!	t   __main__(k   R   R   Rb   R_  Rf   RP  t   binasciiR  R\  R   R   RG  R   R   t   ImportErrorR?   t   __all__t	   ExceptionR    R   R   Rk   RY  R&  R   R   RA   R@   Rm   R>   R"   R#   R$   R%   R&   R'   R(   RF   R  R  R  R
  R  R	  t   _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  Ro   Rp   R*  R+  t   _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   R:   R   t   objectR   R   R   R   R   R   R   R  R	   (    (    (    s   /usr/lib/python2.7/zipfile.pyt   <module>   s   <$			+	=<
  cB