%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/python/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/python/__pycache__/zipstream.cpython-312.pyc

�

Ϫ�f�%���dZddlZddlZddlZddlZGd�dej�ZGd�d�ZGd�de�Z	Gd	�d
e�Z
dZd�Zd
�Z
dd�Zy)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��eZdZdZd�Zy)�ChunkingZipFilez~
    A L{zipfile.ZipFile} object which, with L{readfile}, also gives you access
    to a file-like object for each entry.
    c�x�|jdvrtd��|jstd��|j|�}|jj	|j
d�|jj
tj�}|ddtjk7rtjd��tjtj|�}|jj
|tj�}|tjr,|jj
|tj�|j dzr|j#d�}n|j#d	�}||j$k7r&tjd
|j$�d|�d���|j&tj(k(rt+||j,�S|j&tj.k(rt1||j,�Stjd
|j&|fz��)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�cp437zFile 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�readfilezChunkingZipFile.readfiles����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)rrs���
*r+rc�P�eZdZdZd�Zd�Zd�Zd�Zd�ZeZ	d�Z
d�Zd	�Zd
�Z
d�Zy)
�
_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�||_|jj|_||_d|_d|_y)zC
        Create a L{_FileEntry} from a L{ChunkingZipFile}.
        rFN)�chunkingZipFiler�length�finished�closed�r#r4r5s   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.isattyes��r+c�$�d|_d|_|`y)z/
        Close self (file-like object)
        T�N)r7r6rr;s r)�closez_FileEntry.closeks�������
��Gr+c�N��d}t�fd�d�D]}||z
}|dk(s�|S|S)z
        Read a line.
        r+c�&���jd�S)Nr>)rr;s�r)�<lambda>z%_FileEntry.readline.<locals>.<lambda>xs������1��r+�
)�iter)r#�line�bytes`  r)�readlinez_FileEntry.readliness@������-�s�3�	�D��D�L�D��u�}����		��r+c�>�|j�}|r|St��)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)
        r0r;s r)�
xreadlinesz_FileEntry.xreadlines��	���r+c��|SrPr0r;s r)�__iter__z_FileEntry.__iter__�rRr+c��|S�Nr0r;s r)�	__enter__z_FileEntry.__enter__�s���r+c�$�|j�yrV)r?)r#�exc_type�	exc_value�	tracebacks    r)�__exit__z_FileEntry.__exit__�s���
�
�r+N)r,r-r.r/r9r<r?rGrK�nextrNrQrTrWr\r0r+r)r2r2Cs@���.���	���D�����r+r2c�$�eZdZdZd�Zd�Zdd�Zy)rzJ
    File-like object used to read an uncompressed entry in a ZipFile
    c�@�tj|||�d|_y)Nr)r2r9�	readBytesr8s   r)r9zZipFileEntry.__init__�s�����D�/�6�:���r+c��|jSrV)r`r;s r)�tellzZipFileEntry.tell�s���~�~�r+Nc��|�|j|jz
}|dk(s|jry|jjjt
||j|jz
��}|xjt|�z
c_|j|jk(st|�|krd|_|S)Nrr+r>)r5r`r6r4rr�min�len)r#�n�datas   r)rzZipFileEntry.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/r9rbrr0r+r)rr�s�����	r+rc�$�eZdZdZd�Zd�Zdd�Zy)r"zE
    File-like object used to read a deflated entry in a ZipFile
    c��tj|||�d|_d|_t	j
d�|_d|_y)Nri�r+)r2r9�
returnedBytesr`�zlib�
decompressobj�decomp�bufferr8s   r)r9zDeflatedZipFileEntry.__init__�s<�����D�/�6�:��������(�(��-�����r+c��|jSrV)rkr;s r)rbzDeflatedZipFileEntry.tell�s���!�!�!r+Nc� �|jry|��|jg}|j|jj	|j
jj|j|jz
���|j|jj	d��|j|jj��d|_d|_dj|�}|xjt|�z
c_|St|j�|k�r |j
jjt|d|j|jz
��}|xjt|�z
c_	|sq|j|jj	d�z|jj�z}d|_d|_|xjt|�z
c_|S|xj|jj	|�z
c_t|j�|kr�� |jd|}|j|d|_|xjt|�z
c_|S)Nr+�Zr>i)r6ro�appendrn�
decompressr4rrr5r`�flush�joinrkrerd)r#rf�resultrgs    r)rzDeflatedZipFileEntry.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+rVrhr0r+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|�\}}|dkDr|dz
}|xsdS)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)�zipinfor}�count�extras    r)r{r{s4���'�+�+�Y�7�L�E�5��q�y�
��
���:�A�r+c#�pK�t|d�}tjj|�stj|�t||�}|j
�}|j�}t||�D�]�\}}	|	jtz}
tjj||�}|
r>tjj|�stj|�|dz}|���ztjj|�d}tjj|�stj|�|stjj|�s�|j|�}
|	jdk(r	|dz}|��t|d�5}|
j!�|	jkrI|
j#|�}|j%|�|dz}|��|
j!�|	jkr�Iddd����|t'|	|�z}|�����y#1swY���xYw�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.
    rr>r�wbN)r�os�path�exists�makedirsr��namelistrz�zip�
external_attr�DIR_BITrv�splitr*r��openrbr�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�FH6�!A&H)�!H6�)H3	�.H6)�.ri)r/�os.pathr�rrrl�ZipFilerr2rr"r�r�r{r�r0r+r)�<module>r�se��
�
�
���0�g�o�o�0�f^�^�B�:��05�:�5�p
��	��"+ r+

Zerion Mini Shell 1.0