CasperSecurity

Current Path : /lib/python3/dist-packages/twisted/python/test/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/twisted/python/test/__pycache__/test_zipstream.cpython-310.pyc

o

�b//�@s�dZddlZddlZddlZddlmZddlmZmZddl	m
Z
Gdd�d�ZGdd	�d	ee
j�Z
Gd
d�dee
j�ZGdd
�d
e
j�ZdS)z'
Tests for L{twisted.python.zipstream}
�N)�md5)�filepath�	zipstream)�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
    cCsZ|��}t�|d|j��}|�d|�Wd�n1swYt�|d�}|�d�S)z6
        Return an appropriate zip file entry
        �w�contentN�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.getFileEntrycCs>|�d��}|�|���Wd�dS1swYdS)zK
        zip files should not be ttys, so isatty() should be false
        �N)r�assertFalse�isatty�r�	fileEntryrrr�test_isatty s"�zFileEntryMixin.test_isattycCsF|�d��}|�|j�Wd�n1swY|�|j�dS)zd
        The C{closed} attribute should reflect whether C{close()} has been
        called.
        rN)rr�closed�
assertTruerrrr�test_closed's�zFileEntryMixin.test_closedcCs`|�d��!}|�|��d�|�|��d�|�|��d�Wd�dS1s)wYdS)zk
        C{readline()} should mirror L{file.readline} and return up to a single
        delimiter.
        shoho
hoshoho
�ho�N)r�assertEqual�readlinerrrr�
test_readline0s
"�zFileEntryMixin.test_readlinecCs^|�d�� }|�|��d�|�|��d�|�t|j�Wd�dS1s(wYdS)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_nextcCsD|�d��}|�|��gd��Wd�dS1swYdS)zG
        C{readlines()} should return a list of all the lines.
        sho
ho
ho)r&r&r!N)rr#�	readlinesrrrr�test_readlinesCs"�zFileEntryMixin.test_readlinescCsP|�d��}|�t|�|�|�|��|�Wd�dS1s!wYdS)zJ
        C{__iter__()} and C{xreadlines()} should return C{self}.
        rN)r�assertIs�iter�
xreadlinesrrrr�test_iterationJs"�zFileEntryMixin.test_iterationcCsDd}|�|��}|�|��|�Wd�dS1swYdS)z9
        C{.read()} should read the entire file.
        s
Hello, world!N)rr#�read�rr�entryrrr�test_readWholeRs"�zFileEntryMixin.test_readWholecCs^d}|�|��}|�d�}|�d�}Wd�n1swY|�|d�|�|d�dS)zD
        C{.read(num)} should read num bytes from the file.
        �
0123456789���Ns0123s456789)rr1r#)rrr3�one�tworrr�test_readPartialZs
�zFileEntryMixin.test_readPartialcCshd}|�|��#}|�d�|�|��d�|�d�|�|��d�Wd�dS1s-wYdS)zb
        C{.tell()} should return the number of bytes that have been read so
        far.
        �dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx�r6�N)rr1r#�tellr2rrr�	test_telles

"�zFileEntryMixin.test_tellN)�__name__�
__module__�__qualname__�__doc__rrr r%r*r,r0r4r:r?rrrrrs
	
	rc@�eZdZdZejZdS)�DeflatedZipFileEntryTestsz2
    DeflatedZipFileEntry should be file-like
    N)r@rArBrCr�ZIP_DEFLATEDr
rrrrrEr�
rEc@rD)�ZipFileEntryTestsz*
    ZipFileEntry should be file-like
    N)r@rArBrCr�
ZIP_STOREDr
rrrrrHzrGrHc@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
        �unzippedN)r�FilePathr
�testdir�makedirs�child�unzipdir�rrrr�setUp�s
zZipstreamTests.setUprcCsv|j�d�j}t�|d��$}t|�D]\}}t|�}|r"|d|}|�||�qWd�|S1s4wY|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�/N)rMrO�pathrr�	enumerate�strr)rr�	directory�
zpfilename�zpfile�irrrrr�makeZipFile�s�
��zZipstreamTests.makeZipFilecCsFt�|��d��}|�t|jd�Wd�dS1swYdS)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�s"�zZipstreamTests.test_invalidModecCs0t�|�dg�d�}|��|�t|jd�dS)zn
        A closed ChunkingZipFile should raise a L{RuntimeError} when
        .readfile() is invoked.
        r\r	N)rrr[�closer(r]rr^rrr�test_closedArchive�sz!ZipstreamTests.test_closedArchivec	Cs|�ddg�}t�|d��}|�d�j}Wd�n1swYt|d��}|�|d�|�d�Wd�n1s>wYt�	|��7}|�
tj|jd�|�d	��}|�
|��d
�Wd�n1sjwYWd�dSWd�dS1s�wYdS)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	�0N�r+brs0000�1�
more contents)r[rr�getinfo�
header_offset�open�seek�writerrr(�
BadZipfilerr#r1)r�fn�zf�
zeroOffset�scribbler_�zferrr�test_invalidHeader�s ����"�z!ZipstreamTests.test_invalidHeaderc	Cs|�ddg�}t�|d��}|�d�}d|_Wd�n1s wYt|d��}|�|jd�|�|�	��Wd�n1sCwYt
�|��7}|�tj
|jd�|�d	��}|�|��d�Wd�n1sowYWd�dSWd�dS1s�wYdS)
z�
        A zipfile entry with a different filename than is found in the central
        directory should raise BadZipfile.
        s
test contentsrfr	rcznot zeroNrdrre)r[rrrgrrirjrhrk�
FileHeaderrrr(rlrr#r1)rrmrn�inforpr_rqrrr�test_filenameMismatch�s"
����"�z$ZipstreamTests.test_filenameMismatchcCs�|��}t�|d��}t�d�}|�|d�d|_Wd�n1s#wYt�|��}|�tj	|j
d�Wd�dS1sBwYdS)zq
        A zipfile which describes an unsupported compression mechanism should
        raise BadZipfile.
        rrcz	some datai�N)r
rr�ZipInfor�
compress_typerrr(rlr)rrmrn�zir_rrr�test_unsupportedCompression�s
�"�z*ZipstreamTests.test_unsupportedCompressionc	Cs�|��}t�|d��!}t�d�}d}t�ddt|��||_|�|d�Wd�n1s.wYt	�
|��.}|�d��}|�|�
�d�Wd�n1sQwYWd�dSWd�dS1siwYdS)zW
        readfile() should skip over 'extra' data present in the zip metadata.
        rrcshello, extraz<hh�*s
the real dataN)r
rrrv�struct�pack�len�extrarrrrr#r1)rrmrnrx�
extra_datar_rqrrr�test_extraData�s
�P�zZipstreamTests.test_extraDatacCs�d}dd�t|�D�}dd�|D�}|�|�}tt�||jj��|�t|j�	��tt
tt|����|j��D]}t
|���}|�|��||�q8dS)z�
        L{twisted.python.zipstream.unzipIterChunky} returns an iterator which
        must be exhausted to completely unzip the input archive.
        �
cS�g|]}d|�qS�zThis is test file %d!r��.0rZrrr�
<listcomp>��z7ZipstreamTests.test_unzipIterChunky.<locals>.<listcomp>cS�g|]}|�d��qS��ascii��encoder�rrrr���N)�ranger[�listr�unzipIterChunkyrPrTr#�set�listdir�maprV�children�int�basename�
getContent)r�numfilesrrXrO�numrrr�test_unzipIterChunky�s
$�z#ZipstreamTests.test_unzipIterChunkycCs�d}dd�t|�D�}dd�|D�}|�|d�}tt�||jj��dd�t|�D�}|�t|j�	d��
��|�|j�	d���D]}t|�
��}|�|��||�qAd	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.
        r�cSr�r�rr�rrrr�r�z@ZipstreamTests.test_unzipIterChunkyDirectory.<locals>.<listcomp>cSr�r�r�r�rrrr�	r��foocSsh|]	}t|��d��qSr�)rVr�)r�r�rrr�	<setcomp>sz?ZipstreamTests.test_unzipIterChunkyDirectory.<locals>.<setcomp>sfooN)r�r[r�rr�rPrTr#r�rOr�r�r�r�r�)rr�rrX�fileContentsrOr�rrr�test_unzipIterChunkyDirectorys�z,ZipstreamTests.test_unzipIterChunkyDirectorycCsd}td�D]}tt��d�}t|��d�}|d|7}qt|���}	t�|�	��}
|
�
�|
�d�j}|�
|||�tj||
j|d�}t|�}
||
koQ|kn}|�|�|D]}
q[|�|
d�|
�d	����}t|�����}|�||	�Wd
�d
S1s�wYd
S)zW
        unzipIterChunky should unzip the given number of bytes per iteration.
        r"i��r�� zbigfile.zip)�	chunksizer�
zipstreamjunkN)r��round�randomrVr�r�	hexdigestrrLr
rNrOrT�_makebigfilerr�r'rr#rir1)rr
r��lower�upper�junk�nr��
numEncoded�junkmd5�tempdir�zfpath�uziterr	�approx�f�newmd5rrr�_unzipIterChunkyTests*
"�z#ZipstreamTests._unzipIterChunkyTestcC�|�tjddd�dS)zs
        unzipIterChunky should unzip the given number of bytes per iteration on
        a stored archive.
        i��#�-N)r�rrIrQrrr�test_unzipIterChunkyStored5�z)ZipstreamTests.test_unzipIterChunkyStoredcCr�)zu
        unzipIterChunky should unzip the given number of bytes per iteration on
        a deflated archive.
        i���N)r�rrFrQrrr�test_chunkyDeflated<r�z"ZipstreamTests.test_chunkyDeflatedcCsbt�|d|�� }td�D]}d|}|�|d�q|�d|�Wd�dS1s*wYdS)zT
        Create a zip file with the given file name and compression scheme.
        rr�zzipstream%drr�N)rrr�r)rrr
r�rnrZrmrrrr�Cs"�zZipstreamTests._makebigfileN)r)r@rArBrCrRr[r`rbrrruryr�r�r�r�r�r�r�rrrrrJ�s 

	
rJ)rCr�r{r�hashlibr�twisted.pythonrr�
twisted.trialrr�TestCaserErHrJrrrr�<module>sa
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY