HEX
Server: Apache
System: Linux opal14.opalstack.com 3.10.0-1160.108.1.el7.x86_64 #1 SMP Thu Jan 25 16:17:31 UTC 2024 x86_64
User: curbgloabal_opal (1234)
PHP: 8.1.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib64/python3.6/test/__pycache__/test_mmap.cpython-36.pyc
3


 \o�@s�ddlmZmZmZmZmZmZmZmZm	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZed�ZejZGdd�de
j�ZGdd�de
j�Zdd	�Zed
kr�e�dS)�)	�TESTFN�run_unittest�
import_module�unlink�requires�_2G�_4G�
gc_collect�cpython_onlyN�mmapc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zej
eed�d�dd��Zej
eed�d�dd��Zej
eed�d�dd��Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zej
eed/�d0�d1d2��Zd3d4�Zd5d6�Z d7d8�Z!ej
ej"d9kd:�d;d<��Z#e$ej
ej"d9kd:�d=d>���Z%ej
ej"d9kd:�d?d@��Z&ej
ej"d9kd:�dAdB��Z'dCdD�Z(dEdF�Z)dGdH�Z*dIdJ�Z+ej,ej"d9kdK�dLdM��Z-dNdO�Z.dPS)Q�	MmapTestscCstjjt�rtjt�dS)N)�os�path�existsrr)�self�r�!/usr/lib64/python3.6/test_mmap.py�setUpszMmapTests.setUpcCs(ytjt�Wntk
r"YnXdS)N)r
rr�OSError)rrrr�tearDownszMmapTests.tearDowncCs�ttd�}zJ|jdt�|jd�|jdtd�|j�tj|j�dt�}Wd|j�Xtt	|��}|j
|jd�t�|j
t|�dt�|j
|dd�|j
|dd�d�|j
t|jt|��|j
t|jt|�d�d|d<d	|tdtdd�<|j
|dd�|j
|dd�d
�|j
|tdtd�d
�|j�tjd|�}|dk�rj|jd�n2|jd�\}}||}|j
|t�|j
|td�|jdd�|j
|j�d�|jdd�|j
|j�d�|jdd�|j
|j�t|��|j
t|jd�|j
t|jdd�|j
t|jt|�dd�y|jd�Wntk
�rVYnjX|j
t|�d�|j
t|jdd�ttd�}z |jdd�|j
|j�d�Wd|j�X|j
|j�d�|j�dS)Nzbw+�sfoo��rs�3sbars3��sfoobars	[A-Za-z]+zregex match on mmap failed!��*ii�rb�3r���)�openr�write�PAGESIZE�flushr�fileno�close�str�type�assertEqual�find�len�assertRaises�
IndexError�__getitem__�__setitem__�re�search�fail�span�seek�tell�
ValueError�resize�SystemError�size)r�f�m�tp�match�start�endZlengthrrr�
test_basicsd





zMmapTests.test_basicc�Cs�d}ttd��}|jd|�WdQRXttd����}tj|j�|tjd�}|j|dd�d|d�yd||dd�<Wntk
r�YnX|jd�yd|d	<Wntk
r�YnX|jd�y|j	d	d	�|jd
�Wntk
r�YnX|jd�y|j	d	d	�|j
d�Wntk
�r0YnX|jd�y|jd|�Wn*tk
�rdYn tk
�rxYnX|jd
�ttd��}|j|j
�d|d�WdQRXWdQRXttd���}ytj|j�|d�}Wn.tk
�rtjjd��r|jd�Yn"Xtjjd��s&|jd�|j�tjjd��r\ttd��}|j|�WdQRXWdQRXttd��V}tj|j�|tjd�}d||dd�<|j|dd�d|d�|j�|j�WdQRXttd��}|j
�}WdQRX|j|d|d�ttd���}tj|j�|tjd�}d||dd�<|j|dd�d|d�|j�ttd��}|j|j
�d|d�WdQRX|jt|jd|�|j�WdQRXttd�� }|jttj|j�|dd�WdQRXtjdk�r|ttd��*}|jttj|j�|tjtjtjd�WdQRXtjttdd	�B}ttd��B}tj|j�||d�}|jt|jd�|jt|j
d	�|j�WdQRXdS)N�
�wb�ar)�accessz#Readonly memory map data incorrect.�bz$Able to write to readonly memory maprsabc�drz"Able to resize readonly memory mapz*Readonly memory map data file was modifiedzr+br�winz0Opening mmap with size+1 should work on Windows.z1Opening mmap with size+1 should raise ValueError.�cz5Write-through memory map memory not updated properly.z8Write-through memory map data file not updated properly.z4Copy-on-write memory map data not written correctly.z4Copy-on-write test data file should not be modified.��posix)�flags�protrDZ	PROT_EXEC)rLsabcdef)r!rr"rr%�ACCESS_READr)�	TypeErrorr2r4�
write_byter7r8�readr6�sys�platform�
startswithr&�truncateZACCESS_WRITEr$ZACCESS_COPYr,r
�nameZMAP_PRIVATE�	PROT_READ�getattr)r�mapsize�fpr:r;ZstuffrLrrr�test_access_parameterzs�





$zMmapTests.test_access_parametercCs|jttjdd�dS)Nri���)r,rr)rrrr�test_bad_file_desc�szMmapTests.test_bad_file_descc
Cs�ttd��4}d}t|�}|j|�|j�tj|j�|�}WdQRXxft|d�D]V}xPt||d�D]>}|||�}|j|j	|�|j	|��|j|j	|d�d�qfWqRW|j
�dS)Nzwb+saabaacdeefaar�xr )r!rr+r"r$rr%�ranger)r*r&)rr:�data�nr;r>Zfinish�slicerrr�test_tougher_find�s
zMmapTests.test_tougher_findcCs�ttd�}d}t|�}|j|�|j�tj|j�|�}|j�|j|j	d�d�|j|j	d�d�|j|j	ddd	�d�|j|j	dd�d�|j|j	ddd
�d�|j|j	ddd�d�|j|j	t
d��d�dS)
Nzwb+sone two onessonersones�rrr r r[r )r!rr+r"r$rr%r&r)r*�	bytearray)rr:r_r`r;rrr�
test_find_end
s

zMmapTests.test_find_endcCs�ttd�}d}t|�}|j|�|j�tj|j�|�}|j�|j|j	d�d�|j|j	d�d�|j|j	ddd	�d�|j|j	ddd
�d�|j|j	ddd�d�|j|j	ddd�d
�|j|j	t
d��d�dS)Nzwb+sone two onessonercsone rrrr r[r r[r )r!rr+r"r$rr%r&r)�rfindrd)rr:r_r`r;rrr�
test_rfind s

zMmapTests.test_rfindcCs\ttd�}|jdd�|j�ttd�}tj|j�dtjd�}|j�|j�|j�dS)	Nzwb+r�rCr)rDii)r!rr"r&rr%rM)rr:�mfrrr�test_double_close3s

zMmapTests.test_double_close�statzneeds os.stat()cCsvttd�}|jdd�|j�ttd�}tj|j�d�}|jt|�d	d�|j|jd
�dd�|j�|j�dS)Nzwb+rrh�mzrb+rz Map size should equal file size.iiii)	r!rr"r&rr%r)r+rP)rr:rirrr�test_entire_file@s

zMmapTests.test_entire_filecCsrttd��}|jd	d�WdQRXttd��:}tj|j�ddtjd��}|jt|jd�WdQRXWdQRXdS)
NrBirrlrr)�offsetrDi�8i)	r!rr"rr%rMr,r-r.)rr:rirrr�test_length_0_offsetOs
zMmapTests.test_length_0_offsetcCsXttd��}|jdd�WdQRXttd�� }|jttj|j�ddd�WdQRXdS)NrBi��rlzw+bri�)rn)r!rr"r,r6rr%)rr:rrr�test_length_0_large_offset\s
z$MmapTests.test_length_0_large_offsetcCs2ttd�}|jd�|j�tj|j�d�}|jddd�|j|dd�dd�|j�|j�d}x�t	t
|��D]�}x�t	t
|��D]�}x�t	t
|�t||��D]v}|d|�||||�|||d�}tjdt
|��}||dd�<|j|||�|j|dd�|�|j�q�Wq�WqrWtjd
d
�}dddd	d
g}	xHtj
|	|	|	�D]6\}
}}y|j|
||�Wntk
�r~YnX�qLWdddddd d"g}	x(|	D] \}
}}|jt|j|
||��q�W|j�tjd#d	�}|jt|jddd�|jt|jd	dd	�|jt|jdd	d	�|jddd	�|jddd�dS)$Nzwb+s
ABCDEabcderA�rs
ABCDEABCDEz'Map move should have duplicated front 5s
0123456789r�drr r i����r r r r )r r r r r )r r rr r )r rr r r )rr r r )r rrr )rr rr )rrr r )r!rr"r$rr%Zmover)r&r^r+�max�	itertools�productr6r,)rr:rir_�dest�src�countZexpectedr;Zoffsets�sourcer9rrr�	test_movegsH

,
zMmapTests.test_movecCsftjdt�}x"tt�D]}|j||dd�qWx0tt�D]$}|d@}|||<|j|||�q:WdS)Nrrz+anonymously mmap'ed contents should be zero�r )rr#r^r))rr;�x�brrr�test_anonymous�s
zMmapTests.test_anonymouscCs&tjdd�}|j|j�|jttd���|jd�|j|j�ttd���|jd�|j|j�ttdd���|jd�|j|j�d�|jd�|j|jd�ttdd���|jd�|j|jd
�ttdd���|jd�|j|jd�ttdd���|jd
�|j|jd�ttd
d���dS)Nrrhrrc�rrIrqr�	rr r r[i���)	r�
addCleanupr&r"�bytesr^r4r)rP)rr;rrr�
test_read_all�s"






zMmapTests.test_read_allcCsRtjdd�}|j|j�|jt|jd�|jt|jd�|jt|jdddg�dS)Nrrh�foog@rrr )rr�r&r,rNrP)rr;rrr�test_read_invalid_arg�s
zMmapTests.test_read_invalid_argc
Cs�tttd���}tjd	t|��}||dd�<|j|dd�|�d}xP|D]H}xB|D]:}x4|dd�D]$}|j||||�||||��qfWqTWqJWdS)N�rrr��,r�r r r[�������)
rNrrr�r�r r[r�r�)r��reversedr^rr+r))r�sr;�indicesr>�stop�steprrr�test_extended_getslice�s

z MmapTests.test_extended_getslicec	
Cs�tttd���}tjd	t|��}d}x�|D]�}x�|D]�}x�|dd�D]z}||dd�<|j|dd�|�t|�}||||�}tt|��}|||||�<|||||�<|j|dd�t|��qFWq4Wq*WdS)Nr�rrrr��,rr�r r r[�������)
rNrrr�r�r r[r�r�)r�r�r^rr+r)�list)	rr�r;r�r>r�r��Lr_rrr�test_extended_set_del_slice�s

z%MmapTests.test_extended_set_del_slicecCsB|jd|�|jd�|jd|d�|j�tj|j�d�S)Nrsfoorr)r"r$rr%)rr:�halfsizerrr�make_mmap_file�s

zMmapTests.make_mmap_filecCsJttd�}|j�ttd��$}|jtdtj|j�dtjd�WdQRXdS)Nzw+brzcannot mmap an empty filer)rD)r!rr&ZassertRaisesRegexr6rr%rM)rr:rrr�test_empty_file�s
zMmapTests.test_empty_filecCs�ttd�}�z�tj}|j||�}|j�|j�|d}ttd�}xXdD]P}y$tj|j�||d�}|jdd�Wntt	t
fk
r�YqHX|jdd�qHW|j�ttd�}tj|j�|||d�}|j|dd�d�|j�y|jd	�Wntk
�rYn~X|jt
|�d	�|jt|jd
d�|j|dd�d�ttd�}|jdd�|j|j�|d	�|j�|j|j�|d	�|j�Wd|j�ytjt�Wntk
�r�YnXXdS)Nzw+brzr+br)rnrrsfooiirr[r )r[r N)r!rrZALLOCATIONGRANULARITYr�r&r%r)r6rN�
OverflowErrorr7r8r+r,r4r5r9r
rr)rr:r�r;rXrnrrr�test_offset�sL




zMmapTests.test_offsetcCsGdd�dtj�}|t�dS)Nc@seZdZdd�ZdS)z*MmapTests.test_subclass.<locals>.anon_mmapc_stjj|df|�|�S)Nrr )r�__new__)�klass�args�kwargsrrrr�/sz2MmapTests.test_subclass.<locals>.anon_mmap.__new__N)�__name__�
__module__�__qualname__r�rrrr�	anon_mmap.sr�)rr#)rr�rrr�
test_subclass-szMmapTests.test_subclassrVzneeds mmap.PROT_READcCsdd}ttd��}|jd|�WdQRXttd�}tj|j�|tjd�}|jt|jd�|j�dS)NrArBrCr)rLr�)	r!rr"rr%rVr,rNr&)rrXrYr:r;rrr�test_prot_readonly3s
zMmapTests.test_prot_readonlycCs|jtjt�dS)N)�assertIsr�errorr)rrrr�
test_error=szMmapTests.test_errorcCs�d}ttd��}|jdt|��WdQRXttd�}tj|j�t|��}|j�xFtt|��D]6}|j|j	�|�|j
||�|j|j	�|d�q`W|jt|j
d�|j|dd�|�|j
d�xLtt|��D]<}|j|j	�|�|j|j�||�|j|j	�|d�q�W|jt|j�|j
d�|j|jd�d�|j|j	�d	�|j
d�|jd
�|j|j	�d	�|j|dd�d�|jtd��|j|j	�d
�|j|dd�d�|jt|jd�dS)Ns
0123456789rBr]zr+brrrs345rsbars
012bar6789sbazr�s
012barbaz9sba�x)r!rr"r+rr%r&r^r)r5rOr,r6r4�	read_byterPrd)rr_rYr:r;�irrr�test_io_methods@s:




zMmapTests.test_io_methodscCsZxTdD]L}tjdd�}|j|�|j|d|�|jd�|j|j�|�|j�qWdS)N���r{rr)r�r�r{r )rrOr)r4r�r&)rr}r;rrr�test_non_ascii_bytecs


zMmapTests.test_non_ascii_byte�ntzrequires WindowscCsd}d}t|�t|�kst�tjdt|�dd�}||dd�<tjdt|�dd�}||dd�<|j|dd�|�|j|dd�|�|j�|j�tjd	t|�dd�}||dd�<tjd
t|�dd�}||dd�<|j|dd�|�|j|dd�|�|j�|j�dS)Ns
0123456789s
abcdefghijrr�)�tagnameZboor r r r )r+�AssertionErrorrr)r&)rZdata1Zdata2�m1�m2rrr�test_tagnamels&zMmapTests.test_tagnamecCsHtjdd�}d}tjdd|d�}|jtj|�tj|�t|�d�dS)Nrrrr�)r�r r )rr)rQ�	getsizeofr+)rr�r�r�rrr�test_sizeof�s
zMmapTests.test_sizeofcCs�tjdddd�}ytjdddd�dd�WnYnX|j�ttd��}|jd
�WdQRXttd	�}tj|j�d
�}|j�y|jd
�WnYnXy|dd�WnYnX|j�dS)Nri�r�)r�i�rBr]rAzr+brr r s
xxxxxxxxxx)rr&r!rr"r%r7)rr;rYr:rrr�test_crasher_on_windows�s(
z!MmapTests.test_crasher_on_windowscCsBtj�}z*|jt��tj|j�d�}WdQRXWd|j�XdS)NrA)�socketr,rrr%r&)rr�r;rrr�test_invalid_descriptor�s
z!MmapTests.test_invalid_descriptorc	Cs4tjdd��}|j|j�WdQRX|j|j�dS)NrrAr )rZassertFalse�closed�
assertTrue)rr;rrr�test_context_manager�szMmapTests.test_context_managercCsT|jt��"}tjdd��
}t�WdQRXWdQRX|j|jtd�|j|jd�dS)NrrAz)wrong exception raised in context managerzcontext manager failedr )r,�	ExceptionrrZassertIsInstanceZ	exceptionr�r�)r�excr;rrr�test_context_manager_exception�s
z(MmapTests.test_context_manager_exceptioncCs>tjdd�}tj|�}|j|�|�~t�|j|�d�dS)Nrrhr )r�weakref�refr�r	)r�mm�wrrrr�test_weakref�s
zMmapTests.test_weakrefcCsXtjd
d�}|j|jd�d�|j|jd�d�|j|jd�d�|j|jd�d	�dS)Nrrhrrr]syzrspythonrr )rr)r")rr�rrr�0test_write_returning_the_number_of_bytes_written�s
z:MmapTests.test_write_returning_the_number_of_bytes_writtenz(cannot resize anonymous mmaps on WindowscCs�tjd
d�}|j|j�|jd�y|jd�Wntk
rN|jd�YnX|j|jd�d�|jt	|j
�|jt	|jd�|jt	|jd	�dS)Nri i�izresizing not supported�rrsabcr )
rr�r&rPr7r8ZskipTestr)r,r6r�rOr")rr;rrr�test_resize_past_pos�s
zMmapTests.test_resize_past_poscCsLtjdd�}|jt��||WdQRX|jt��|dWdQRXdS)Nrrhrr )rr,rN)rr;rrr�test_concat_repeat_exception�s
z&MmapTests.test_concat_repeat_exceptionN)/r�r�r�rrr@rZr\rbrergrj�unittest�
skipUnless�hasattrr
rmrorprzr~r�r�r�r�r�r�r�r�rr�r�r�r�rUr�r
r�r�r�r�r�r�r�ZskipIfr�r�rrrrrsJ^}

1	9
#			rc@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	j
eje
kd
�dd��Ze	j
eje
kd
�dd��ZdS)�LargeMmapTestscCstt�dS)N)rr)rrrrr�szLargeMmapTests.setUpcCstt�dS)N)rr)rrrrr�szLargeMmapTests.tearDowncCs�tjdd�dkstjdkr.tddtd��ttd�}y |j|�|j|�|j�WnJt	t
tfk
r�y|j�Wnt	t
fk
r�YnXt
jd��YnX|S)	NrrG�darwinZ	largefilez-test requires %s bytes and a long time to runlzw+bz*filesystem does not have largefile support)rQrRrr'r!rr4r"r$rr�r6r&r�ZSkipTest)rZ
num_zeroes�tailr:rrr�_make_test_file�s


zLargeMmapTests._make_test_filecCsP|jdd��:}tj|j�ddtjd��}|j|dd�WdQRXWdQRXdS)Nl��� rl)rnrDi���� )r�rr%rMr))rr:r;rrr�test_large_offsetsz LargeMmapTests.test_large_offsetcCs�|jdd���}tjdkrp|jt��tj|j�dtjd�WdQRX|jt��tj|j�dtjd�WdQRXtj|j�dtjd��}|j	|j
�d�WdQRXWdQRXdS)Nl��r�l)rDri)r�rQ�maxsizer,r�rr%rMr6r)r9)rr:r;rrr�test_large_filesizes
  z"LargeMmapTests.test_large_filesizecCsrd}|t|�d}|t|�}|j||��<}tj|j�dtjd��}|j|||�|�WdQRXWdQRXdS)Ns  DEARdear  rr)rD)r+r�rr%rMr))r�boundaryr�r>r?r:r;rrr�_test_around_boundarysz$LargeMmapTests._test_around_boundaryz!test cannot run on 32-bit systemscCs|jt�dS)N)r�r)rrrr�test_around_2GBszLargeMmapTests.test_around_2GBcCs|jt�dS)N)r�r)rrrr�test_around_4GB!szLargeMmapTests.test_around_4GBN)r�r�r�rrr�r�r�r�r�r�rQr�rr�r�rrrrr��sr�cCsttt�dS)N)rrr�rrrr�	test_main&sr��__main__)Ztest.supportrrrrrrrr	r
r�r
r0rtr�rQr�rr#ZTestCaserr�r�r�rrrr�<module>s&,^=