HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/python/__pycache__/zipstream.cpython-38.pyc
U


W[&�@s�dZddlZddlZddlZddlZe�ej�ZGdd�dej	�Z
Gdd�de�ZGdd�de�Z
Gd	d
�d
e�ZdZdd
�Zdd�Zddd�ZdS)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@seZdZdZdd�ZdS)�ChunkingZipFilez~
    A L{zipfile.ZipFile} object which, with L{readfile}, also gives you access
    to a file-like object for each entry.
    cCs&|jdkrtd��|js td��|�|�}|j�|jd�|j�t�}|dd�tj	krbt�
d��t�tj
|�}|j�|tj�}|tjr�|j�|tj�|jd@r�|�d�}n
|�d	�}||jkr�t�
d
|j|f��|jtjkr�t||j�S|jtjk�rt||j�St�
d|j|f��dS)
z3
        Return file-like object for name.
        )�r�azread() requires mode "r" or "a"z3Attempt to read ZIP archive that was already closedr�z Bad magic number for file headerizutf-8�cp437z3File name in directory "%s" and header "%s" differ.z-Unsupported compression method %d for file %sN)�mode�RuntimeError�fpZgetinfo�seek�
header_offset�read�_fileHeaderSize�zipfileZstringFileHeaderZ
BadZipfile�structZunpack�structFileHeaderZ_FH_FILENAME_LENGTHZ_FH_EXTRA_FIELD_LENGTHZ	flag_bits�decodeZ
orig_filenameZ
compress_typeZ
ZIP_STORED�ZipFileEntryZ
compress_sizeZZIP_DEFLATED�DeflatedZipFileEntry)�self�nameZzinfoZfheader�fnameZ	fname_str�r�:/usr/lib/python3/dist-packages/twisted/python/zipstream.py�readfilesD
�





����zChunkingZipFile.readfileN)�__name__�
__module__�__qualname__�__doc__rrrrrrsrc@sdeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZeZ	dd
�Z
dd�Zdd�Zdd�Z
dd�ZdS)�
_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}
    cCs&||_|jj|_||_d|_d|_dS)zC
        Create a L{_FileEntry} from a L{ChunkingZipFile}.
        rFN)�chunkingZipFiler	�length�finished�closed�rrr rrr�__init__]s

z_FileEntry.__init__cCsdS)zD
        Returns false because zip files should not be ttys
        Fr�rrrr�isattyhsz_FileEntry.isattycCsd|_d|_|`dS)z/
        Close self (file-like object)
        T�N)r"r!r	r%rrr�closeosz_FileEntry.closecs4d}t�fdd�d�D]}||7}|dkrq0q|S)z
        Read a line.
        �cs
��d�S)Nr')rrr%rr�<lambda>}r)z%_FileEntry.readline.<locals>.<lambda>�
)�iter)r�lineZbyterr%r�readlinexsz_FileEntry.readlinecCs|��}|r|St��dS)zi
        Implement next as file does (like readline, except raises StopIteration
        at EOF)
        N)r.�
StopIteration)rZnextlinerrr�__next__�sz_FileEntry.__next__cCst|�S)z1
        Returns a list of all the lines
        )�listr%rrr�	readlines�sz_FileEntry.readlinescCs|S�z/
        Returns an iterator (so self)
        rr%rrr�
xreadlines�sz_FileEntry.xreadlinescCs|Sr3rr%rrr�__iter__�sz_FileEntry.__iter__cCs|S�Nrr%rrr�	__enter__�sz_FileEntry.__enter__cCs|��dSr6)r()r�exc_type�	exc_value�	tracebackrrr�__exit__�sz_FileEntry.__exit__N)rrrrr$r&r(r.r0�nextr2r4r5r7r;rrrrrFs	rc@s*eZdZdZdd�Zdd�Zd	dd�ZdS)
rzJ
    File-like object used to read an uncompressed entry in a ZipFile
    cCst�|||�d|_dS)Nr)rr$�	readBytesr#rrrr$�szZipFileEntry.__init__cCs|jSr6)r=r%rrr�tell�szZipFileEntry.tellNcCsv|dkr|j|j}|dks"|jr&dS|jj�t||j|j��}|jt|�7_|j|jkslt|�|krrd|_|S)Nrr)r')r r=r!rr	r�min�len)r�n�datarrrr�s�zZipFileEntry.read)N�rrrrr$r>rrrrrr�src@s*eZdZdZdd�Zdd�Zd	dd�ZdS)
rzE
    File-like object used to read a deflated entry in a ZipFile
    cCs0t�|||�d|_d|_t�d�|_d|_dS)Nri�r))rr$�
returnedBytesr=�zlibZ
decompressobj�decomp�bufferr#rrrr$�s
zDeflatedZipFileEntry.__init__cCs|jSr6)rDr%rrrr>�szDeflatedZipFileEntry.tellNcCs`|jr
dS|dkr�|jg}|�|j�|jj�|j|j	���|�|j�d��|�|j�
��d|_d|_d�|�}|jt
|�7_|St
|j�|k�r(|jj�t|d|j|j	��}|j	t
|�7_	|�s|j|j�d�|j�
�}d|_d|_|jt
|�7_|S|j|j�|�7_q�|jd|�}|j|d�|_|jt
|�7_|SdS)Nr)�Zr'i)r!rG�appendrF�
decompressrr	rr r=�flush�joinrDr@r?)rrA�resultrBrrrr�sL
���
�
��zDeflatedZipFileEntry.read)NrCrrrrr�sr�cCs,d}t|�}|��D]}|t||�7}q|S)zr
    Predict the number of chunks that will be extracted from the entire
    zipfile, given chunksize blocks.
    r)r�infolist�countFileChunks)�filename�	chunksizeZtotalchunksZzf�inforrr�countZipFileChunkss
rTcCs(t|j|�\}}|dkr |d7}|p&dS)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}
    rr')�divmod�	file_size)ZzipinforR�countZextrarrrrPsrP�.�c
csPt|d�}tj�|�s t�|�t||�}|��}|��}t||�D�]\}}	|	j	t
@}
tj�||�}|
r�tj�|�s�t�|�|d8}|VqDtj�|�d}tj�|�s�t�|�|s�tj�|��s6|�
|�}
|	jdkr�|d8}|Vt|d��:}|
��|	jk�r*|
�|�}|�|�|d8}|Vq�W5QRXqD|t|	|�8}|VqDdS)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.
    rr'r�wbN)r�os�path�exists�makedirsrTZnamelistrO�zipZ
external_attr�DIR_BITrL�splitrrV�openr>r�writerP)rQZ	directoryZ	overwriterRZczfZ	remaining�namesZinfos�entryrS�isdir�fZfdirr	ZoutfileZhunkrrr�unzipIterChunky$s<	









rh)rXrrY)rr�os.pathr[rErZcalcsizerr
ZZipFiler�objectrrrr`rTrPrhrrrr�<module>s4j7�