%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f//����dZddlZddlZddlZddlmZddlmZmZddl	m
Z
Gd�d�ZGd�d	ee
j�Z
Gd
�dee
j�ZGd�d
e
j�Zy)z'
Tests for L{twisted.python.zipstream}
�N)�md5)�filepath�	zipstream)�unittestc�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�FileEntryMixinz?
    File entry classes should behave as file-like objects
    c��|j�}tj|d|j�5}|j	d|�ddd�tj|d�}|jd�S#1swY�0xYw)z6
        Return an appropriate zip file entry
        �w�contentN�r)�mktemp�zipfile�ZipFile�compression�writestrr�ChunkingZipFile�readfile)�self�contents�filename�zs    �D/usr/lib/python3/dist-packages/twisted/python/test/test_zipstream.py�getFileEntryzFileEntryMixin.getFileEntrysk���;�;�=��
�_�_�X�s�D�,<�,<�
=�	,��
�J�J�y�(�+�	,��%�%�h��4���z�z�)�$�$�	,�	,�s�A4�4A=c��|jd�5}|j|j��ddd�y#1swYyxYw)zK
        zip files should not be ttys, so isatty() should be false
        �N)r�assertFalse�isatty�r�	fileEntrys  r�test_isattyzFileEntryMixin.test_isatty s@���
�
�r�
"�	1�i����Y�-�-�/�0�	1�	1�	1�s	� ;�Ac��|jd�5}|j|j�ddd�|jj�y#1swY�%xYw)zd
        The C{closed} attribute should reflect whether C{close()} has been
        called.
        rN)rr�closed�
assertTruers  r�test_closedzFileEntryMixin.test_closed'sO��
�
�
�r�
"�	/�i����Y�-�-�.�	/����	�(�(�)�	/�	/�s�A�Ac��|jd�5}|j|j�d�|j|j�d�|j|j�d�ddd�y#1swYyxYw)zk
        C{readline()} should mirror L{file.readline} and return up to a single
        delimiter.
        shoho
hoshoho
�ho�N)r�assertEqual�readliners  r�
test_readlinezFileEntryMixin.test_readline0st��
�
�
�{�
+�	8�y����Y�/�/�1�9�=����Y�/�/�1�5�9����Y�/�/�1�3�7�	8�	8�	8���A!A<�<Bc��|jd�5}|j|j�d�|j|j�d�|jt|j�ddd�y#1swYyxYw)zV
        Zip file entries should implement the iterator protocol as files do.
        sho
hoho�ho
shohoN)rr(�next�assertRaises�
StopIterationrs  r�	test_nextzFileEntryMixin.test_next:sk���
�
�{�
+�	=�y����Y�^�^�-�w�7����Y�^�^�-�w�7����m�Y�^�^�<�	=�	=�	=�r+c��|jd�5}|j|j�gd��ddd�y#1swYyxYw)zG
        C{readlines()} should return a list of all the lines.
        sho
ho
ho)r-r-r&N)rr(�	readlinesrs  r�test_readlineszFileEntryMixin.test_readlinesCsG���
�
�}�
-�	O�����Y�0�0�2�4M�N�	O�	O�	O�s	�#>�Ac���|jd�5}|jt|�|�|j|j�|�ddd�y#1swYyxYw)zJ
        C{__iter__()} and C{xreadlines()} should return C{self}.
        rN)r�assertIs�iter�
xreadlinesrs  r�test_iterationzFileEntryMixin.test_iterationJsR���
�
�r�
"�	=�i��M�M�$�y�/�9�5��M�M�)�.�.�0�)�<�	=�	=�	=�s�<A�A c��d}|j|�5}|j|j�|�ddd�y#1swYyxYw)z9
        C{.read()} should read the entire file.
        s
Hello, world!N)rr(�read�rr�entrys   r�test_readWholezFileEntryMixin.test_readWholeRsD��$��
�
�
�x�
(�	5�E����U�Z�Z�\�8�4�	5�	5�	5�s	�!>�Ac���d}|j|�5}|jd�}|jd�}ddd�|jd�|jd�y#1swY�.xYw)zD
        C{.read(num)} should read num bytes from the file.
        �
0123456789���Ns0123s456789)rr;r()rrr=�one�twos     r�test_readPartialzFileEntryMixin.test_readPartialZsj�� ��
�
�
�x�
(�	"�E��*�*�Q�-�C��*�*�S�/�C�	"�	
����g�&�����i�(�		"�	"�s�#A$�$A-c��d}|j|�5}|jd�|j|j�d�|jd�|j|j�d�ddd�y#1swYyxYw)zb
        C{.tell()} should return the number of bytes that have been read so
        far.
        �dxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx�rA�N)rr;r(�tellr<s   r�	test_tellzFileEntryMixin.test_tellesp��
��
�
�
�x�
(�	.�E��J�J�q�M����U�Z�Z�\�1�-��J�J�q�M����U�Z�Z�\�1�-�		.�	.�	.�s�A#B�B	N)�__name__�
__module__�__qualname__�__doc__rr r$r*r1r4r9r>rErK�r'rrrs:���%�1�*�8�=�O�=�5�	)�
.r'rc�(�eZdZdZej
Zy)�DeflatedZipFileEntryTestsz2
    DeflatedZipFileEntry should be file-like
    N)rLrMrNrOr�ZIP_DEFLATEDrrPr'rrRrRrs����&�&�Kr'rRc�(�eZdZdZej
Zy)�ZipFileEntryTestsz*
    ZipFileEntry should be file-like
    N)rLrMrNrOr�
ZIP_STOREDrrPr'rrUrUzs����$�$�Kr'rUc�f�eZdZdZd�Zdd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zy)�ZipstreamTestsz,
    Tests for twisted.python.zipstream
    c��tj|j��|_|jj	�|jjd�|_|jj	�y)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�rs r�setUpzZipstreamTests.setUp�sR��
 �(�(�����7������������*�*�:�6��
��
�
��� r'c��|jjd�j}tj|d�5}t|�D],\}}t
|�}|r|dz|z}|j||��.	ddd�|S#1swY|SxYw)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)r\r^�pathrr�	enumerate�strr)rr�	directory�
zpfilename�zpfile�irrs        r�makeZipFilezZipstreamTests.makeZipFile�s���
�\�\�'�'�
�6�;�;�
�
�_�_�Z��
-�	3��'��1�
3�
��7��q�6���(�3���9�H�����'�2�	
3�	3���
	3���s�;B�Bc��tj|j�d�5}|jt|j
d�ddd�y#1swYyxYw)z�
        A ChunkingZipFile opened in write-mode should not allow .readfile(),
        and raise a RuntimeError instead.
        r
�	somethingN)rrr
r/�RuntimeErrorr�r�czfs  r�test_invalidModezZipstreamTests.test_invalidMode�sK��
�
&�
&�t�{�{�}�c�
:�	G�c����l�C�L�L�+�F�	G�	G�	G�s�"A�Ac��tj|jdg�d�}|j�|j	t
|jd�y)zn
        A closed ChunkingZipFile should raise a L{RuntimeError} when
        .readfile() is invoked.
        rmrN)rrrk�closer/rnrros  r�test_closedArchivez!ZipstreamTests.test_closedArchive�sB��
�'�'��(8�(8�+��(G��M���	�	�����,����k�Br'c�t�|jddg�}tj|d�5}|jd�j}ddd�t|d�5}|j
d�|jd�ddd�tj|�5}|jtj|jd�|jd	�5}|j|j�d
�ddd�ddd�y#1swY��xYw#1swY��xYw#1swY�*xYw#1swYyxYw)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)rkrr�getinfo�
header_offset�open�seek�writerrr/�
BadZipFilerr(r;)r�fn�zf�
zeroOffset�scribblerp�zfes       r�test_invalidHeaderz!ZipstreamTests.test_invalidHeader�s��
�
�
���@�
A��
�_�_�R��
%�	7�����C��6�6�J�	7��"�e�_�	%���M�M�*�a�(��N�N�8�$�	%��
&�
&�r�
*�	?�c����g�0�0�#�,�,��D����c�"�
?�c�� � �����-=�>�
?�	?�	?�
	7�	7��	%�	%��

?�
?��	?�	?�s;�D
�$D�=D.�!D"�9D.�
D�D�"D+	�'D.�.D7c��|jddg�}tj|d�5}|jd�}d|_ddd�t|d�5}|j
jd�|j|j��ddd�tj|�5}|jtj|jd�|jd	�5}|j|j!�d�ddd�ddd�y#1swY��xYw#1swY��xYw#1swY�*xYw#1swYyxYw)
z�
        A zipfile entry with a different filename than is found in the central
        directory should raise BadZipFile.
        s
test contentsryrrvznot zeroNrwrrx)rkrrrzrr|r}r{r~�
FileHeaderrrr/rrr(r;)rr�r��infor�rpr�s       r�test_filenameMismatchz$ZipstreamTests.test_filenameMismatch�s��
�
�
�/�1A�B�
C��
�_�_�R��
%�	'���:�:�c�?�D�&�D�M�	'��"�e�_�	.���M�M�$�,�,�a�0��N�N�4�?�?�,�-�	.��
&�
&�r�
*�	?�c����g�0�0�#�,�,��D����c�"�
?�c�� � �����-=�>�
?�	?�	?�	'�	'��	.�	.��
?�
?��	?�	?�s;�D�<D+�0=E�-!D7�E�D(�+D4�7E	�<E�Ec��|j�}tj|d�5}tjd�}|j	|d�d|_ddd�t
j|�5}|jtj|jd�ddd�y#1swY�SxYw#1swYyxYw)zq
        A zipfile which describes an unsupported compression mechanism should
        raise BadZipFile.
        r
rvz	some datai�N)r
rr�ZipInfor�
compress_typerrr/rr)rr�r��zirps     r�test_unsupportedCompressionz*ZipstreamTests.test_unsupportedCompression�s���
�[�[�]��
�_�_�R��
%�	$������%�B��K�K��K�(� $�B��
	$��
&�
&�r�
*�	E�c����g�0�0�#�,�,��D�	E�	E�	$�	$��	E�	E�s�/B(�3,B4�(B1�4B=c��|j�}tj|d�5}tjd�}d}t	j
ddt
|��|z|_|j|d�ddd�tj|�5}|jd�5}|j|j�d�ddd�ddd�y#1swY�bxYw#1swY�xYw#1swYyxYw)zW
        readfile() should skip over 'extra' data present in the zip metadata.
        r
rvshello, extraz<hh�*s
the real dataN)r
rrr��struct�pack�len�extrarrrrr(r;)rr�r�r��
extra_datarpr�s       r�test_extraDatazZipstreamTests.test_extraData�s����[�[�]��
�_�_�R��
%�	.������%�B�(�J��{�{�5�"�c�*�o�>��K�B�H��K�K��,�-�		.�
�
&�
&�r�
*�	;�c�3�<�<��3D�	;�����S�X�X�Z�)9�:�	;�	;�	;�	.�	.��
	;�	;��	;�	;�s0�AC�C2�(!C&�	C2�C#�&C/	�+C2�2C;c�r�d}t|�D�cgc]}d|z��	}}|D�cgc]}|jd���}}|j|�}tt	j
||jj��|jt|jj��tttt|����|jj�D]>}t|j��}|j|j!�||��@ycc}wcc}w)z�
        L{twisted.python.zipstream.unzipIterChunky} returns an iterator which
        must be exhausted to completely unzip the input archive.
        �
�This is test file %d!�asciiN)�range�encoderk�listr�unzipIterChunkyr_rdr(�set�listdir�maprf�children�int�basename�
getContent)r�numfilesrjrrhr^�nums       r�test_unzipIterChunkyz#ZipstreamTests.test_unzipIterChunky�s���
��9>�x��I�A�+�a�/�I��I�/7�8�!�A�H�H�W�%�8��8��%�%�h�/�
��Y�
&�
&�z�4�=�=�3E�3E�
F�G�����T�]�]�2�2�4�5�s�3�s�E�(�O�;T�7U�V��]�]�+�+�-�	@�E��e�n�n�&�'�C����U�-�-�/��#��?�	@��
J��8s
�D/�D4c���d}t|�D�cgc]}d|z��	}}|D�cgc]}|jd���}}|j|d�}tt	j
||jj��t|�D�chc]}t|�jd���}}|jt|jjd�j��|�|jjd�j�D]>}t|j��}|j|j!�||��@ycc}wcc}wcc}w)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�r�r��foosfooN)r�r�rkr�rr�r_rdrfr(r�r^r�r�r�r�r�)rr�rjrrhr��fileContentsr^s        r�test_unzipIterChunkyDirectoryz,ZipstreamTests.test_unzipIterChunkyDirectorys*����9>�x��I�A�+�a�/�I��I�/7�8�!�A�H�H�W�%�8��8��%�%�h��6�
��Y�
&�
&�z�4�=�=�3E�3E�
F�G�<A�(�O�L�S��C�����0�L��L�����T�]�]�0�0��8�@�@�B�C�\�R��]�]�(�(��0�9�9�;�	@�E��e�n�n�&�'�C����U�-�-�/��#��?�	@��J��8��Ms�E�E#�!E(c�D�d}td�D]B}ttj�d�}t|�j	d�}|d|zz
}�Dt|�j
�}	tj|j��}
|
j�|
jd�j}|j|||�tj||
j|��}t!|�}
||
cxkxr|knc}|j#|�|D]}
�|j%|
d�|
jd	�j'�5}t|j)��j
�}|j%||	�d
d
d
�y
#1swYy
xYw)zW
        unzipIterChunky should unzip the given number of bytes per iteration.
        r'i��r�� zbigfile.zip)�	chunksizer�
zipstreamjunkN)r��round�randomrfr�r�	hexdigestrr[r
r]r^rd�_makebigfilerr�r.r#r(r|r;)rrr��lower�upper�junk�nr��
numEncoded�junkmd5�tempdir�zfpath�uziterr�approx�f�newmd5s                 r�_unzipIterChunkyTestz#ZipstreamTests._unzipIterChunkyTests_�����t��	&�A���
�
���,�C��S�����1�J��D�:�%�%�D�	&�
�d�)�%�%�'���#�#�D�K�K�M�2���������}�-�2�2�����&�+�t�4��*�*�6�7�<�<�9�U����L����"�U�"��������	�A��	�����A��
�]�]�?�
+�
0�
0�
2�	.�a������]�,�,�.�F����V�W�-�	.�	.�	.�s�:F�Fc�H�|jtjddd�y)zs
        unzipIterChunky should unzip the given number of bytes per iteration on
        a stored archive.
        i��#�-N)r�rrVr`s r�test_unzipIterChunkyStoredz)ZipstreamTests.test_unzipIterChunkyStored5s��
	
�!�!�'�"4�"4�c�2�r�Br'c�H�|jtjddd�y)zu
        unzipIterChunky should unzip the given number of bytes per iteration on
        a deflated archive.
        i���N)r�rrSr`s r�test_chunkyDeflatedz"ZipstreamTests.test_chunkyDeflated<s��
	
�!�!�'�"6�"6��R��Dr'c���tj|d|�5}td�D]}d|z}|j|d��|jd|�ddd�y#1swYyxYw)zT
        Create a zip file with the given file name and compression scheme.
        r
r�zzipstream%drr�N)rrr�r)rrrr�r�rjr�s       rr�zZipstreamTests._makebigfileCsf���_�_�X�s�K�
8�	/�B��2�Y�
$��"�Q�&�����B��#�
$�
�K�K���.�		/�	/�	/�s�:A�A$N)r)rLrMrNrOrarkrqrtr�r�r�r�r�r�r�r�r�r�rPr'rrXrX�sT���!��G�C�?�"?�$E�";�@� @�,.�<C�E�/r'rX)rOr�r�r�hashlibr�twisted.pythonrr�
twisted.trialrr�TestCaserRrUrXrPr'r�<module>r�sg����
���.�"�^.�^.�B'���0A�0A�'�%���(9�(9�%�I/�X�&�&�I/r'

Zerion Mini Shell 1.0