
    \d%                         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dS )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dS )ChunkingZipFilez~
    A L{zipfile.ZipFile} object which, with L{readfile}, also gives you access
    to a file-like object for each entry.
    c                    | j         dvrt          d          | j        st          d          |                     |          }| j                            |j        d           | j                            t          j                  }|dd         t          j	        k    rt          j
        d          t          j        t          j        |          }| j                            |t          j                           }|t          j                 r*| j                            |t          j                            |j        dz  r|                    d          }n|                    d	          }||j        k    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         8lib/python3.11/site-packages/twisted/python/zipstream.pyreadfilezChunkingZipFile.readfile   s    9J&&@AAAw 	VTUUUT""U(!,,,',,w5661Q3<7333$%GHHH- 8'BBWW%@ABB712 	BGLL!?@AAA?U" 	.W--IIW--I+++$$&&&			3  
 '"444e&9::: G$888'e.ABBB$?&-.      N)__name__
__module____qualname____doc__r*    r+   r)   r   r      s-         
* * * * *r+   r   c                   R    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dS )
_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                 `    || _         | j         j        | _        || _        d| _        d| _        dS )zC
        Create a L{_FileEntry} from a L{ChunkingZipFile}.
        r   FN)chunkingZipFiler   lengthfinishedclosedr#   r4   r5   s      r)   __init__z_FileEntry.__init__[   s2      /&)r+   c                     dS )zD
        Returns false because zip files should not be ttys
        Fr0   r#   s    r)   isattyz_FileEntry.isattye   s	     ur+   c                 &    d| _         d| _        | `dS )z/
        Close self (file-like object)
        T   N)r7   r6   r   r;   s    r)   closez_FileEntry.closek   s     GGGr+   c                 R     d}t           fdd          D ]}||z  }|dk    r n|S )z
        Read a line.
        r+   c                  .                          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   sN     ----s33 	 	DDLDu}} r+   c                 N    |                                  }|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oor+   c                      t          |           S )z1
        Returns a list of all the lines
        )listr;   s    r)   	readlinesz_FileEntry.readlines   s     Dzz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                 .    |                                   d S 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dS )r   zJ
    File-like object used to read an uncompressed entry in a ZipFile
    c                 L    t                               | ||           d| _        d S )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                 H   || j         | j        z
  }|dk    s| j        rdS | 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dn,A66T]63#&++C4;3O,P,PQQ#d))#>T[((CIIMMDMr+   rV   r,   r-   r.   r/   r9   rb   r   r0   r+   r)   r   r      sP             	 	 	 	 	 	r+   r   c                   &    e Zd ZdZd Zd ZddZdS )r"   zE
    File-like object used to read a deflated entry in a ZipFile
    c                     t                               | ||           d| _        d| _        t	          j        d          | _        d| _        d S )Nr   ir+   )r2   r9   returnedBytesr`   zlibdecompressobjdecompbufferr8   s      r)   r9   zDeflatedZipFileEntry.__init__   sF    D/6:::(--r+   c                     | j         S rV   )rk   r;   s    r)   rb   zDeflatedZipFileEntry.tell   s    !!r+   Nc                    | j         rdS || j        g}|                    | j                            | j        j                            | j        | j	        z
                                 |                    | j                            d                     |                    | j        
                                           d| _        d| _         d                    |          }| xj        t          |          z  c_        |S t          | j                  |k     r| j        j                            t          |d| j        | j	        z
                      }| xj	        t          |          z  c_	        |si| j        | j                            d          z   | j        
                                z   }d| _         d| _        | xj        t          |          z  c_        |S | xj        | j                            |          z  c_        t          | j                  |k     | 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   s3   = 	39F MM&&(+00t~1MNN   
 MM$+0066777MM$+++--...DKDMXXf%%F#f++-Mdk""Q&&+.334t~!=>>  #d))+ 	@dk&<&<T&B&BBT[EVEVEXEXX  %&DM"%DK&&#f++5&&!MKK4;#9#9$#?#??KK dk""Q&& [!_F+abb/DK#f++-Mr+   rV   rh   r0   r+   r)   r"   r"      sP           " " "& & & & & &r+   r"      c                 |    d}t          |           }|                                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      sI    
 K		"	"B 8 8tY777r+   c                 P    t          | j        |          \  }}|dk    r|dz  }|p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{     s6     '+Y77LE5qyy
:Ar+   .   c              #     K   t          | d          }t          j                            |          st          j        |           t          | |          }|                                }|                                }t          ||          D ]\  }}	|	j	        t          z  }
t          j                            ||          }|
r=t          j                            |          st          j        |           |dz  }|V  tt          j                            |          d         }t          j                            |          st          j        |           |st          j                            |          s|                    |          }|	j        dk    r	|dz  }|V  t          |d          5 }|                                |	j        k     rP|                    |          }|                    |           |dz  }|V  |                                |	j        k     Pddd           n# 1 swxY w Y   |t'          |	|          z  }|V  dS )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>>)$$ 
I"8Y77ILLNNELLNNE5%((    t"W,GLLE** 	 7>>!$$ ANIOOOO 7==##A&D7>>$'' "D!!!  q 1 1  \\%((>Q&&NI#OOO!T]] (g''))dn44!wwy11d+++!Q	'	 ''))dn44( ( ( ( ( ( ( ( ( ( ( ( ( ( ( _T9===	9   s   4A.H..H2	5H2	)r   r   r   )r/   os.pathr   r   r   rl   ZipFiler   r2   r   r"   r   r   r{   r   r0   r+   r)   <module>r      s+  
 
    0 0 0 0 0go 0 0 0f^ ^ ^ ^ ^ ^ ^ ^B    :   05 5 5 5 5: 5 5 5p 	 	 	  "+  +  +  +  +  + r+   