Ë
    ojÐ%  ã                   óª   — d Z ddlZddlZddlZddlZ G d„ dej                  «      Z G d„ d«      Z G d„ de«      Z	 G d	„ d
e«      Z
dZd„ Zd„ Zdd„Zy)zŸ
An incremental approach to unzipping files.  This allows you to unzip a little
bit of a file at a time, which means you can report progress as a file unzips.
é    Nc                   ó   — e Zd ZdZd„ Zy)ÚChunkingZipFilez~
    A L{zipfile.ZipFile} object which, with L{readfile}, also gives you access
    to a file-like object for each entry.
    c                 óx  — | j                   dvrt        d«      ‚| j                  st        d«      ‚| j                  |«      }| j                  j	                  |j
                  d«       | j                  j                  t        j                  «      }|dd t        j                  k7  rt        j                  d«      ‚t        j                  t        j                  |«      }| j                  j                  |t        j                     «      }|t        j                     r,| j                  j                  |t        j                     «       |j                   dz  r|j#                  d«      }n|j#                  d	«      }||j$                  k7  r&t        j                  d
|j$                  ›d|›d�«      ‚|j&                  t        j(                  k(  rt+        | |j,                  «      S |j&                  t        j.                  k(  rt1        | |j,                  «      S t        j                  d|j&                  |fz  «      ‚)z3
        Return file-like object for name.
        )ÚrÚazread() requires mode "r" or "a"z3Attempt to read ZIP archive that was already closedr   é   z Bad magic number for file headeri   zutf-8Úcp437zFile name in directory "z" and header "z	" differ.z-Unsupported compression method %d for file %s)ÚmodeÚRuntimeErrorÚfpÚgetinfoÚseekÚheader_offsetÚreadÚzipfileÚsizeFileHeaderÚstringFileHeaderÚ
BadZipFileÚstructÚunpackÚstructFileHeaderÚ_FH_FILENAME_LENGTHÚ_FH_EXTRA_FIELD_LENGTHÚ	flag_bitsÚdecodeÚorig_filenameÚcompress_typeÚ
ZIP_STOREDÚZipFileEntryÚcompress_sizeÚZIP_DEFLATEDÚDeflatedZipFileEntry)ÚselfÚnameÚzinfoÚfheaderÚfnameÚ	fname_strs         ú:/usr/lib/python3/dist-packages/twisted/python/zipstream.pyÚreadfilezChunkingZipFile.readfile   sÁ  € ð �9‰9˜JÑ&ÜÐ@ÓAÐAØ�wŠwÜÐTÓUÐUØ—‘˜TÓ"ˆà�‰�‰�U×(Ñ(¨!Ô,à—'‘'—,‘,œw×5Ñ5Ó6ˆØ�1�Qˆ<œ7×3Ñ3Ò3Ü×$Ñ$Ð%GÓHÐHä—-‘-¤× 8Ñ 8¸'ÓBˆØ—‘—‘˜W¤W×%@Ñ%@ÑAÓBˆà”7×1Ñ1Ò2Ø�G‰G�L‰L˜¤×!?Ñ!?Ñ@ÔAà�?‰?˜UÒ"àŸ™ WÓ-‰IàŸ™ WÓ-ˆIà˜×+Ñ+Ò+Ü×$Ò$à×&Ó&ª	ð3óð ð
 ×Ñ¤'×"4Ñ"4Ò4Ü  e×&9Ñ&9Ó:Ð:Ø× Ñ ¤G×$8Ñ$8Ò8Ü'¨¨e×.AÑ.AÓBÐBä×$Ñ$Ø?Ø×&Ñ&¨Ð-ñ.óð ó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r*   © r+   r)   r   r      s   „ ñó
*r+   r   c                   óP   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ ZeZ	d„ Z
d„ Zd	„ Zd
„ Zd„ Zy)Ú
_FileEntrya!  
    Abstract superclass of both compressed and uncompressed variants of
    file-like objects within a zip archive.

    @ivar chunkingZipFile: a chunking zip file.
    @type chunkingZipFile: L{ChunkingZipFile}

    @ivar length: The number of bytes within the zip file that represent this
    file.  (This is the size on disk, not the number of decompressed bytes
    which will result from reading it.)

    @ivar fp: the underlying file object (that contains pkzip data).  Do not
    touch this, please.  It will quite likely move or go away.

    @ivar closed: File-like 'closed' attribute; True before this file has been
    closed, False after.
    @type closed: L{bool}

    @ivar finished: An older, broken synonym for 'closed'.  Do not touch this,
    please.
    @type finished: L{int}
    c                 ór   — || _         | j                   j                  | _        || _        d| _        d| _        y)zC
        Create a L{_FileEntry} from a L{ChunkingZipFile}.
        r   FN)ÚchunkingZipFiler   ÚlengthÚfinishedÚclosed©r#   r4   r5   s      r)   Ú__init__z_FileEntry.__init__[   s4   € ð  /ˆÔØ×&Ñ&×)Ñ)ˆŒØˆŒØˆŒØˆ�r+   c                  ó   — y)zD
        Returns false because zip files should not be ttys
        Fr0   ©r#   s    r)   Úisattyz_FileEntry.isattye   s   € ð r+   c                 ó$   — d| _         d| _        | `y)z/
        Close self (file-like object)
        Té   N)r7   r6   r   r;   s    r)   Úclosez_FileEntry.closek   s   € ð ˆŒØˆŒØ‰Gr+   c                 óN   ‡ — d}t        ˆ fd„d«      D ]  }||z  }|dk(  sŒ |S  |S )z
        Read a line.
        r+   c                  ó&   •— ‰ j                  d«      S )Nr>   )r   r;   s   €r)   ú<lambda>z%_FileEntry.readline.<locals>.<lambda>x   s   ø€  §¡¨1£€ r+   ó   
)Úiter)r#   ÚlineÚbytes   `  r)   Úreadlinez_FileEntry.readlines   s@   ø€ ð ˆÜÓ-¨sÓ3ò 	ˆDØ�D‰LˆDØ�u‹}ØØˆð		ð ˆr+   c                 ó>   — | j                  «       }|r|S t        «       ‚)zi
        Implement next as file does (like readline, except raises StopIteration
        at EOF)
        )rG   ÚStopIteration)r#   Únextlines     r)   Ú__next__z_FileEntry.__next__~   s   € ð
 —=‘=“?ˆÙØˆOÜ‹oÐr+   c                 ó   — t        | «      S )z1
        Returns a list of all the lines
        )Úlistr;   s    r)   Ú	readlinesz_FileEntry.readlines‹   s   € ô �D‹zÐr+   c                 ó   — | S ©z/
        Returns an iterator (so self)
        r0   r;   s    r)   Ú
xreadlinesz_FileEntry.xreadlines‘   ó	   € ð ˆr+   c                 ó   — | S rP   r0   r;   s    r)   Ú__iter__z_FileEntry.__iter__—   rR   r+   c                 ó   — | S ©Nr0   r;   s    r)   Ú	__enter__z_FileEntry.__enter__�   s   € Øˆr+   c                 ó$   — | j                  «        y rV   )r?   )r#   Úexc_typeÚ	exc_valueÚ	tracebacks       r)   Ú__exit__z_FileEntry.__exit__    s   € Ø�
‰
�r+   N)r,   r-   r.   r/   r9   r<   r?   rG   rK   ÚnextrN   rQ   rT   rW   r\   r0   r+   r)   r2   r2   C   s@   „ ñò.òòò	òð €Dòòòòór+   r2   c                   ó$   — e Zd ZdZd„ Zd„ Zdd„Zy)r   zJ
    File-like object used to read an uncompressed entry in a ZipFile
    c                 ó@   — t         j                  | ||«       d| _        y )Nr   )r2   r9   Ú	readBytesr8   s      r)   r9   zZipFileEntry.__init__©   s   € Ü×Ñ˜D /°6Ô:Øˆ�r+   c                 ó   — | j                   S rV   )r`   r;   s    r)   ÚtellzZipFileEntry.tell­   s   € Ø�~‰~Ðr+   Nc                 ó„  — |€| j                   | j                  z
  }|dk(  s| j                  ry| j                  j                  j                  t        || j                   | j                  z
  «      «      }| xj                  t        |«      z  c_        | j                  | j                   k(  st        |«      |k  rd| _        |S )Nr   r+   r>   )r5   r`   r6   r4   r   r   ÚminÚlen)r#   ÚnÚdatas      r)   r   zZipFileEntry.read°   s‘   € Øˆ9Ø—‘˜dŸn™nÑ,ˆAØ�Š6�T—]’]ØØ×#Ñ#×&Ñ&×+Ñ+¬C°°4·;±;ÀÇÁÑ3OÓ,PÓQˆØ�Šœ#˜d›)Ñ#�Ø�>‰>˜TŸ[™[Ò(¬C°«I¸ªMØˆDŒMØˆr+   rV   ©r,   r-   r.   r/   r9   rb   r   r0   r+   r)   r   r   ¤   s   „ ñòòô	r+   r   c                   ó$   — e Zd ZdZd„ Zd„ Zdd„Zy)r"   zE
    File-like object used to read a deflated entry in a ZipFile
    c                 ó�   — t         j                  | ||«       d| _        d| _        t	        j
                  d«      | _        d| _        y )Nr   iñÿÿÿr+   )r2   r9   ÚreturnedBytesr`   ÚzlibÚdecompressobjÚdecompÚbufferr8   s      r)   r9   zDeflatedZipFileEntry.__init__Á   s<   € Ü×Ñ˜D /°6Ô:ØˆÔØˆŒÜ×(Ñ(¨Ó-ˆŒØˆ�r+   c                 ó   — | j                   S rV   )rk   r;   s    r)   rb   zDeflatedZipFileEntry.tellÈ   s   € Ø×!Ñ!Ð!r+   Nc                 ó   — | j                   ry|�€| j                  g}|j                  | j                  j	                  | j
                  j                  j                  | j                  | j                  z
  «      «      «       |j                  | j                  j	                  d«      «       |j                  | j                  j                  «       «       d| _        d| _         dj                  |«      }| xj                  t        |«      z  c_        |S t        | j                  «      |k  �r | j
                  j                  j                  t        |d| j                  | j                  z
  «      «      }| xj                  t        |«      z  c_	        |sq| j                  | j                  j	                  d«      z   | j                  j                  «       z   }d| _         d| _        | xj                  t        |«      z  c_        |S | xj                  | j                  j	                  |«      z  c_        t        | j                  «      |k  r�Œ | j                  d | }| j                  |d  | _        | xj                  t        |«      z  c_        |S )Nr+   ó   Zr>   i   )r6   ro   Úappendrn   Ú
decompressr4   r   r   r5   r`   ÚflushÚjoinrk   re   rd   )r#   rf   Úresultrg   s       r)   r   zDeflatedZipFileEntry.readË   s÷  € Ø�=Š=ØØ‰9à—‘ðˆFð �M‰MØ—‘×&Ñ&Ø×(Ñ(×+Ñ+×0Ñ0°·±¸t¿~¹~Ñ1MÓNóôð
 �M‰M˜$Ÿ+™+×0Ñ0°Ó6Ô7Ø�M‰M˜$Ÿ+™+×+Ñ+Ó-Ô.ØˆDŒKØˆDŒMØ—X‘X˜fÓ%ˆFØ×Ò¤# f£+Ñ-ÕØˆMä�d—k‘kÓ" QÓ&Ø×+Ñ+×.Ñ.×3Ñ3Ü˜˜4 §¡¨t¯~©~Ñ!=Ó>ó�ð —’¤# d£)Ñ+•ÙàŸ™ d§k¡k×&<Ñ&<¸TÓ&BÑBÀTÇ[Á[×EVÑEVÓEXÑXð ð %&�D”MØ"%�D”KØ×&Ò&¬#¨f«+Ñ5Õ&Ø!�Mà—K’K 4§;¡;×#9Ñ#9¸$Ó#?Ñ?•Kô �d—k‘kÓ" QÔ&ð —[‘[  !�_ˆFØŸ+™+ a b˜/ˆDŒKØ×Ò¤# f£+Ñ-ÕØˆMr+   rV   rh   r0   r+   r)   r"   r"   ¼   s   „ ñòò"ô&r+   r"   é   c                 óh   — d}t        | «      }|j                  «       D ]  }|t        ||«      z  }Œ |S )zr
    Predict the number of chunks that will be extracted from the entire
    zipfile, given chunksize blocks.
    r   )r   ÚinfolistÚcountFileChunks)ÚfilenameÚ	chunksizeÚtotalchunksÚzfÚinfos        r)   ÚcountZipFileChunksr�   ÷   s?   € ð
 €KÜ	˜Ó	"€BØ—‘“ò 8ˆØ” t¨YÓ7Ñ7‰ð8àÐr+   c                 óT   — t        | j                  |«      \  }}|dkD  r|dz  }|xs dS )a9  
    Count the number of chunks that will result from the given C{ZipInfo}.

    @param zipinfo: a C{zipfile.ZipInfo} instance describing an entry in a zip
    archive to be counted.

    @return: the number of chunks present in the zip file.  (Even an empty file
    counts as one chunk.)
    @rtype: L{int}
    r   r>   )ÚdivmodÚ	file_size)Úzipinfor}   ÚcountÚextras       r)   r{   r{     s4   € ô ˜'×+Ñ+¨YÓ7�L€Eˆ5Øˆq‚yØ�‰
ˆØŠ:�AÐr+   c              #   óp  K  — t        | d«      }t        j                  j                  |«      st        j                  |«       t        | |«      }|j                  «       }|j                  «       }t        ||«      D �]©  \  }}	|	j                  t        z  }
t        j                  j                  ||«      }|
r>t        j                  j                  |«      st        j                  |«       |dz  }|–— Œzt        j                  j                  |«      d   }t        j                  j                  |«      st        j                  |«       |st        j                  j                  |«      s¦|j                  |«      }|	j                  dk(  r	|dz  }|–— t        |d«      5 }|j!                  «       |	j                  k  rI|j#                  |«      }|j%                  |«       |dz  }|–— |j!                  «       |	j                  k  rŒIddd«       �Œ—|t'        |	|«      z  }|–— �Œ¬ y# 1 sw Y   �Œ¸xY w­w)zï
    Return a generator for the zipfile.  This implementation will yield after
    every chunksize uncompressed bytes, or at the end of a file, whichever
    comes first.

    The value it yields is the number of chunks left to unzip.
    r   r>   r   ÚwbN)r   ÚosÚpathÚexistsÚmakedirsr�   Únamelistrz   ÚzipÚexternal_attrÚDIR_BITrv   Úsplitr*   r„   Úopenrb   r   Úwriter{   )r|   Ú	directoryÚ	overwriter}   ÚczfÚ	remainingÚnamesÚinfosÚentryr€   ÚisdirÚfÚfdirr   ÚoutfileÚhunks                   r)   ÚunzipIterChunkyr¡     sµ  è ø€ ô ˜( CÓ
(€CÜ�7‰7�>‰>˜)Ô$Ü
�‰�IÔÜ" 8¨YÓ7€IØ�L‰L‹N€EØ�L‰L‹N€Eä˜5 %Ó(ó  ‰ˆˆtØ×"Ñ"¤WÑ,ˆÜ�G‰G�L‰L˜ EÓ*ˆÙä—7‘7—>‘> !Ô$Ü—‘˜A”Ø˜‰NˆIØ‹Oô —7‘7—=‘= Ó# AÑ&ˆDÜ—7‘7—>‘> $Ô'Ü—‘˜DÔ!Ù¤§¡§¡¨qÔ 1Ø—\‘\ %Ó(�Ø—>‘> QÒ&Ø ‘N�IØ#’OÜ˜!˜T“]ð ( gØŸ'™'›) d§n¡nÒ4Ø!Ÿw™w yÓ1˜ØŸ™ dÔ+Ø! Q™˜	Ø'šð	 Ÿ'™'›) d§n¡nÓ4÷(ñ (ð œ_¨T°9Ó=Ñ=�	Ø”ñ9 ÷((ñ (üs   ‚FH6Æ!A&H)È!H6È)H3	È.H6)ú.r   i   )r/   Úos.pathrŠ   r   r   rl   ÚZipFiler   r2   r   r"   r‘   r�   r{   r¡   r0   r+   r)   ú<module>r¥      se   ðñ
ó
 Û Û Û ô0�g—o‘oô 0÷f^ñ ^ôB�:ô ô05˜:ô 5ðp €ò	òô"+ r+   