
    (i                    n   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ej                  Z	 ddlZ	 ddlZg dZ G d de      Z G d de      ZexZZdZd	Zd
ZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#dZ$ e	jJ                  e#      Z&dZ'dZ(dZ)dZ*dZ+dZ,dZ-dZ.dZ/dZ0dZ1dZ2 e	jJ                  e1      Z3dZ4dZ5dZ6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>d Z?dZ@d!ZAdZBd"ZCd#ZDd$ZEd%ZFd&ZGd'ZH e	jJ                  eG      ZIdZJdZKdZLdZMdZNdZOdZPdZQdZRdZSdZTd ZUd(ZVd)ZW e	jJ                  eV      ZXd*ZYd+ZZ e	jJ                  eY      Z[dZ\dZ]dZ^dZ_dZ`dZadZbdZcdZddZed, Zfd- Zgd. Zhd/ Zi G d0 d1ej      Zk G d2 d3      Zl G d4 d5      Zm G d6 d7      Zni dd8dd9dd:dd:dd:dd:dd;dd<dd=dd>dd;dd?dd@d%dAdBdCdDdEdFdGZodH ZpdI ZqdJ Zr G dK dLej                        Zt G dM dN      Zu G dO dPeu      ZvdSdQZwexdRk(  r ew        yy# e$ r dZe
j                  ZY w xY w# e$ r dZY w xY w# e$ r dZY w xY w)TzP
Read and write ZIP files.

XXX references to utf-8 need further investigation.
    N)
BadZipFile
BadZipfileerror
ZIP_STOREDZIP_DEFLATED	ZIP_BZIP2ZIP_LZMA
is_zipfileZipInfoZipFile	PyZipFileLargeZipFilec                       e Zd Zy)r   N)__name__
__module____qualname__     /opt/sopds/opds_catalog/zipf.pyr   r   '   s    r   r   c                       e Zd ZdZy)r   zu
    Raised when writing a zipfile, the zipfile requires ZIP64 extensions
    and those extensions are disabled.
    N)r   r   r   __doc__r   r   r   r   r   +   s    r   r   cp866                 -   .   ?   s   <4s4H2LHs   PK                     	   z<4s4B4HL2L5H2Ls   PK
                     z<4s2B4HL2L2Hs   PKz<4sLQLs   PKz
<4sQ2H2L4Qs   PKc                 >    	 t        |       ry	 y# t        $ r Y yw xY w)NTF)_EndRecDataIOErrorfps    r   _check_zipfiler7      s2    r?    s    	c                     d}	 t        | d      rt        |       }|S t        | d      5 }t        |      }ddd       |S # 1 sw Y   |S xY w# t        $ r Y |S w xY w)zQuickly 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.
    Freadr5   rbN)hasattrr7   openr4   )filenameresultr6   s      r   r
   r
      sw    
 F8V$#x0F M	 h% ,'+, M	, M  Ms2   A A A A  A
A 
A 	AAc           
         	 | j                  |t        z
  d       | j                  t              }t	        |      t        k7  r|S t        j                  t        |      \  }}}}|t        k7  r|S |dk7  s|dk7  rt        d      | j                  |t        z
  t        z
  d       | j                  t              }t	        |      t        k7  r|S t        j                  t        |      \
  }}}	}
}}}}}}|t        k7  r|S ||t        <   ||t        <   ||t        <   ||t         <   ||t"        <   ||t$        <   ||t&        <   |S # t        $ r |cY S w xY w)zM
    Read the ZIP64 end-of-archive records and use that to update endrec
    r$   r   r#   z3zipfiles that span multiple disks are not supported)seeksizeEndCentDir64Locatorr4   r9   lenstructunpackstructEndArchive64LocatorstringEndArchive64Locatorr   sizeEndCentDir64structEndArchive64stringEndArchive64_ECD_SIGNATURE_ECD_DISK_NUMBER_ECD_DISK_START_ECD_ENTRIES_THIS_DISK_ECD_ENTRIES_TOTAL	_ECD_SIZE_ECD_OFFSET)fpinoffsetendrecdatasigdisknoreloffdisksszcreate_versionread_versiondisk_numdisk_dirdircount	dircount2dirsize	diroffsets                    r   _EndRecData64rb      s^   		&22A6 99,-D
4y++!'/H$!OC
''{eqjNOO 	IIf..1AA1E99%&D
4y$$ MM,d34C^\8Xi)
   !F>'F&F?%-F!"!*FF9#F;ME   s   D= =E
Ec                    | j                  dd       | j                         }	 | j                  t         d       | j	                         }t        |      t        k(  rt|dd t        k(  rh|dd dk(  r`t        j                  t        |      }t        |      }|j                  d       |j                  |t        z
         t        | t         |      S t        |dz
  t        z
  d      }| j                  |d       | j	                         }|j                  t              }|dk\  r|||t        z    }t        |      t        k7  ryt        t        j                  t        |            }|t           }||t        z   |t        z   |z    }|j                  |       |j                  ||z          t        | ||z   |z
  |      S y# t        $ r Y yw xY w)	zReturn 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.r   r$   Nr&   s     r   r   )r@   tellsizeEndCentDirr4   r9   rB   stringEndArchiverC   rD   structEndArchivelistappendrb   maxrfind_ECD_COMMENT_SIZE)	rQ   filesizerT   rS   maxCommentStartstartrecDatacommentSizecomments	            r   r3   r3      s    	IIaOyy{H
		>/1% 99;DD	^#Qq	%%RS	[ /6F| 	ch/0 TN?F;; (g.?COIIoq!99;DJJ'(EzuU>12w<>)fmm$4g>?./u^+E.,@,LMgo-. T?U#:X#E#% 	% W  s   F= =	G	G	c                   0    e Zd ZdZdZddZd	dZd Zd Zy)
r   z>Class with attributes describing each file in the ZIP archive.)orig_filenamer=   	date_timecompress_typers   extracreate_systemrZ   extract_versionreserved	flag_bitsvolumeinternal_attrexternal_attrheader_offsetCRCcompress_size	file_size	_raw_timec                    || _         |j                  t        d            }|dk\  r|d| }t        j                  dk7  r2t        j                  |v r |j                  t        j                  d      }|| _        || _        |d   dk  rt        d      t        | _
        d| _        d| _        t        j                  dk(  rd| _        nd| _        t         | _        t         | _        d| _        d| _        d| _        d| _        d| _        y )Nr   /  z+ZIP does not support timestamps before 1980r   win32r%   )ru   findchrossepreplacer=   rv   
ValueErrorr   rw   rs   rx   sysplatformry   DEFAULT_VERSIONrZ   rz   r{   r|   r}   r~   r   )selfr=   rv   	null_bytes       r   __init__zZipInfo.__init__=  s    % MM#a&)	>),H 66S=RVVx/''4H "Q<$JKK (
<<7"!"D "#D-.r   Nc                    | j                   }|d   dz
  dz  |d   dz  z  |d   z  }|d   dz  |d	   dz  z  |d   dz  z  }| j                  d
z  rdx}x}}n$| j                  }| j                  }| j                  }| j
                  }d}	||t        kD  xs	 |t        kD  }|r4d}
|t        j                  |
dt        j                  |
      d	z
  ||      z   }|t        kD  s	|t        kD  r|st        d      d}d}t        }	| j                  t        k(  rt        t        |	      }	n#| j                  t         k(  rt        t"        |	      }	t        |	| j$                        | _        t        |	| j&                        | _        | j)                         \  }}t        j                  t*        t,        | j$                  | j.                  || j                  |||||t1        |      t1        |            }||z   |z   S )z'Return the per-file header as a string.r   r   r*   r#   r'   r$   r%   r,   r&   r   z<HHQQ'Filesize would require ZIP64 extensions    )rv   r|   r   r   r   rx   ZIP64_LIMITrC   packcalcsizer   ZIP64_VERSIONrw   r   rk   BZIP2_VERSIONr	   LZMA_VERSIONrz   rZ   _encodeFilenameFlagsstructFileHeaderstringFileHeaderr{   rB   )r   zip64dtdosdatedostimer   r   r   rx   min_versionfmtr=   r|   headers                 r   
FileHeaderzZipInfo.FileHeaderg  s   ^^a54<A%1
2RU:Q%2+1
*beqj9>>D .//C/-)((C ..MI

=+J}{/JECFKKvs+A-y-I IE{"mk&A"#LMM #I&M'K*m[9K8+lK8K";0D0DE!+t/B/BC"779)-/?%%t}}i##Wgs	XE
	,
  5((r   c                     	 | j                   j                  d      | j                  fS # t        $ r- | j                   j                  d      | j                  dz  fcY S w xY w)Nasciiutf-8   )r=   encoder|   UnicodeEncodeErrorr   s    r   r   zZipInfo._encodeFilenameFlags  sZ    	I==''0$..@@! 	I==''0$..52HHH	Is   &) 3AAc                    | j                   }t        j                  }|r |d|d d       \  }}|dk(  r|dk\  r |d|dd       }n:|dk(  r |d|dd	       }n(|d
k(  r |d|dd       }n|dk(  rd}nt        d|      d}| j                  dv r||   | _        |dz  }| j
                  dk(  r||   | _        |dz  }| j                  dk(  r| j                  }||   | _        |dz  }||dz   d  }|ry y )N<HHr&   r#      z<QQQ   r/   z<QQr   r   z<Qr   r   r   zCorrupt extra field )l    r   r   )rx   rC   rD   RuntimeErrorr   r   r   )r   rx   rD   tplncountsidxolds           r   _decodeExtrazZipInfo._decodeExtra  s&   

E5!9-FBQw8#FE!BK8F2X#E52;7F1W#D%"+6F1WF&'EFF >>%EE%+C[DN1HC%%3)/D&1HC%%3,,C)/D&FC"Q$%LE= r   )NoName)r   r#   r#   r   r   r   N)	r   r   r   r   	__slots__r   r   r   r   r   r   r   r   r   $  s#    H
I,#T,)\I"!r   r   c                   <    e Zd ZdZd Z e       Zd Zd Zd Zd Z	y)_ZipDecryptera  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                      d} dgdz  }t        d      D ]2  }|}t        d      D ]  }|dz  r|dz	  dz  | z  }|dz	  dz  } |||<   4 |S )zGenerate 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[ r      r   r#   r   )range)polytableicrcjs        r   _GenerateCRCTablez_ZipDecrypter._GenerateCRCTable  sy     c	s 	AC1X 471H
2d:C1H
2C	4
 E!H	 r   c                 >    |dz	  dz  | j                   ||z  dz     z  S )z(Compute the CRC32 primitive on one byte.r   i    )crctable)r   chr   s      r   _crc32z_ZipDecrypter._crc32  s(    X%bD7H)IIIr   c                 ^    d| _         d| _        d| _        |D ]  }| j                  |        y )NixV4igE#ixV4)key0key1key2_UpdateKeys)r   pwdps      r   r   z_ZipDecrypter.__init__  s4    			 	 AQ	 r   c                 $   | j                  || j                        | _        | j                  | j                  dz  z   dz  | _        | j                  dz  dz   dz  | _        | j                  | j                  dz	  dz  | j                        | _        y )Nr   r   ir#   r   )r   r   r   r   )r   cs     r   r   z_ZipDecrypter._UpdateKeys  sr    KK499-	YY$))c/2j@	YY*Q.*<	KKbC 7C	r   c                     t        |t              sJ | j                  dz  }|||dz  z  dz	  dz  z  }| j                  |       |S )zDecrypt a single character.r$   r#   r   r   )
isinstanceintr   r   )r   r   ks      r   __call__z_ZipDecrypter.__call__  sN    !S!!!IIM1!9"c)*r   N)
r   r   r   r   r   r   r   r   r   r   r   r   r   r   r     s,    
$ !"HJ Dr   r   c                   $    e Zd Zd Zd Zd Zd Zy)LZMACompressorc                     d | _         y r   )_compr   s    r   r   zLZMACompressor.__init__  s	    
r   c                 .   t        j                  dt         j                  i      }t        j                  t         j                  t        j
                  t         j                  |      g      | _        t        j                  dddt        |            |z   S )Nidfiltersz<BBHr*   r&   )
lzma_encode_filter_propertiesFILTER_LZMA1r   
FORMAT_RAW_decode_filter_propertiesr   rC   r   rB   )r   propss     r   _initzLZMACompressor._init   sq    ..d6G6G/HI((..t/@/@%HC
 
 {{61aU4u<<r   c                     | j                   ,| j                         | j                   j                  |      z   S | j                   j                  |      S r   )r   r   compressr   rT   s     r   r   zLZMACompressor.compress  sA    ::::<$**"5"5d";;;zz""4((r   c                     | j                   +| j                         | j                   j                         z   S | j                   j                         S r   )r   r   flushr   s    r   r   zLZMACompressor.flush  s=    ::::<$**"2"2"444zz!!r   N)r   r   r   r   r   r   r   r   r   r   r   r     s    =)
"r   r   c                       e Zd Zd Zd Zy)LZMADecompressorc                 .    d | _         d| _        d| _        y )Nr   F)_decomp_unconsumedeofr   s    r   r   zLZMADecompressor.__init__  s    r   c           
      J   | j                   | xj                  |z  c_        t        | j                        dk  ryt        j                  d| j                  dd       \  }t        | j                        d|z   k  ryt        j                  t
        j                  t        j                  t
        j                  | j                  dd|z          g      | _         | j                  d|z   d  }| `| j                   j                  |      }| j                   j                  | _        |S )Nr&   r   z<Hr$   r   )r   r   rB   rC   rD   r   r   r   r   r   
decompressr   )r   rT   psizer>   s       r   r   zLZMADecompressor.decompress  s    <<$4##$)]]4)9)9!A)>?FE4##$E	1002243D3D ,,Qq5y9;K DL ##AIJ/D ((.<<##r   N)r   r   r   r   r   r   r   r   r   r     s    
r   r   storeshrinkreduceimplodetokenizedeflate	deflate64bzip2r   terse   lz77a   wavpackb   ppmdc                     | t         k(  ry | t        k(  rt        st        d      y | t        k(  rt
        st        d      y | t        k(  rt        st        d      y t        d      )Nz.Compression requires the (missing) zlib modulez-Compression requires the (missing) bz2 modulez.Compression requires the (missing) lzma modulez(That compression method is not supported)r   r   zlibr   r   bz2r	   r   )compressions    r   _check_compressionr  B  s    j 		$DF F  
		!CE E  
	 DF F  EFFr   c                     | t         k(  r3t        j                  t        j                  t        j                  d      S | t
        k(  rt        j                         S | t        k(  r
t               S y )N)
r   r	  compressobjZ_DEFAULT_COMPRESSIONDEFLATEDr   r
  BZ2Compressorr	   r   )rw   s    r   _get_compressorr  U  sY    $ : :]]C! 	!	)	#  ""	(	"r   c                    | t         k(  ry | t        k(  rt        j                  d      S | t        k(  rt        j                         S | t        k(  r
t               S t        j                  |       }|rt        d| |fz        t        d| fz        )Nr  zcompression type %d (%s)zcompression type %d)r   r   r	  decompressobjr   r
  BZ2Decompressorr	   r   compressor_namesgetNotImplementedError)rw   descrs     r   _get_decompressorr  a  s    
"	,	&!!#&&	)	#""$$	(	"!! $$]3%&@MSXCY&YZZ%&;}>N&NOOr   c                        e Zd ZdZ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d Zd Z fdZ xZS )
ZipExtFilezZFile-like object for reading an archive member.
       Is returned by ZipFile.open().
    i   @i   s*   ^(?P<chunk>[^\r\n]+)|(?P<newline>\n|\r\n?)c                    || _         || _        || _        |j                  | _        |j
                  | _        |j                  | _        t        | j                        | _
        d| _        d| _        d| _        d|v | _        d | _        | j                  | xj                  dz  c_        || _        |j"                  | _        t'        |d      r%|j(                  | _        t-        d      dz  | _        y d | _        y )NFr   r   Ur   r   r   )_fileobj
_decrypter_close_fileobjrw   _compress_typer   _compress_leftr   _leftr  _decompressor_eof_readbuffer_offset
_universalnewlinesmoder=   namer;   r   _expected_crccrc32_running_crc)r   fileobjr,  zipinfo	decrypterclose_fileobjs         r   r   zZipExtFile.__init__  s    #+%33%33&&
.t/B/BC	+ ??&2%	$$	7E"!(D %c
Z 7D!%Dr   c                 V   | j                   sU|dk  rP| j                  j                  d| j                        dz   }|dkD  r"| j                  | j                  | }|| _        |S | j                   s t        j
                  j                  | |      S d}|dk  st        |      |k  r| j                  d      }|dk(  r|S | j                  j                  |      }|j                  d      }|_| j                  g | _        || j                  vr| j                  j                  |       | xj                  t        |      z  c_        |dz   S |j                  d      }|dk\  r|d|t        |      z
   }| xj                  t        |      z  c_        ||z  }|dk  rt        |      |k  r|S )	zrRead and return a line from the stream.

        If limit is specified, at most limit bytes will be read.
        r      
r#   r   r$   newlineNchunk)r*  r(  r   r)  ioBufferedIOBasereadlinerB   peekPATTERNsearchgroupr+  rj   )r   limitr   line	readaheadmatchr7  r8  s           r   r;  zZipExtFile.readline  s    519  %%eT\\:Q>A1u''a8 $$--dE::ai3t9u,		!IC LL''	2Ekk),G"==($&DM$--/MM((1G,e|#KK(Ez1D	 12LLCJ&LEMD9 ai3t9u,< r   c                 x   |t        | j                        | j                  z
  kD  rp| j                  |      }t        |      | j                  kD  r)|| j                  | j                  d z   | _        d| _        n| xj                  t        |      z  c_        | j                  | j                  | j                  dz    S )z6Returns buffered bytes without advancing the position.Nr   i   )rB   r(  r)  r9   )r   nr8  s      r   r<  zZipExtFile.peek  s    s4##$t||33IIaLE5zDLL(#(4+;+;DLLM+J#J  E
* dllS.@AAr   c                      y)NTr   r   s    r   readablezZipExtFile.readable  s    r   c                    ||dk  r`| j                   | j                  d }d| _         d| _        | j                  s+|| j                  | j                        z  }| j                  s+|S || j                  z   }|t        | j                         k  r"| j                   | j                  | }|| _        |S |t        | j                         z
  }| j                   | j                  d }d| _         d| _        |dkD  ri| j                  s]| j                  |      }|t        |      k  r|| _         || _        ||d| z  }	 |S ||z  }|t        |      z  }|dkD  r| j                  s]|S )zRead and return up to n bytes.
        If the argument is omitted, None, or negative, data is read and returned until EOF is reached..
        Nr   r   )r(  r)  r'  _read1MAX_NrB   )r   rE  bufendrT   s        r   r9   zZipExtFile.read  sX    9A""4<<=1C"DDLiit{{4::.. iiJ$,,T%%&&""4<<4CDLJ#d&&''t||}-!eDII;;q>D3t9}#'  tBQx 
 4KCTNA !eDII 
r   c                     | j                   y t        || j                        dz  | _        | j                  r2| j                  | j                   k7  rt	        d| j
                  z        y y )Nr   zBad CRC-32 for file %r)r.  r/  r0  r'  r   r-  )r   newdatas     r   _update_crczZipExtFile._update_crc  sb    %!'4+<+<=
J99**d.@.@@5		ABB A9r   c                 .   ||dk  rI| j                   | j                  d }d| _         d| _        | j                  | j                        }||z  }|S || j                  z   }|t	        | j                         k  r"| j                   | j                  | }|| _        |S |t	        | j                         z
  }| j                   | j                  d }d| _         d| _        |dkD  r7| j                  |      }|t	        |      k  r|| _         || _        |d| }||z  }|S )z7Read up to n bytes with at most one read() system call.Nr   r   )r(  r)  rI  rJ  rB   )r   rE  rK  rT   rL  s        r   read1zZipExtFile.read1  s    9A""4<<=1C"DDL;;tzz*D4KCJ$,,T%%&&""4<<4CDLJ#d&&''t||}-q5;;q>D3t9}#'  BQx4KC
r   c                    | j                   s|dk  ry| j                  t        k(  rE| j                  j                  }|t        |      kD  r2|| j                  |t        |      z
        z  }n| j                  |      }| j                  t        k(  r| j                  dk  | _         n| j                  t        k(  rt        || j                        }| j                  j                  ||      }| j                  j                  xs( | j                  dk  xr | j                  j                   | _         | j                   re|| j                  j                         z  }nG| j                  j                  |      }| j                  j                  xs | j                  dk  | _         |d | j                   }| xj                  t        |      z  c_        | j                  dk  rd| _         | j                  |       |S )Nr   r   T)r'  r#  r   r&  unconsumed_tailrB   _read2r   r$  rk   MIN_READ_SIZEr   r   r   r%  rO  r   rE  rT   s      r   rI  zZipExtFile._read1,  s    99Q ,.%%55D3t9}AD	M22;;q>D*,++q0DI  L0At))*A%%00q9D++// ;''1, ;**::: I yy**0022%%006D**..J$2E2E2JDIKTZZ 

c$i
::?DIr   c                 F   | j                   dk  ryt        || j                        }t        || j                         }| j                  j                  |      }| xj                   t        |      z  c_         | j                  t        t        | j                  |            }|S )Nr   r   )
r$  rk   rU  minr   r9   rB   r!  bytesmaprV  s      r   rT  zZipExtFile._read2P  s    !#4%%&4&&'}}!!!$s4y(??&T__d34Dr   c                     	 | j                   r| j                  j                          t        | 	          y # t        | 	          w xY wr   )r"  r   closesuper)r   	__class__s    r   r\  zZipExtFile.close^  s4    	""##%GMOEGMOs	   &8 A)NF)r#   )r   r   r   r   rJ  rU  recompiler=  r   r;  r<  rG  r9   rO  rQ  rI  rT  r\  __classcell__)r^  s   @r   r  r  r  sl    
 E M bjjGHG9=$&B0dBBC<"H r   r  c                       e Zd ZdZdZdZdedfdZd Zd Z	d Z
d	 Zd
 ZddZd Zd Zd Zed        Zej&                  d        ZddZddZddZddZed        Zd Zd ZddZddZd Zd Zy) r   a   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), ZIP_DEFLATED (requires zlib),
                 ZIP_BZIP2 (requires bz2) or ZIP_LZMA (requires lzma).
    allowZip64: if True ZipFile will create files with ZIP64 extensions when
                needed, otherwise it will raise an exception when this would
                be necessary.

    NrFc                    |dvrt        d      t        |       || _        d| _        d| _        i | _        g | _        || _        |j                  dd      d   x| _	        }d| _
        d| _        t        | _        t        |t              r4d| _        || _        d	d
dd}	 t%        j&                  |||         | _        n d| _        || _        t-        |dd      | _        	 |dk(  r| j/                          y|dk(  rd| _        y|dk(  r8	 | j/                          | j(                  j1                  | j2                  d       yt        d      # t*        $ r, |dk(  r#dx}}t%        j&                  |||         | _        n Y w xY w# t4        $ r& | j(                  j1                  dd       d| _        Y yw xY w#  | j(                  }d| _        | j                   s|j7                           xY w)z>Open the ZIP file with mode read "r", write "w" or append "a".)re  waz(ZipFile() requires mode "r", "w", or "a"Fr   b Nr   r:   wbzr+brh  rg  r#   r-  re  Tr$   zMode must be "r", "w" or "a")r   r  _allowZip64
_didModifydebug
NameToInfofilelistr  r   r,  r   _commentZIP_CODEPAGEcodepager   str_filePassedr=   r9  r<   r6   r4   getattr_RealGetContentsr@   	start_dirr   r\  )r   filer,  r  
allowZip64keymodeDictr6   s           r   r   zZipFile.__init__y  s   &IJJ;'%
&,,sB/22	C$ dC  D DM"U;H''$7  !DDG#D&$7DM	cz%%' #'+))+GGLL3 ##ABBA  3;!$$D3 ggdHTN;DG 0 " +GGLLA& '+DO+	BDG##
sN   E
 F4 5F4 F4 6F ?F4 
2E?>E?,F1.F4 0F11F4 42G&c                     | S r   r   r   s    r   	__enter__zZipFile.__enter__  s    r   c                 $    | j                          y r   r\  )r   typevalue	tracebacks       r   __exit__zZipFile.__exit__  s    

r   c                 2   | j                   }	 t        |      }|st        d      | j                  dkD  rt        |       |t           }|t           }|t           | _	        |t           |z
  |z
  }|t           t        k(  r|t        t        z   z  }| j                  dkD  r||z   }t        d|||       ||z   | _        |j!                  | j                  d       |j#                  |      }t%        j&                  |      }d}||k  r{|j#                  t(              }	t+        |	      t(        k7  rt        d      t-        j.                  t0        |	      }	|	t2           t4        k7  rt        d      | j                  dkD  rt        |	       |j#                  |	t6                 }
|	d   }|d	z  r|
j9                  d
      }
n|
j9                  | j:                        }
t=        |
      }|j#                  |	t>                 |_         |j#                  |	tB                 |_"        |	tF           |_$        |	dd \  |_%        |_&        |_'        |_(        |_)        |_*        }}|_+        |_,        |_-        |jN                  t\        kD  rt_        d|jN                  dz  z        |	dd \  |_0        |_1        |_2        ||_3        |dz	  dz   |dz	  dz  |dz  |dz	  |dz	  dz  |dz  dz  f|_4        |jk                          |jH                  |z   |_$        | jl                  jo                  |       || jp                  |jr                  <   |t(        z   |	t6           z   |	t>           z   |	tB           z   }| j                  dkD  rt        d|       ||k  rzyy# t        $ r t        d      w xY w)z/Read in the table of contents for the ZIP file.zFile is not a zip filer#   r$   zgiven, inferred, offsetr   zTruncated central directoryz&Bad magic number for central directoryr'   r   r   r   zzip file version %.1fr+   r.   r1   r*   r      r,   r"   totalN):r6   r3   r4   r   rn  printrO   rP   _ECD_COMMENTrq  _ECD_LOCATIONrJ   rI   rG   rA   rx  r@   r9   r9  BytesIOsizeCentralDirrB   rC   rD   structCentralDir_CD_SIGNATUREstringCentralDir_CD_FILENAME_LENGTHdecoders  r   _CD_EXTRA_FIELD_LENGTHrx   _CD_COMMENT_LENGTHrs   _CD_LOCAL_HEADER_OFFSETr   rZ   ry   rz   r{   r|   rw   r   r   r   MAX_EXTRACT_VERSIONr  r}   r~   r   r   rv   r   rp  rj   ro  r=   )r   r6   rS   size_cd	offset_cdconcatinferredrT   r  centdirr=   flagsxtds                  r   rw  zZipFile._RealGetContents  sh   WW	7 _F 566::>&M#;'	|, &09<.!%77'*AABF::>	)H+Y&I"V+
"wwwZZgoggn-G7|~- !>??mm$4g>G}%)99 !IJJzzA~gwww':;<HAJEu}#??73 $??4==9!Aggg&<=>AG(: ;<AI%&=>AO 8?q}5Qq0A1:Q_aq  #66)*A+,+<+<r+A+C D D9@B6AHaoqAKT4K!Q$QtV%&UQT4K!D&AHAK NNoo6AOMM  #*+DOOAJJ' ^+g6I.JJ567123E zzA~gu%[ go3  	7566	7s   N Nc                 T    | j                   D cg c]  }|j                   c}S c c}w )z+Return a list of file names in the archive.)rp  r=   r   s     r   namelistzZipFile.namelist  s    *.--8$888s   %c                     | j                   S )zJReturn a list of class ZipInfo instances for files in the
        archive.)rp  r   s    r   infolistzZipFile.infolist       }}r   c                     t        ddz  |       | j                  D ];  }d|j                  dd z  }t        d|j                  ||j                  fz  |       = y)z+Print a table of contents for the zip file.z%-46s %19s %12s)z	File NamezModified    Sizery  z%d-%02d-%02d %02d:%02d:%02dNr(   z%-46s %s %12d)r  rp  rv   r=   r   )r   ry  zinfodates       r   printdirzZipFile.printdir  s_    "GG	]] 	E05??2A3FFD/U^^T5??$KK	r   c                    d}| j                   D ]L  }	 | j                  |j                  d      5 }|j                  |      r	 |j                  |      rddd       N y# 1 sw Y   xY w# t        $ r |j                  cY c S w xY w)z%Read all the files and check the CRC.i   re  N)rp  r<   r=   r9   r   )r   
chunk_sizer  fs       r   testzipzZipFile.testzip!  s    
]] 	&E& YYu~~s3 q&&, &&,		&   &~~%&s(   A+$AA+A(	$A++BBc                 \    | j                   j                  |      }|t        d|z        |S )z,Return the instance of ZipInfo given 'name'.z(There is no item named %r in the archive)ro  r  KeyError)r   r-  infos      r   getinfozZipFile.getinfo.  s9    ""4(<:TAC C r   c                 x    |r't        |t              st        dt        |      z        |r|| _        yd| _        y)z)Set default password for encrypted files.pwd: expected bytes, got %sN)r   rY  	TypeErrorr  r   )r   r   s     r   setpasswordzZipFile.setpassword7  s4    z#u-9DIEFFDHDHr   c                     | j                   S )z.The comment text associated with the ZIP file.)rq  r   s    r   rs   zZipFile.comment@  r  r   c                     t        |t              st        dt        |      z        t	        |      t
        k\  r'| j                  rt        dt
        z         |d t
         }|| _        d| _	        y )Nzcomment: expected bytes, got %sz3Archive comment is too long; truncating to %d bytesT)
r   rY  r  r  rB   ZIP_MAX_COMMENTrn  r  rq  rm  )r   rs   s     r   rs   zZipFile.commentE  sb    '5)=WMNNw<?*zzK)* +./Gr   c                 t    | j                  |d|      5 }|j                         cddd       S # 1 sw Y   yxY w)z)Return file bytes (as a string) for name.re  N)r<   r9   )r   r-  r   r6   s       r   r9   zZipFile.readR  s2    YYtS#& 	"779	 	 	s   .7c                    |dvrt        d      |r't        |t              st        dt	        |      z        | j
                  st        d      | j                  r| j
                  }n t        j                  | j                  d      }	 t        |t              r|}n| j                  |      }|j                  |j                  d       |j                  t              }t!        |      t        k7  rt#        d      t%        j&                  t(        |      }|t*           t,        k7  rt#        d      |j                  |t.                 }|t0           r|j                  |t0                  |j2                  d	z  rt5        d
      |j2                  dz  rt5        d      |j2                  dz  r|j7                  d      }n|j7                  | j8                        }||j:                  k7  rt#        d|j:                  d|d      |j2                  dz  }	d}
|	r|s| j<                  }|st        d|z        t?        |      }
|j                  d      }tA        tC        |
|dd             }|j2                  dz  r|jD                  dz	  dz  }n|jF                  dz	  dz  }|d   |k7  rt        d|      tI        ||||
| j                         S #  | j                  s|jK                           xY w)z#Return file-like object for 'name'.)re  r  rUz&open() requires mode "r", "U", or "rU"r  z3Attempt to read ZIP archive that was already closedr:   r   zTruncated file headerz Bad magic number for file header    z$compressed patched data (flag bit 5)@   zstrong encryption (flag bit 6)r   r   zFile name in directory z and header z differ.r#   Nz6File %s is encrypted, password required for extractionr   r   r   r   r,   zBad password for file)r4  )&r   r   rY  r  r  r6   ru  r9  r<   r=   r   r  r@   r   r9   sizeFileHeaderrB   r   rC   rD   r   _FH_SIGNATUREr   _FH_FILENAME_LENGTH_FH_EXTRA_FIELD_LENGTHr|   r  r  rs  ru   r   r   ri   rZ  r   r   r  r\  )r   r-  r,  r   zef_filer  fheaderfname	fname_stris_encryptedzdr   h
check_bytes                 r   r<   zZipFile.openW  s   ''GHHz#u-9DIEFFwwGI I
 wwHwwt}}d3HI	$( T*MM%--q1 mmN3G7|~- !899mm$4g>G}%)99 !CDDMM'*=">?E-.g&<=>%)*PQQ%)*JKK&!LL1	!LL7	E/// **E34 4
 !??S0LB((C& (ACG(H I I #3' "r*R"./??S("'//Q"6$!>J #())r/T!9JR5J&&'>EEheR040@0@,@B B	## s   
IK K,c                     t        |t              s| j                  |      }|t        j                         }| j                  |||      S )a#  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'.
        )r   r   r  r   getcwd_extract_member)r   memberpathr   s       r   extractzZipFile.extract  sA     &'*\\&)F<99;D##FD#66r   c                 \    || j                         }|D ]  }| j                  |||        y)zExtract 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   r  membersr   r2  s        r   
extractallzZipFile.extractall  s3     ?mmoG 	-GLL$,	-r   c                     | j                   }|s+d}t        j                  |dt        |      z        }|| _         |j	                  |      }d |j                  |      D        }|j                  d |D              }|S )z;Replace bad characters and remove trailing dots from parts.z:<>|"?*_c              3   >   K   | ]  }|j                  d         yw).N)rstrip.0r  s     r   	<genexpr>z1ZipFile._sanitize_windows_name.<locals>.<genexpr>  s     AQ188C=As   c              3   &   K   | ]	  }|s|  y wr   r   r  s     r   r  z1ZipFile._sanitize_windows_name.<locals>.<genexpr>  s     7QQq7s   )!_windows_illegal_name_trans_tablert  	maketransrB   	translatesplitjoin)clsarcnamepathsepr   illegals        r   _sanitize_windows_namezZipFile._sanitize_windows_name  st     55GMM'3W+=>E49C1##E*A'--*@A,,7'77r   c                    |j                   j                  dt        j                  j                        }t        j                  j
                  rB|j                  t        j                  j
                  t        j                  j                        }t        j                  j                  |      d   }dt        j                  j                  t        j                  j                  ft        j                  j                  j                  fd|j                  t        j                  j                        D              }t        j                  j                  dk(  r*| j                  |t        j                  j                        }t        j                  j                  ||      }t        j                  j                  |      }t        j                  j                  |      }|r4t        j                  j                  |      st        j                  |       |j                   d   dk(  r6t        j                  j!                  |      st        j"                  |       |S | j%                  ||      5 }t%        |d      5 }t'        j(                  ||       d	d	d	       d	d	d	       |S # 1 sw Y   xY w# 1 sw Y   |S xY w)
zbExtract the ZipInfo object 'member' to a physical
           file on the path targetpath.
        r   r#   rj  c              3   *   K   | ]
  }|vr|  y wr   r   )r  r  invalid_path_partss     r   r  z*ZipFile._extract_member.<locals>.<genexpr>  s#      #C&'/A&A $% #Cs   \r`  )r   rk  N)r=   r   r   r  r   altsep
splitdrivecurdirpardirr  r  r  normpathdirnameexistsmakedirsisdirmkdirr<   shutilcopyfileobj)	r   r  
targetpathr   r  	upperdirssourcetargetr  s	           @r   r  zZipFile._extract_member  s    //))#rww{{;77>>oobggnnbggkkBG ''$$W-a0 "''.."''..A''++"" #CgmmBGGKK.H #C C77;;$11'277;;GGWW\\*g6
WW%%j1
 GGOOJ/	RWW^^I6KK	"??2#%77==,$YYv3Y' 	/6*d#	/'-vv.	/ 	/ 		/ 	/ 	/ s$   8J:J.J:.J7	3J::Kc                    |j                   | j                  v r"| j                  rt        d|j                          | j                  dvrt        d      | j                  st        d      t        |j                         |j                  t        kD  r| j                  st        d      |j                  t        kD  r| j                  st        d      yy)z6Check for errors before writing a file to the archive.zDuplicate name:rg  rh  z write() requires mode "w" or "a"z4Attempt to write ZIP archive that was already closedr   z+Zipfile size would require ZIP64 extensionsN)r=   ro  rn  r  r,  r   r6   r  rw   r   r   rl  r   r   )r   r  s     r   _writecheckzZipFile._writecheck  s    >>T__,zz'899J&ABBwwHJ J5../??[(##"#LMM,##"CE E $ -r   c                  	   | j                   st        d      t        j                  |      }t        j                  |j
                        }t        j                  |j                        }|dd }||}t        j                  j                  t        j                  j                  |      d         }|d   t        j                  t        j                  fv r+|dd }|d   t        j                  t        j                  fv r+|r|dz  }t        ||      }|d   dz  dz  |_        || j                   |_        n||_        |j$                  |_        d|_        | j                   j+                         |_        |j"                  t.        k(  r|xj(                  d	z  c_        | j1                  |       d
| _        |rtd|_        d|_        d|_        | j8                  j;                  |       || j<                  |j>                  <   | j                   jA                  |jC                  d             ytE        |j"                        }	tG        |d      5 }
dx|_        }dx|_        }| jH                  xr |j&                  dz  tJ        kD  }| j                   jA                  |jC                  |             d}	 |
jM                  d      }|snZ|tO        |      z   }tQ        ||      dz  }|	r|	jS                  |      }|tO        |      z   }| j                   jA                  |       n	 ddd       |	rA|	jU                         }tO        |      z   }| j                   jA                  |       ||_        n|_        |_        |_        s4| jH                  r(|tJ        kD  rt        d      tJ        kD  rt        d      | j                   j+                         }| j                   jW                  |j,                  d       | j                   jA                  |jC                  |             | j                   jW                  |d       | j8                  j;                  |       || j<                  |j>                  <   y# 1 sw Y   SxY w)zLPut the bytes from filename into the archive under the name
        arcname.7Attempt to write to ZIP archive that was already closedr   r(   Nr#   r   r   r/   r$   TFr:   g?i    r   z*File size has increased during compressingz-Compressed size larger than uncompressed size),r6   r   r   statS_ISDIRst_modetime	localtimest_mtimer  r  r  r   r  r   r   r  rw   st_sizer   r|   re   r   r	   r  rm  r   r   rp  rj   ro  r=   writer   r  r<   rl  r   r9   rB   r/  r   r   r@   )r   r=   r  rw   str  mtimerv   r  cmprr6   r   r   r   r   rK  positions                    r   r  zZipFile.write  s    wwKM M WWXRZZ(r{{+!AJ	?G''""277#5#5g#>q#ABajRVVRYY//abkG ajRVVRYY//sNG+!!uv~"4 "&"2"2E"/E**"gglln(*OOt#OEO"#EEIMM  '.3DOOENN+GGMM%**512u223(D! 	#REI233E-$$ 9OOd*[8 GGMM%**512Iggh'%C0	Co
2--,C$1CH$<Mc"  	#& **,C)CH4MGGMM#"/E"+E	#));&"#OPP{*"#RSS 77<<>U((!,e&&u-.Xq!U#*/'Q	# 	#s   CQ33Q=c                 p   t        |t              r|j                  d      }t        |t              sNt        |t	        j
                  t	        j                               dd       }| j                  |_        d|_        n|}| j                  st        d      t        |      |_        | j                  j                         |_        |||_        |j                  t        k(  r|xj                   dz  c_        | j#                  |       d| _        t'        |      d	z  |_        t+        |j                        }|r3|j-                  |      |j/                         z   }t        |      |_        n|j                  |_        |j                  t2        kD  xs |j0                  t2        kD  }|r| j4                  st7        d
      | j                  j9                  |j;                  |             | j                  j9                  |       |j                   dz  rU|rdnd}| j                  j9                  t=        j>                  ||j(                  |j0                  |j                               | j                  j/                          | j@                  jC                  |       || jD                  |jF                  <   y)a  Write a file into the archive.  The contents is 'data', which
        may be either a 'str' or a 'bytes' instance; if it is a 'str',
        it is encoded as UTF-8 first.
        'zinfo_or_arcname' is either a ZipInfo instance or
        the name of the file in the archive.r   Nr(   )r=   rv   i  r  r$   Tr   r   r   z<LQQz<LLL)$r   rt  r   r   r  r  r  rw   r   r6   r   rB   r   re   r   r	   r|   r  rm  r/  r   r  r   r   r   r   rl  r   r  r   rC   r   rp  rj   ro  r=   )r   zinfo_or_arcnamerT   rw   r  cor   r   s           r   writestrzZipFile.writestrn  s    dC ;;w'D*G4%5&*nnTYY[&A"1&EGE"&"2"2E"-E$EwwKM M d)"gglln$"/E(*OOt#O$K*,	U001;;t$rxxz1D"%d)E"'//E+- 2##k1 	))HIIe&&u-.d??T!!&vCGGMM&++c599e6I6I//# $U#*/'r   c                 $    | j                          y)z2Call the "close()" method in case the user forgot.Nr  r   s    r   __del__zZipFile.__del__  s    

r   c                    | j                   y	 | j                  dv r| j                  rxd}| j                   j                         }| j                  D ]  }|dz   }|j
                  }|d   dz
  dz  |d   dz  z  |d   z  }|d	   d
z  |d   dz  z  |d   dz  z  }g }|j                  t        kD  s|j                  t        kD  r;|j                  |j                         |j                  |j                         d}d}	n|j                  }|j                  }	|j                  t        kD  r|j                  |j                         d}
n|j                  }
|j                  }d}|r<t        j                  ddt        |      z  z   ddt        |      z  g| |z   }t        }|j                   t"        k(  rt%        t&        |      }n#|j                   t(        k(  rt%        t*        |      }t%        ||j,                        }t%        ||j.                        }	 |j1                         \  }}t        j                  t2        t4        ||j6                  ||j8                  ||j                   |||j:                  |	|t        |      t        |      t        |j<                        d|j>                  |j@                  |
      }| j                   jO                  |       | j                   jO                  |       | j                   jO                  |       | j                   jO                  |j<                          | j                   j                         }|}||z
  }|}|tP        k\  s|t        kD  s	|t        kD  rt        j                  tR        tT        ddddd||||      }| j                   jO                  |       t        j                  tV        tX        d|d      }| j                   jO                  |       t[        |d      }t[        |d      }t[        |d      }t        j                  t\        t^        dd||||t        | j`                        	      }| j                   jO                  |       | j                   jO                  | j`                         | j                   jc                          | j                   }d| _         | jd                  s|jg                          yy# tB        $ r tE        t2        t4        ||j6                  ||j8                  |jF                  |j                   |||j:                  |	|t        |jH                        t        |      t        |j<                        d|j>                  |j@                  |
ftJ        jL                          w xY w# | j                   }d| _         | jd                  s|jg                          w w xY w)zJClose the file, and for mode "w" and "a" write the ending
        records.Nr  r   r#   r   r*   r'   r$   r%   r,   r&   r   r   Qr   r  ,   r    r   )4r6   r,  rm  re   rp  rv   r   r   r   rj   r   rx   rC   r   rB   r   rw   r   rk   r   r	   r   rz   rZ   r   r  r  ry   r{   r   rs   r~   r   DeprecationWarningr  r|   r=   r   stderrr  ZIP_FILECOUNT_LIMITrH   rI   rE   rF   rX  rh   rg   rq  r   ru  r\  )r   countpos1r  r   r   r   rx   r   r   r   
extra_datar   rz   rZ   r=   r|   r  pos2centDirCountcentDirSizecentDirOffsetzip64endreczip64locrecrS   r6   s                             r   r\  zZipFile.close  s    77?d	yyJ&4??ww||~!]] =1E!AIEB!!ut|1BqEQJ>AFG erkBqEQJ6"Q%1*EGE4$22[@U__5U%8%89$.	(2$)OO	(-(;(;**[8U%8%89(2(-(;(;!&J"#K%+[[ %CJ 6 !1SZ<&927&9;E&F
 '4**i7&)-&E,,8&),&D&)+u7L7L&MO%(e6J6J%KN.3.H.H.J+)"(++.>,n!//%..%u':':GW!II}iM3z?C<Nu22E4G4G)#+" GGMM'*GGMM(+GGMM*-GGMM%--0{=1~ ww||~$"Tk $ $77!K/+-"(++.0BB1lL'#8K GGMM+."(++55q$#CK GGMM+.#&|V#<L"%k:">K$'z$BM%57G$%q,$/DMM@RT f%dmm,BDG##
 $] . /1A>!//%..!OOU-@-@'7!II}i/Z#emmBTu22E4G4G)+ 25= X BDG##
 $s'   HV B$S8G+V B7VV 2W r   )re  N)NN)NNN) r   r   r   r   r6   r  r   r   r~  r  rw  r  r  r  r  r  r  propertyrs   setterr9   r<   r  r  classmethodr  r  r  r  r  r  r\  r   r   r   r   r   f  s     
B(,%"%:% @DK&\9
&   ^^
 

Zx7
-  %NE&V0p20hjr   r   c                   .    e Zd ZdZdeddfdZd	dZd Zy)
r   zDClass to create ZIP archives with Python library files and packages.re  Fr`  c                 F    t         j                  | ||||       || _        y )N)r,  r  rz  )r   r   	_optimize)r   ry  r,  r  rz  optimizes         r   r   zPyZipFile.__init__  s'    t$K$. 	 	0!r   c                 L   t         j                  j                  |      \  }}t         j                  j                  |      rt         j                  j	                  |d      }t         j                  j                  |      r|r|d|}n|}| j                  rt        d|d|       | j                  |dd |      \  }}| j                  rt        d|       | j                  ||       t        j                  |      }|j                  d       |D ]  }	t         j                  j	                  ||	      }
t         j                  j                  |	      \  }}t         j                  j                  |
      rQt         j                  j                  t         j                  j	                  |
d            s| j                  |
|       |dk(  s| j                  |
dd |      \  }}| j                  rt        d|       | j                  ||        y
| j                  rt        d	|       t        j                  |      D ]  }	t         j                  j	                  ||	      }
t         j                  j                  |	      \  }}|dk(  sK| j                  |
dd |      \  }}| j                  rt        d|       | j                  ||        y
|dd
 dk7  rt        d      | j                  |dd |      \  }}| j                  rt        d|       | j                  ||       y
)a,  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.
        z__init__.pyr   zAdding package inasr   Adding.pyzAdding files from directoryNz.Files added with writepy() must end with ".py"zAdding file)r   r  r  r  r  isfilern  r  _get_codenamer  listdirremovesplitextwritepyr   )r   pathnamebasenamedirr-  initnamer  r  dirlistr=   r  rootexts                r   r1  zPyZipFile.writepy  s    GGMM(+	T77=="ww||Hm<Hww~~h'*2D9H#H::-xxH!%!3!3HQrNH!Mw::(G,

5'***X.}- ' 3H77<<(;D " 0 0 :ID#ww}}T*77>>"'',,t]*KL LLx8)-););D2J)1*3w::!(G4

5'23 ::7B "

8 4 3H77<<(;D " 0 0 :ID#e|)-););D2J)1*3w::!(G4

5'23 }%"FH H!//2INE7zzmW-JJug&r   c                 b    d fd	}|dz   }|dz   }|dz   }t         j                  |d      }t         j                  |d      } j                  dk(  rt        j                  j                  |      rEt        j                  |      j                  t        j                  |      j                  k\  r|x}	}
nt        j                  j                  |      rEt        j                  |      j                  t        j                  |      j                  k\  r|x}	}
ngt        j                  j                  |      rEt        j                  |      j                  t        j                  |      j                  k\  r|}
|}	nt        j                  j                  |      rDt        j                  |      j                  t        j                  |      j                  k\  r|}
|}	n ||      r|}
|}	n|x}
}	n j                  dk(  r|}
|}	n|}
|}	t        j                  j                  |
      r?t        j                  |
      j                  t        j                  |      j                  k\  s || j                  	      s|x}
}	t        j                  j                  |	      d
   }|r|d|}|
|fS )a   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).
        r`  c                     dd l }j                  rt        d|        	 |j                  | d|       y# |j                  $ r}t        |j
                         Y d }~yd }~ww xY w)Nr   	CompilingT)doraiser&  F)
py_compilern  r  rb  PyCompileErrormsg)ry  r&  r=  errr   s       r   _compilez)PyZipFile._get_codename.<locals>._compiled  s\    zzk4(""4"I  ,, cggs   4 A"AA"r+  z.pycz.pyoTFr   )r&  r#   r   r_  )	impcache_from_sourcer%  r   r  r,  r  r  r  )r   r2  r3  rA  file_pyfile_pycfile_pyopycache_pycpycache_pyor  r  archivenames   `           r   r-  zPyZipFile._get_codename]  s   		 e#f$f$++GT:++GU;>>Rx(!**bggg.>.G.GG"**%''..*''(#,,0@0I0II"**%''..-''+&//27773C3L3LL $"''..-''+&//27773C3L3LL $" G$(E'G&--EG ~~"#"#"GGNN5)GGEN++rwww/?/H/HH$..A&--EGggmmG,Q/%-{;K{##r   N)rj  )r   r   r   r   r   r   r1  r-  r   r   r   r   r     s     N"%:!B"?'BC$r   r   c           	         dd l }|j                  d      }| t        j                  dd  } | r| d   dvr t	        |       t        j
                  d       | d   dk(  rWt        |       dk7  r t	        |       t        j
                  d       t        | d   d      5 }|j                          d d d        y | d   dk(  r~t        |       dk7  r t	        |       t        j
                  d       t        | d   d      5 }|j                         }d d d        rt	        d	j                  |             t	        d
       y | d   dk(  r?t        |       dk7  r t	        |       t        j
                  d       t        | d   d      5 }| d   }|j                         D ]  }|j                  d      r$t        j                  j                  ||dd        }n t        j                  j                  ||      }t        j                  j!                  |      }t        j                  j#                  |      st        j$                  |       t'        |d      5 }	|	j)                  |j+                  |             d d d         	 d d d        y | d   dk(  rt        |       dk  r t	        |       t        j
                  d       fdt        | d   dd      5 }| dd  D ])  }
 ||
t        j                  j-                  |
             + 	 d d d        y y # 1 sw Y   y xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w# 1 sw Y   y xY w)Nr   aE          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
        r#   )-l-c-e-trK  r$   re  rN  z.The following enclosed file is corrupted: {!r}zDone testingrM  r%   z./rk  rL  c           	      t   t         j                  j                  |      r| j                  ||t               y t         j                  j                  |      rat        j                  |      D ]H  } | t         j                  j                  ||      t         j                  j                  ||             J y y r   )r   r  r,  r  r   r  r.  r  )zfr  zippathnmaddToZips       r   rS  zmain.<locals>.addToZip  s    ww~~d#w5t$**T* OBRGGLLr2BGGLL"4MOO %r   rg  T)rz  )textwrapdedentr   argvr  exitrB   r   r  r  formatr  
startswithr   r  r  r  r  r  r<   r  r9   r3  )argsrT  USAGErP  badfileoutr  tgttgtdirr6   srcrS  s              @r   mainra    s   
//  E |xx|47"::eAw$t9>%LHHQKT!Wc" 	bKKM	 	 
aDt9>%LHHQKT!Wc" 	#bjjlG	#BII'RSn	aDt9>%LHHQKT!Wc" 	,bq'C 
,??4('',,sDH5C'',,sD1C-ww~~f-KK'#t_ ,HHRWWT]+, ,
,	, 	, 
aDt9q=%LHHQK	O T!Wcd3 	9rABx 9S"''"2"23"789	9 	9 
A	 		# 	#,, ,	, 	,8	9 	9sI   L9L CL1!L$.
L12L=LL!$L.)L11L:=M__main__r   )yr   r9  r   ra  	importlibr   r  r  r  rC   binasciir	  r/  ImportErrorr
  r   __all__	Exceptionr   r   r   r   rr  r   r  r  r   r   r   r	   r   r   r   r   r  rh   rg   r   rf   rJ   rK   rL   rM   rN   rO   rP   rm   r  r  r  r  r  r  _CD_CREATE_VERSION_CD_CREATE_SYSTEM_CD_EXTRACT_VERSION_CD_EXTRACT_SYSTEM_CD_FLAG_BITS_CD_COMPRESS_TYPE_CD_TIME_CD_DATE_CD_CRC_CD_COMPRESSED_SIZE_CD_UNCOMPRESSED_SIZEr  r  r  _CD_DISK_NUMBER_START_CD_INTERNAL_FILE_ATTRIBUTES_CD_EXTERNAL_FILE_ATTRIBUTESr  r   r   r  r  _FH_EXTRACT_VERSION_FH_EXTRACT_SYSTEM_FH_GENERAL_PURPOSE_FLAG_BITS_FH_COMPRESSION_METHOD_FH_LAST_MOD_TIME_FH_LAST_MOD_DATE_FH_CRC_FH_COMPRESSED_SIZE_FH_UNCOMPRESSED_SIZEr  r  rE   rF   rA   rH   rI   rG   _CD64_SIGNATURE_CD64_DIRECTORY_RECSIZE_CD64_CREATE_VERSION_CD64_EXTRACT_VERSION_CD64_DISK_NUMBER_CD64_DISK_NUMBER_START_CD64_NUMBER_ENTRIES_THIS_DISK_CD64_NUMBER_ENTRIES_TOTAL_CD64_DIRECTORY_SIZE_CD64_OFFSET_START_CENTDIRr7   r
   rb   r3   objectr   r   r   r   r  r  r  r  r:  r  r   r   ra  r   r   r   r   <module>r     s>  
 
 	 	  
     JJE
L	 	9    
  
	       !12   	   $    !12      
      ! !   "    !12   !    
     % ) )&//*CD  " " "6??#56      !"     (V:zY!v Y!x8 8v" ". 8wx x x	
 x x y z y { 	      	!" # (G&	P"q"" qhj
 j
ZM$ M$`D9L zF i6  DNNE  
C
  Ds4   H H H) HHH&%H&)H43H4