
bc        	   @   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] e j^ d-  Z_ d.   Z` d/   Za d0   Zb d1   Zc d2   Zd d ee f d3     YZf d4 f  d5     YZg i d6 d 6d7 d 6d8 d 6d8 d 6d8 d 6d8 d 6d9 d 6d: d 6d; d 6d< d 6d9 d 6d= d  6d> d" 6d? d% 6d@ dA 6dB dC 6dD dE 6Zh dF e	 ji f dG     YZj d	 ee f dH     YZk d
 ek f dI     YZl e dJ  Zm en dK k rWem   n  d S(L   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iPKs   <HHc   
      C   s   t  j } t } g  } d } } x | d t |   k r | |  | | d ! \ } } | d | }	 | | k r | | k r | j |  | | ! n  |	 } t } n  |	 } q" W| s |  Sd j |  S(   Ni    i   t    (   t   _EXTRA_FIELD_STRUCTt   unpackt   Falset   lent   appendt   Truet   join(
   t   extrat   xidsR   t   modifiedt   buffert   startt   it   xidt   xlent   j(    (    s   /usr/lib/python2.7/zipfile.pyt   _strip_extra   s     	
	
c         C   s,   y t  |   r t SWn t k
 r' n Xt S(   N(   t   _EndRecDataR   t   IOErrorR   (   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"   R   t   structR   t   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   is     R   i   i   Ni   (   R(   t   tellt   sizeEndCentDirR   t   NoneR"   R   t   stringEndArchiveR*   R   t   structEndArchivet   listR   RH   t   maxt   rfindt   _ECD_COMMENT_SIZE(	   R7   t   filesizeR:   R9   t   maxCommentStartR   t   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_typeRV   R   t   create_systemR@   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   (   RW   t   findt   chrt   ost   sept   replaceR&   RX   t
   ValueErrorR   RY   RV   R   t   syst   platformRZ   R@   R[   R\   R]   R^   R_   R`   (   t   selfR&   RX   t	   null_byte(    (    s   /usr/lib/python2.7/zipfile.pyt   __init__6  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(   RX   R]   Rb   Rc   Rd   R   RK   t   ZIP64_LIMITR*   t   packt   calcsizeR   RO   R[   R@   t   _encodeFilenameFlagst   structFileHeadert   stringFileHeaderR\   RY   R   (   Rq   t   zip64t   dtt   dosdatet   dostimeRb   Rc   Rd   R   t   fmtR&   R]   t   header(    (    s   /usr/lib/python2.7/zipfile.pyt
   FileHeader`  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   encodeR]   t   UnicodeEncodeError(   Rq   (    (    s   /usr/lib/python2.7/zipfile.pyRw     s    !c         C   s(   |  j  d @r |  j j d  S|  j Sd  S(   Ni   s   utf-8(   R]   R&   t   decode(   Rq   (    (    s   /usr/lib/python2.7/zipfile.pyt   _decodeFilename  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    (   R   R*   R   R   t   RuntimeErrorRd   Rc   Ra   (   Rq   R   R   t   tpt   lnt   countst   idxt   old(    (    s   /usr/lib/python2.7/zipfile.pyt   _decodeExtra  s4    				(   RW   R&   RX   RY   RV   R   RZ   R@   R[   R\   R]   R^   R_   R`   Ra   Rb   Rc   Rd   Re   (   i  i   i   i    i    i    N(
   R	   R
   R   t	   __slots__Rs   RK   R   Rw   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   tableR   t   crcR   (    (    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(   Rq   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(   Rq   t   pwdt   p(    (    s   /usr/lib/python2.7/zipfile.pyRs     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   Rj   R   (   Rq   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   Rj   R   (   Rq   R   t   k(    (    s   /usr/lib/python2.7/zipfile.pyt   __call__  s    (	   R	   R
   R   R   R   R   Rs   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   Rb   I    (   t   _fileobjt
   _decryptert   _close_fileobjRY   t   _compress_typeRc   t   _compress_sizet   _compress_leftR   t   zlibt   decompressobjt   _decompressorR   t   compressor_namest   gett   NotImplementedErrort   _unconsumedt   _readbuffert   _offsett
   _universalRK   t   newlinest   modeR&   t   nameR$   Rb   t   _expected_crct   crc32t   _running_crc(   Rq   t   fileobjR   t   zipinfot	   decryptert   close_fileobjt   descr(    (    s   /usr/lib/python2.7/zipfile.pyRs     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   Ri   R   t   iot   BufferedIOBaset   readlineR   t   peekt   PATTERNt   searcht   groupRK   R   R   (   Rq   t   limitR   t   linet	   readaheadt   matchR   R   (    (    s   /usr/lib/python2.7/zipfile.pyR   B  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"   (   Rq   t   nR   (    (    s   /usr/lib/python2.7/zipfile.pyR   t  s    c         C   s   t  S(   N(   R   (   Rq   (    (    s   /usr/lib/python2.7/zipfile.pyt   readable  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(   RK   R   t   read1R   (   Rq   R   t   bufR:   (    (    s   /usr/lib/python2.7/zipfile.pyR"     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   RK   R   R   R    R   (   Rq   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(   RK   t   MAX_NR   R   R   R   R   RO   t   MIN_READ_SIZEt   minR   R"   R   R   t   mapR   R   R   R   R   t
   decompresst   unconsumed_tailt   flush(   Rq   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   (   Rq   (    (    s   /usr/lib/python2.7/zipfile.pyR     s    	i   N(   R	   R
   R   R   R   t   ret   compileR   RK   R   Rs   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   compressionRm   R   RK   R   t   _commentR   t
   basestringt   _filePassedR&   R%   R    R   t   getattrt   _RealGetContentsR   R(   t	   start_dirR    R   (   Rq   t   fileR   R   t
   allowZip64t   keyt   modeDictR    (    (    s   /usr/lib/python2.7/zipfile.pyRs     sf    											

		
			c         C   s   |  S(   N(    (   Rq   (    (    s   /usr/lib/python2.7/zipfile.pyt	   __enter__4  s    c         C   s   |  j    d  S(   N(   R   (   Rq   t   typet   valuet	   traceback(    (    s   /usr/lib/python2.7/zipfile.pyt   __exit__7  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   R5   R6   t   _ECD_COMMENTR   t   _ECD_LOCATIONR0   R/   R-   R)   R   R(   R"   t	   cStringIOt   StringIOt   sizeCentralDirR   R*   R   t   structCentralDirt   _CD_SIGNATUREt   stringCentralDirt   _CD_FILENAME_LENGTHR   t   _CD_EXTRA_FIELD_LENGTHR   t   _CD_COMMENT_LENGTHRV   t   _CD_LOCAL_HEADER_OFFSETRa   R@   RZ   R[   R\   R]   RY   Rb   Rc   Rd   R^   R_   R`   Re   RX   R   R   R&   R   R   R   (   Rq   R    R9   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   R   R&   (   Rq   t   lR:   (    (    s   /usr/lib/python2.7/zipfile.pyt   namelist  s    c         C   s   |  j  S(   sJ   Return a list of class ZipInfo instances for files in the
        archive.(   R   (   Rq   (    (    s   /usr/lib/python2.7/zipfile.pyt   infolist  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   RX   R&   Rd   (   Rq   t   zinfot   date(    (    s   /usr/lib/python2.7/zipfile.pyt   printdir  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    (   Rq   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   RK   t   KeyError(   Rq   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   (   Rq   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   (   Rq   (    (    s   /usr/lib/python2.7/zipfile.pyRV     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   (   Rq   RV   R-  (    (    s   /usr/lib/python2.7/zipfile.pyRV     s    		c         C   s   |  j  | d |  j   S(   s)   Return file bytes (as a string) for name.R   (   R%   R"   (   Rq   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   R/  ("   R   R    R   R   R%   R&   R   R   R   R)  R(   Ra   R"   t   sizeFileHeaderR   R    R*   R   Rx   t   _FH_SIGNATURERy   t   _FH_FILENAME_LENGTHt   _FH_EXTRA_FIELD_LENGTHRW   R]   RK   R   R   R   Re   Rb   R   R   R   (   Rq   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(   R   R   R)  RK   Rk   t   getcwdt   _extract_member(   Rq   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(   RK   R  RA  (   Rq   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.
        Rg   i   c         s   s6   |  ], } | d  t  j j t  j j f k r | Vq d S(   R   N(   Rk   R@  t   curdirt   pardir(   t   .0R  (    (    s   /usr/lib/python2.7/zipfile.pys	   <genexpr>6  s    s   \s   :<>|"?*c         S   s%   i  |  ] } t  d   t  |   q S(   t   _(   R   (   RF  R   (    (    s   /usr/lib/python2.7/zipfile.pys
   <dictcomp><  s   	 RG  c         s   s   |  ] } | j  d   Vq d S(   t   .N(   t   rstrip(   RF  R  (    (    s   /usr/lib/python2.7/zipfile.pys	   <genexpr>A  s    c         s   s   |  ] } | r | Vq d  S(   N(    (   RF  R  (    (    s   /usr/lib/python2.7/zipfile.pys	   <genexpr>B  s    iR   R   N(   R&   Rm   Rk   R@  Rl   t   altsept
   splitdriveR   t   splitR   R   t   stringt	   maketransR   t	   translatet   normpatht   dirnamet   existst   makedirst   isdirt   mkdirR%   R   t   shutilt   copyfileobj(
   Rq   R?  t
   targetpathR   t   arcnamet   illegalR   t	   upperdirst   sourcet   target(    (    s   /usr/lib/python2.7/zipfile.pyR>  )  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    RY   R   R   R   R   RK   R   R   t   ZIP_FILECOUNT_LIMITRd   Rt   Ra   R   (   Rq   R!  R-  t   requires_zip64(    (    s   /usr/lib/python2.7/zipfile.pyt   _writecheckW  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 >| _ | rt | _ n$ | 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 rat) j* t) j+ t) j, d  } n d	 } d } xx |	 j- d  } | sPn  | t. |  } t/ | |
  d @}
 | r| j0 |  } | t. |  } n  |  j  j" |  qpWWd	 QX| r,| j1   } | t. |  } |  j  j" |  | | _ n	 | | _ |
 | _ | | _ | r|  j& r| t' k rrt d   n  | t' k rt d   qn  |  j  j   } |  j  j2 | j d  |  j  j" | j# |   |  j  j2 | 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   Rg   i  l    i   NR#   g?ii   i   I    s*   File size has increased during compressings-   Compressed size larger than uncompressed sizei    (3   R    R   Rk   t   statt   S_ISDIRt   st_modet   timet	   localtimet   st_mtimeRK   R@  RP  RK  Rl   RJ  R   R`   R   RY   R   t   st_sizeRd   R]   RI   Ra   Ra  R   R   Rc   Rb   R   R   R   R&   t   writeR   R   R%   R   Rt   R   R   t   compressobjt   Z_DEFAULT_COMPRESSIONt   DEFLATEDR"   R   R   t   compressR   R(   (   Rq   R&   RY  RY   t   stRT  t   mtimeRX   R!  R    Rb   Rc   Rz   t   cmprRd   R   t   position(    (    s   /usr/lib/python2.7/zipfile.pyRi  s  s    		"										c         C   sE  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# | t$ | 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&   RX   i   iRg   iA  i   i  s7   Attempt to write to ZIP archive that was already closedI    is'   Filesize would require ZIP64 extensionsi   s   <LLQQs   <LLLLNi  Ai  ((   R   R   Re  Rf  R   RY   R&   R`   R    R   RK   R   Rd   RI   Ra   Ra  R   R   R   Rb   R   R   Rj  Rk  Rl  Rm  R   Rc   Rt   R   R   Ri  R   R]   R*   Ru   t   _DD_SIGNATURER   R   R   (   Rq   t   zinfo_or_arcnameR:  RY   R!  t   coRz   R~   (    (    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   (   Rq   (    (    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 |
 d  }
 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 red } n* | t k rzd } n | t k rd } n  | rI|  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 |  _  |  j0 s| j1   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   (   i   (2   R    RK   R   R   RI   R   RX   Rd   Rt   Rc   R   Ra   R   R   R*   Ru   R   RO   R[   R@   Rw   R  R  RZ   R\   RY   Rb   RV   R_   R`   t   DeprecationWarningRo   t   stderrR]   R&   Ri  R_  R   R   R.   R/   R+   R,   R   RM   RL   R   R   R   R   (   Rq   t   pos1R!  R{   R|   R}   R   Rd   Rc   Ra   t
   extra_dataR[   R@   R&   R]   R  t   pos2t   centDirCountt   centDirSizet   centDirOffsetR`  t   zip64endrect   zip64locrecR9   R    (    (    s   /usr/lib/python2.7/zipfile.pyR     s    	&&									
!	
							N(   R	   R
   R   RK   R    R   R   Rs   R  R  R   R  R  R#  R&  R)  R*  t   propertyRV   t   setterR"   R%   RA  RC  R>  Ra  Ri  Ru  Rv  R   (    (    (    s   /usr/lib/python2.7/zipfile.pyR     s0   G			E							O	.	\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(   Rk   R@  RL  RT  R   t   isfileR   t   _get_codenameRi  t   listdirt   removet   splitextt   writepyR   (   Rq   t   pathnamet   basenamet   dirR   t   initnameR7  RY  t   dirlistR&   R@  t   roott   ext(    (    s   /usr/lib/python2.7/zipfile.pyR  z  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(   Rk   R@  R  Rb  Rg  t
   py_compileR   R   RK   R   t   PyCompileErrort   msgRL  (
   Rq   R  R  t   file_pyt   file_pyct   file_pyoR7  R  t   errt   archivename(    (    s   /usr/lib/python2.7/zipfile.pyR    s*    


$	$		(   R	   R
   R   R  R  (    (    (    s   /usr/lib/python2.7/zipfile.pyR   w  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(   Rk   R@  R  Ri  R   RT  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   dedentRK   Ro   t   argvt   exitR   R   R#  R&  t   formatRC  R   Rk   R@  R  RQ  RD  RE  (   t   argsR  t   USAGER  t   badfileR@  R  (    (   R  s   /usr/lib/python2.7/zipfile.pyt   main  sT    	!	t   __main__(o   R   R*   Rk   Re  Ro   RV  t   binasciiR  Rb  R   R   RM  R   R   t   ImportErrorRK   t   __all__t	   ExceptionR    R   R   Rt   R_  R,  R   R   RM   RL   Rv   RJ   R0   R1   R2   R3   R4   R5   R6   RQ   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  Rx   Ry   R0  R1  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_SIZER2  R3  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_CENTDIRRr  t   StructR   R   R!   R   RH   R   t   objectR   R   R   R   R   R   R   R  R	   (    (    (    s   /usr/lib/python2.7/zipfile.pyt   <module>   s   <$				+	=<
  cB