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: //lib/python3/dist-packages/twisted/python/test/__pycache__/test_zipstream.cpython-38.pyc
U

�`�[0�@s�dZddlZddlZddlZddlmZddlmZmZddl	m
Z
Gdd�de�ZGdd	�d	ee
j
�ZGd
d�dee
j
�ZGdd
�d
e
j
�ZdS)z'
Tests for L{twisted.python.zipstream}
�N)�md5)�	zipstream�filepath)�unittestc@s`eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�FileEntryMixinz?
    File entry classes should behave as file-like objects
    c	CsF|��}t�|d|j��}|�d|�W5QRXt�|d�}|�d�S)z6
        Return an appropriate zip file entry
        �w�content�r)�mktemp�zipfile�ZipFile�compression�writestrr�ChunkingZipFile�readfile)�self�contents�filename�z�r�D/usr/lib/python3/dist-packages/twisted/python/test/test_zipstream.py�getFileEntrys
zFileEntryMixin.getFileEntryc	Cs(|�d��}|�|���W5QRXdS)zK
        zip files should not be ttys, so isatty() should be false
        �N)r�assertFalse�isatty�rZ	fileEntryrrr�test_isatty szFileEntryMixin.test_isattyc	Cs2|�d��}|�|j�W5QRX|�|j�dS)zd
        The C{closed} attribute should reflect whether C{close()} has been
        called.
        rN)rr�closed�
assertTruerrrr�test_closed(szFileEntryMixin.test_closedc	CsJ|�d��6}|�|��d�|�|��d�|�|��d�W5QRXdS)zk
        C{readline()} should mirror L{file.readline} and return up to a single
        delimiter.
        shoho
hoshoho
�ho�N)r�assertEqual�readlinerrrr�
test_readline2szFileEntryMixin.test_readlinec	CsH|�d��4}|�|��d�|�|��d�|�t|j�W5QRXdS)zV
        Zip file entries should implement the iterator protocol as files do.
        sho
hoho�ho
shohoN)rr"�next�assertRaises�
StopIterationrrrr�	test_next=szFileEntryMixin.test_nextc	Cs0|�d��}|�|��dddg�W5QRXdS)zG
        C{readlines()} should return a list of all the lines.
        sho
ho
hor%r N)rr"�	readlinesrrrr�test_readlinesGszFileEntryMixin.test_readlinesc	Cs:|�d��&}|�t|�|�|�|��|�W5QRXdS)zJ
        C{__iter__()} and C{xreadlines()} should return C{self}.
        rN)rZassertIs�iterZ
xreadlinesrrrr�test_iterationOszFileEntryMixin.test_iterationc	Cs.d}|�|��}|�|��|�W5QRXdS)z9
        C{.read()} should read the entire file.
        s
Hello, world!N)rr"�read�rr�entryrrr�test_readWholeXszFileEntryMixin.test_readWholec	CsJd}|�|��}|�d�}|�d�}W5QRX|�|d�|�|d�dS)zD
        C{.read(num)} should read num bytes from the file.
        �
0123456789���s0123s456789N)rr.r")rrr0ZoneZtworrr�test_readPartialas
zFileEntryMixin.test_readPartialc	CsRd}|�|��:}|�d�|�|��d�|�d�|�|��d�W5QRXdS)zb
        C{.tell()} should return the number of bytes that have been read so
        far.
        Zdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx�r3�N)rr.r"�tellr/rrr�	test_tellms

zFileEntryMixin.test_tellN)�__name__�
__module__�__qualname__�__doc__rrrr$r)r+r-r1r5r9rrrrrs

		rc@seZdZdZejZdS)�DeflatedZipFileEntryTestsz2
    DeflatedZipFileEntry should be file-like
    N)r:r;r<r=r�ZIP_DEFLATEDr
rrrrr>{sr>c@seZdZdZejZdS)�ZipFileEntryTestsz(
   ZipFileEntry should be file-like
   N)r:r;r<r=r�
ZIP_STOREDr
rrrrr@�sr@c@s�eZdZdZdd�Zd dd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)!�ZipstreamTestsz,
    Tests for twisted.python.zipstream
    cCs6t�|���|_|j��|j�d�|_|j��dS)zz
        Creates junk data that can be compressed and a test directory for any
        files that will be created
        ZunzippedN)r�FilePathr
�testdir�makedirs�child�unzipdir�rrrr�setUp�s
zZipstreamTests.setUprc	Cs`|j�d�j}t�|d��<}t|�D],\}}t|�}|rD|d|}|�||�q$W5QRX|S)z�
        Makes a zip file archive containing len(contents) files.  Contents
        should be a list of strings, each string being the content of one file.
        zzipfile.zipr�/)rDrF�pathrr�	enumerate�strr)rrZ	directory�
zpfilenameZzpfile�irrrrr�makeZipFile�szZipstreamTests.makeZipFilec	Cs0t�|��d��}|�t|jd�W5QRXdS)z�
        A ChunkingZipFile opened in write-mode should not allow .readfile(),
        and raise a RuntimeError instead.
        r�	somethingN)rrr
r'�RuntimeErrorr�r�czfrrr�test_invalidMode�szZipstreamTests.test_invalidModecCs0t�|�dg�d�}|��|�t|jd�dS)zn
        A closed ChunkingZipFile should raise a L{RuntimeError} when
        .readfile() is invoked.
        rQr	N)rrrP�closer'rRrrSrrr�test_closedArchive�sz!ZipstreamTests.test_closedArchivec
Cs�|�ddg�}t�|d��}|�d�j}W5QRXt|d��}|�|d�|�d�W5QRXt�	|��>}|�
tj|jd�|�d��}|�
|��d	�W5QRXW5QRXd
S)z�
        A zipfile entry with the wrong magic number should raise BadZipfile for
        readfile(), but that should not affect other files in the archive.
        z
test contentsz
more contentsr	�0�r+brs0000�1�
more contentsN)rPrr�getinfo�
header_offset�open�seek�writerrr'�
BadZipfilerr"r.)r�fn�zfZ
zeroOffset�scribblerT�zferrr�test_invalidHeader�s�z!ZipstreamTests.test_invalidHeaderc
Cs�|�ddg�}t�|d��}|�d�}d|_W5QRXt|d��"}|�|jd�|�|�	��W5QRXt
�|��>}|�tj
|jd�|�d��}|�|��d�W5QRXW5QRXd	S)
z�
        A zipfile entry with a different filename than is found in the central
        directory should raise BadZipfile.
        s
test contentsr[r	rXznot zerorYrrZN)rPrrr\rr^r_r]r`Z
FileHeaderrrr'rarr"r.)rrbrc�infordrTrerrr�test_filenameMismatch�s�
z$ZipstreamTests.test_filenameMismatchc	Csh|��}t�|d��"}t�d�}|�|d�d|_W5QRXt�|��}|�tj	|j
d�W5QRXdS)zq
        A zipfile which describes an unsupported compression mechanism should
        raise BadZipfile.
        rrXz	some datai�N)r
rr�ZipInforZ
compress_typerrr'rar)rrbrc�zirTrrr�test_unsupportedCompression�s
z*ZipstreamTests.test_unsupportedCompressionc
Cs�|��}t�|d��8}t�d�}d}t�ddt|��||_|�|d�W5QRXt	�
|��,}|�d��}|�|�
�d�W5QRXW5QRXdS)zW
        readfile() should skip over 'extra' data present in the zip metadata.
        rrXshello, extraz<hh�*s
the real dataN)r
rrri�structZpack�lenZextrarrrrr"r.)rrbrcrjZ
extra_datarTrerrr�test_extraData�s
��zZipstreamTests.test_extraDatacCs�d}dd�t|�D�}dd�|D�}|�|�}tt�||jj��|�t|j�	��tt
tt|����|j��D]$}t
|���}|�|��||�qpdS)z�
        L{twisted.python.zipstream.unzipIterChunky} returns an iterator which
        must be exhausted to completely unzip the input archive.
        �
cSsg|]}d|�qS�zThis is test file %d!r��.0rOrrr�
<listcomp>sz7ZipstreamTests.test_unzipIterChunky.<locals>.<listcomp>cSsg|]}|�d��qS��ascii��encoderrrrrrt
sN)�rangerP�listr�unzipIterChunkyrGrKr"�set�listdir�maprM�children�int�basename�
getContent)r�numfilesrrNrF�numrrr�test_unzipIterChunkys
�z#ZipstreamTests.test_unzipIterChunkycCs�d}dd�t|�D�}dd�|D�}|�|d�}tt�||jj��dd�t|�D�}|�t|j�	d��
��|�|j�	d���D]$}t|�
��}|�|��||�q�d	S)
z�
        The path to which a file is extracted by L{zipstream.unzipIterChunky}
        is determined by joining the C{directory} argument to C{unzip} with the
        path within the archive of the file being extracted.
        rpcSsg|]}d|�qSrqrrrrrrrt sz@ZipstreamTests.test_unzipIterChunkyDirectory.<locals>.<listcomp>cSsg|]}|�d��qSrurwrrrrrrt!sZfoocSsh|]}t|��d��qSru)rMrx)rsr�rrr�	<setcomp>$sz?ZipstreamTests.test_unzipIterChunkyDirectory.<locals>.<setcomp>sfooN)ryrPrzrr{rGrKr"r|rFr}rr�r�r�)rr�rrNZfileContentsrFr�rrr�test_unzipIterChunkyDirectorys�z,ZipstreamTests.test_unzipIterChunkyDirectoryc	Csd}td�D],}tt��d�}t|��d�}|d|7}qt|���}	t�|�	��}
|
�
�|
�d�j}|�
|||�tj||
j|d�}t|�}
||
ko�|kn}|�|�|D]}
q�|�|
d�|
�d	����"}t|�����}|�||	�W5QRXd
S)zW
        unzipIterChunky should unzip the given number of bytes per iteration.
        r!i��rv� zbigfile.zip)�	chunksizer�
zipstreamjunkN)ry�round�randomrMrxrZ	hexdigestrrCr
rErFrK�_makebigfilerr{r&rr"r^r.)rr
r��lower�upper�junk�nr�Z
numEncodedZjunkmd5ZtempdirZzfpathZuziterr	Zapprox�fZnewmd5rrr�_unzipIterChunkyTest2s,
�
z#ZipstreamTests._unzipIterChunkyTestcCs|�tjddd�dS)zs
        unzipIterChunky should unzip the given number of bytes per iteration on
        a stored archive.
        i��#�-N)r�rrArHrrr�test_unzipIterChunkyStoredQsz)ZipstreamTests.test_unzipIterChunkyStoredcCs|�tjddd�dS)zu
        unzipIterChunky should unzip the given number of bytes per iteration on
        a deflated archive.
        i���N)r�rr?rHrrr�test_chunkyDeflatedYsz"ZipstreamTests.test_chunkyDeflatedc	CsLt�|d|��4}td�D]}d|}|�|d�q|�d|�W5QRXdS)zT
        Create a zip file with the given file name and compression scheme.
        rrpzzipstream%drr�N)rrryr)rrr
r�rcrOrbrrrr�as
zZipstreamTests._makebigfileN)r)r:r;r<r=rIrPrUrWrfrhrkror�r�r�r�r�r�rrrrrB�s
	
rB)r=r�rmrZhashlibrZtwisted.pythonrrZ
twisted.trialr�objectrZTestCaser>r@rBrrrr�<module>sj