Uname: Linux web3.us.cloudlogin.co 5.10.226-xeon-hst #2 SMP Fri Sep 13 12:28:44 UTC 2024 x86_64
Software: Apache
PHP version: 8.1.31 [ PHP INFO ] PHP os: Linux
Server Ip: 162.210.96.117
Your Ip: 3.145.71.235
User: edustar (269686) | Group: tty (888)
Safe Mode: OFF
Disable Function:
NONE

name : test_mmap.cpython-310.pyc
o

ab{{�@s�ddlmZmZmZmZmZddlmZddlm	Z	m
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZed�ZejZGdd�dej�ZGdd	�d	ej�Zed
kr[e��dSdS)�)�requires�_2G�_4G�
gc_collect�cpython_only)�
import_module)�TESTFN�unlinkN�mmapc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Ze�eed-�d.�d/d0��Zd1d2�Zd3d4�Zd5d6�Z e�e!j"d7kd8�d9d:��Z#e$e�e!j"d7kd8�d;d<���Z%e�e!j"d7kd8�d=d>��Z&e�e!j"d7kd8�d?d@��Z'dAdB�Z(dCdD�Z)dEdF�Z*dGdH�Z+e�,e!j"d7kdI�dJdK��Z-dLdM�Z.dNdO�Z/dPdQ�Z0e�eejdR�dS�dTdU��Z1dVS)W�	MmapTestscCstj�t�r
t�t�dSdS�N)�os�path�existsrr	��self�r�7/usr/local/python-3.10/lib/python3.10/test/test_mmap.py�setUps�zMmapTests.setUpcCs&zt�t�WdStyYdSwr)r
r	r�OSErrorrrrr�tearDowns
�zMmapTests.tearDowncCs�ttd�}z)|�dt�|�d�|�dtd�|��t�|��dt�}W|��n|��wtt	|��}|�
|�d�t�|�
t|�dt�|�
|dd�|�
|dd�d�|�
t|jt|��|�
t|jt|�d�d|d<d	|tdtdd�<|�
|dd�|�
|dd�d
�|�
|tdtd�d
�|��t�d|�}|dur�|�d�n|�d�\}}||}|�
|t�|�
|td�|�dd�|�
|��d�|�dd�|�
|��d�|�dd�|�
|��t|��|�
t|jd�|�
t|jdd�|�
t|jt|�dd�z|�d�Wn
t�y-Yn9w|�
t|�d�|�
t|jdd�ttd�}z|�dd�|�
|��d�W|��n|��w|�
|��d�|��dS)Nzbw+��foo��rs�3�bars3��sfoobars	[A-Za-z]+zregex match on mmap failed!��*������rb)�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�end�lengthrrr�
test_basicsf

�
zMmapTests.test_basicc
Csrd}ttd��}|�d|�Wd�n1swYttd���}tj|��|tjd�}|�|dd�d|d�z
d||dd�<Wn	tyOYnw|�d�zd|d	<Wn	tydYnw|�d�z
|�	d	d	�|�d
�Wn	ty�Ynw|�d�z
|�	d	d	�|�
d�Wn	ty�Ynw|�d�z	|�d|�Wnty�Ynty�Ynw|�d
�ttd��}|�|�
�d|d�Wd�n1s�wYWd�n1s�wYttd��]}zt�|��|d�}Wnt�ytj�d��r|�d�Ynwtj�d��s&|�d�|��tj�d��rLttd��
}|�|�Wd�n	1�sGwYWd�n	1�sWwYttd��0}tj|��|tjd�}d||dd�<|�|dd�d|d�|��|��Wd�n	1�s�wYttd��}|�
�}Wd�n	1�s�wY|�|d|d�ttd��[}tj|��|tjd�}d||dd�<|�|dd�d|d�|��ttd��}|�|�
�d|d�Wd�n	1�swY|�t|jd|�|��Wd�n	1�s!wYttd��}|jttj|��|dd�Wd�n	1�sDwYtjdk�r�ttd��}|jttj|��|tjtjtjd�Wd�n	1�srwYtjttdd	�B}ttd��'}tj|��||d�}|�t|jd�|�t|j
d	�|��Wd�dS1�s�wYdSdS)N�
�wb�ar$��accessz#Readonly memory map data incorrect.�bz$Able to write to readonly memory mapr�abc�drz"Able to resize readonly memory mapz*Readonly memory map data file was modified�r+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�protrJZ	PROT_EXEC�rTsabcdef)r%rr&r
r)�ACCESS_READr-�	TypeErrorr6r8�
write_byter;r<�readr:�sys�platform�
startswithr*�truncate�ACCESS_WRITEr(�ACCESS_COPYr0r
�nameZMAP_PRIVATE�	PROT_READ�getattr)r�mapsize�fpr>r?�stuffrTrrr�test_access_parameter|s���
�
�
�
�
����4
��	
����
�
�����
����
$��zMmapTests.test_access_parametercCs|�ttjdd�dS)N����)r0rr
rrrr�test_bad_file_desc�szMmapTests.test_bad_file_desccCs�ttd��}d}t|�}|�|�|��t�|��|�}Wd�n1s'wYt|d�D])}t||d�D]}|||�}|�|�	|�|�	|��|�|�	|d�d�q;q2|�
�dS)N�wb+saabaacdeefaar�xr!)r%rr/r&r(r
r)�ranger-r.r*)rr>�data�nr?rBZfinish�slicerrr�test_tougher_find�s
��zMmapTests.test_tougher_findcCs�ttd��}d}t|�}|�|�|��t�|��|�}Wd�n1s'wY|�|�d�d�|�|�d�d�|�|�ddd�d�|�|�dd�d�|�|�ddd�d�|�|�ddd	�d�|�|�t	d��d�dS)
Nrj�one two ones�onersones�r!rrg)
r%rr/r&r(r
r)r-r.�	bytearray�rr>rmrnr?rrr�
test_find_ends
�zMmapTests.test_find_endcCs�ttd��}d}t|�}|�|�|��t�|��|�}Wd�n1s'wY|�|�d�d�|�|�d�d�|�|�ddd�d�|�|�ddd�d�|�|�dd	d�d�|�|�dd	d�d�|�|�t	d��d�dS)
Nrjrqrrrssone rr!rgr)
r%rr/r&r(r
r)r-�rfindrtrurrr�
test_rfind!s
�zMmapTests.test_rfindcCs�ttd��}|�dd�Wd�n1swYttd��}tj|��dtjd�}|��|��Wd�dS1s@wYdS)Nrj�rHr$rI)r%rr&r
r)rVr*�rr>�mfrrr�test_double_close3s�
"�zMmapTests.test_double_closec	Cs�ttd��}|�dd�Wd�n1swYttd��=}t�|��d��}|�t|�dd�|�|�d�dd�Wd�n1sIwYWd�dSWd�dS1sawYdS)Nrjry�mzrb+rz Map size should equal file size.)r%rr&r
r)r-r/rYrzrrr�test_entire_file=s��P�zMmapTests.test_entire_filec	Cs�ttd��}|�dd�Wd�n1swYttd��5}tj|��ddtjd��}|�t|jd�Wd�n1sAwYWd�dSWd�dS1sYwYdS)	NrGir}r$rry��offsetrJi�8)	r%rr&r
r)rVr0r1r2rzrrr�test_length_0_offsetGs���"�zMmapTests.test_length_0_offsetcCs�ttd��}|�dd�Wd�n1swYttd��}|jttj|��ddd�Wd�dS1s:wYdS)NrGi��r}�w+bri��r�)r%rr&r0r:r
r)�rr>rrr�test_length_0_large_offsetSs��"�z$MmapTests.test_length_0_large_offsetc	Csttd��/}|�d�|��t�|��d�}|�ddd�|�|dd�dd�|��Wd�n1s7wYd}t	t
|��D]R}t	t
|��D]I}t	t
|�t||��D];}|d|�||||�|||d�}t�d	t
|��}||dd�<|�|||�|�|dd�|�|��qYqLqDt�d	d
�}gd�}	t�
|	|	|	�D]\}
}}z	|�|
||�Wq�ty�Yq�wgd�}	|	D]\}
}}|�t|j|
||�q�|��t�d	d
�}|�t|jddd�|�t|jd
dd
�|�t|jdd
d
�|�ddd
�|�ddd�dS)Nrjs
ABCDEabcderF�rs
ABCDEABCDEz'Map move should have duplicated front 5�
0123456789r!�d)i����r!rrr�))r!r!r!)r!r!r)r!rr!)rr!r!)r!rr)rr!r)rrr!rr)r%rr&r(r
r)�mover-r*rlr/�max�	itertools�productr:r0)rr>r{rm�dest�src�countZexpectedr?�offsets�sourcer=rrr�	test_move]sL

�,
��
�zMmapTests.test_movecCs^t�dt�}tt�D]}|�||dd�q
tt�D]}|d@}|||<|�|||�qdS)Nr!rz+anonymously mmap'ed contents should be zero�)r
r'rlr-)rr?�x�brrr�test_anonymous�s��zMmapTests.test_anonymouscCs&t�dd�}|�|j�|�ttd���|�d�|�|��ttd���|�d�|�|��ttdd���|�d�|�|��d�|�d�|�|�d�ttdd���|�d�|�|�d�ttdd���|�d�|�|�d	�ttdd���|�d
�|�|�d�ttd
d���dS)Nr!�rrs�rrQr�rg�	i���)	r
�
addCleanupr*r&�bytesrlr8r-rY�rr?rrr�
test_read_all�s"






 zMmapTests.test_read_allcCsPt�dd�}|�|j�|�t|jd�|�t|jd�|�t|jgd��dS)Nr!r��foog@)rrr)r
r�r*r0rWrYr�rrr�test_read_invalid_arg�s
zMmapTests.test_read_invalid_argcCs�tttd���}t�dt|��}||dd�<|�|dd�|�ddddddtjddd	d
f}|D] }|D]}|dd�D]}|�||||�||||��q<q4q0dS�N�r!rrr�i,rgi��i���)r��reversedrlr
r/r-rZ�maxsize)r�sr?�indicesrB�stop�steprrr�test_extended_getslice�s����z MmapTests.test_extended_getslicec	Cs�tttd���}t�dt|��}ddddddtjddd	d
f}|D]K}|D]F}|dd�D]=}||dd�<|�|dd�|�t|�}||||�}tt|��}|||||�<|||||�<|�|dd�t|��q,q$q dSr�)	r�r�rlr
r/rZr�r-�list)	rr�r?r�rBr�r��Lrmrrr�test_extended_set_del_slice�s"���z%MmapTests.test_extended_set_del_slicecCsB|�d|�|�d�|�d|d�|��t�|��d�S)Nrrrr)r&r(r
r))rr>�halfsizerrr�make_mmap_file�s

zMmapTests.make_mmap_filec	Cs`ttd�}|��ttd��}|jtdtj|��dtjd�Wd�dS1s)wYdS)Nr�r$zcannot mmap an empty filerrI)r%rr*�assertRaisesRegexr:r
r)rVr�rrr�test_empty_file�s
�"�zMmapTests.test_empty_filecCs�ttd�}z�tj}|�||�}|��|��|d}ttd�}dD]'}ztj|��||d�}|�dd�Wntt	t
fyBYq"w|�dd�q"|��ttd�}tj|��|||d�}|�|dd�d	�|��z|�d
�Wn	ty}Yn?w|�t
|�d
�|�t|jdd�|�|dd�d	�ttd�}|�dd�|�|��|d
�|��|�|��|d
�|��W|��zt�t�WdSty�YdSw|��zt�t�Wwty�Yww)
Nr�rrN)rgr!Nr�rrrrr"r#r$)r%rr
�ALLOCATIONGRANULARITYr�r*r)r-r:rW�
OverflowErrorr;r<r/r0r8r9r=r
r	r)rr>r�r?rcr�rrr�test_offset�s^

�
�

���zMmapTests.test_offsetcCsGdd�dtj�}|t�dS)Nc@seZdZdd�ZdS)z*MmapTests.test_subclass.<locals>.anon_mmapc_stjj|dg|�Ri|��S)Nr!)r
�__new__)�klass�args�kwargsrrrr�$sz2MmapTests.test_subclass.<locals>.anon_mmap.__new__N)�__name__�
__module__�__qualname__r�rrrr�	anon_mmap#sr�)r
r')rr�rrr�
test_subclass"szMmapTests.test_subclassrazneeds mmap.PROT_READcCs�d}ttd��}|�d|�Wd�n1swYttd��}tj|��|tjd�}|�t|jd�Wd�dS1sBwYdS)NrFrGrHr$rUr�)r%rr&r
r)rar0rW)rrcrdr>r?rrr�test_prot_readonly(s�"�zMmapTests.test_prot_readonlycCs|�tjt�dSr)�assertIsr
�errorrrrrr�
test_error1szMmapTests.test_errorcCs�d}ttd��}|�dt|��Wd�n1swYttd��}t�|��t|��}Wd�n1s:wYtt|��D]}|�|��|�|�	||�|�|��|d�qE|�
t|j	d�|�|dd�|�|�d�tt|��D]}|�|��|�|�|�
�||�|�|��|d�q~|�
t|j
�|�d�|�|�d�d	�|�|��d
�|�d�|�d�|�|��d
�|�|dd�d�|�td
��|�|��d�|�|dd�d�|�
t|jd�dS)Nr�rGrkrNr�xrrs345rrs
012bar6789sbazr�s
012barbaz9sba)r%rr&r/r
r)rlr-r9rXr0r:r8�	read_byterYrt)rrmrdr>r?�irrr�test_io_methods4s<��



zMmapTests.test_io_methodscCsVdD]&}t�dd�}|�|�|�|d|�|�d�|�|��|�|��qdS)N)���r�r!rr)r
rXr-r8r�r*)rr�r?rrr�test_non_ascii_byteVs


�zMmapTests.test_non_ascii_byte�ntzrequires WindowscCsd}d}t|�t|�ksJ�tjdt|�dd�}||dd�<tjdt|�dd�}||dd�<|�|dd�|�|�|dd�|�|��|��tjdt|�dd�}||dd�<tjdt|�dd�}||dd�<|�|dd�|�|�|dd�|�|��|��dS)Nr�s
abcdefghijr!r���tagnameZboo)r/r
r-r*)rZdata1Zdata2�m1�m2rrr�test_tagname_s&zMmapTests.test_tagnamecCsHt�dd�}d}tjdd|d�}|�t�|�t�|�t|�d�dS)Nr!r�r�r�r)r
r-rZ�	getsizeofr/)rr�r�r�rrr�test_sizeofys�zMmapTests.test_sizeofcCs�tjdddd�}ztjdddd�dd�WnY|��ttd��
}|�d�Wd�n1s4wYttd�}t�|��d	�}|��z|�d	�WnYz|dd�WnY|��dS)
Nr!��r�r��rGs
xxxxxxxxxxrNr)r
r*r%rr&r)r;)rr?rdr>rrr�test_crasher_on_windows�s*�
z!MmapTests.test_crasher_on_windowscCsjt��}z+|�t��t�|��d�}Wd�n1swYW|��dSW|��dS|��w)NrF)�socketr0rr
r)r*)rr�r?rrr�test_invalid_descriptor�s��z!MmapTests.test_invalid_descriptorcCsHt�dd��}|�|j�Wd�n1swY|�|j�dS)Nr!rF)r
ZassertFalse�closed�
assertTruer�rrr�test_context_manager�s�zMmapTests.test_context_managerc	Csn|�t��}t�dd��}t�1swYWd�n1s!wY|�|jtd�|�|jd�dS)Nr!rFz)wrong exception raised in context managerzcontext manager failed)r0�	Exceptionr
rZassertIsInstance�	exceptionr�r�)r�excr?rrr�test_context_manager_exception�s��
�z(MmapTests.test_context_manager_exceptioncCs>t�dd�}t�|�}|�|�|�~t�|�|�d�dS)Nr!r�)r
�weakref�refr�r)r�mm�wrrrr�test_weakref�s
zMmapTests.test_weakrefcCsXt�dd�}|�|�d�d�|�|�d�d�|�|�d�d�|�|�d	�d
�dS)Nr!r�r�rrkrsyzr�pythonr)r
r-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 WindowscCs�t�dd�}|�|j�|�d�z|�d�Wnty&|�d�Ynw|�|�d�d�|�t	|j
�|�t	|jd�|�t	|jd	�dS)
Nr!i r�rhzresizing not supported�r�r rL)
r
r�r*rYr;r<ZskipTestr-r0r:r�rXr&r�rrr�test_resize_past_pos�s
�zMmapTests.test_resize_past_poscCsvt�dd�}|�t��||Wd�n1swY|�t��
|dWd�dS1s4wYdS)Nr!r�r)r
r0rWr�rrr�test_concat_repeat_exception�s
�
"�z&MmapTests.test_concat_repeat_exceptioncCs^t�dd�}|�|j�|�d�|��}|�|�tj�d�r-|�	t
|jdtd��dSdS)Nr!r�r��linuxr)r
r�r*r&r(ZassertIsNonerZr[r\r0rr/)rr��resultrrr�test_flush_return_value�s

�z!MmapTests.test_flush_return_valuecCs�t�d�}t�d�}d}tdd�|D��}t||�D]�\}}d|}||}d}	d|d	|d
|df}
ttd���}|�|�|��t�	|	|
�D]k\}}
t
t|�}tj|��|||d
��C}|�
|
�|�t|��}|�|�|�|�d�|�|�|�d�t|��|�|�d�t|
��|�|�d�t|��Wd�n1s�wY|�t|��}|�|�qIWd�n1s�wYqdS)Nzr<mmap.mmap closed=False, access=(?P<access>\S+), length=(?P<length>\d+), pos=(?P<pos>\d+), offset=(?P<offset>\d+)>z<mmap.mmap closed=True>)�2r�r�i@Bi���css$�|]
}|dtjtjVqdS)rN)r
r�)�.0rcrrr�	<genexpr>�s���z&MmapTests.test_repr.<locals>.<genexpr>rH)ZACCESS_DEFAULTrVr_r^rrFr�rQrj)rJr�rJrD�posr�)r4�compile�tuple�zipr%rr&r(r�r�rbr
r)r8rA�reprZassertIsNotNoner-�groupr+)rZopen_mmap_repr_patZclosed_mmap_repr_patZmapsizesr�r�rcrmrDZaccessesZ	positionsrdrJr�Zaccintr�rArrr�	test_repr�sL�
�


�

�����zMmapTests.test_repr�madvisez
needs madvisecCsxdt}t�d|�}|�td��|�tj|�Wd�n1s"wY|�td��|�tjd�Wd�n1s?wY|�td��|�tjdd�Wd�n1s]wY|�td��|�tjttj�Wd�n1s|wY|�	|�tj�d�|�	|�tjt�d�|�	|�tjt|�d�|�	|�tjdd�d�|�	|�tjd|�d�dS)Nrr!zmadvise start out of boundszmadvise length invalidrzmadvise length too large)
r'r
r�r:r�ZMADV_NORMALr�rZr�r-)rr=r?rrr�test_madvises&����zMmapTests.test_madviseN)2r�r�r�rrrErfrirprvrxr|r~r�r�r�r�r�r�r�r�r�r�r�r��unittest�
skipUnless�hasattrr
r�r�r�r�r
r`r�rr�r�r�r�r�r�r�ZskipIfr�r�r�r�r�rrrrrs`^}


0	9
"	


		


$rc@speZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	�
eje
kd
�dd��Ze	�
eje
kd
�dd��ZdS)�LargeMmapTestscC�tt�dSr�r	rrrrrr"�zLargeMmapTests.setUpcCr�rr�rrrrr%r�zLargeMmapTests.tearDowncCs�tjdd�dkstjdkrtddtd��ttd�}z|�|�|�|�|��W|St	t
tfyNz|��Wnt	t
fyHYnwt
�d��w)	NrrO�darwinZ	largefilez-test requires %s bytes and a long time to run�r�z*filesystem does not have largefile support)rZr[rr+r%rr8r&r(rr�r:r*r�ZSkipTest)rZ
num_zeroes�tailr>rrr�_make_test_file(s$
�



��
�zLargeMmapTests._make_test_filec	Cs�|�dd��5}tj|��ddtjd��}|�|dd�Wd�n1s&wYWd�dSWd�dS1s>wYdS)Nl��� rlri���� )r�r
r)rVr-�rr>r?rrr�test_large_offset9s��"�z LargeMmapTests.test_large_offsetc	Cs|�dd��y}tjdkrL|�t��tj|��dtjd�Wd�n1s'wY|�t��tj|��dtjd�Wd�n1sGwYtj|��dtjd��}|�	|�
�d�Wd�n1sjwYWd�dSWd�dS1s�wYdS)Nl��rr�rIrry)r�rZr�r0r�r
r)rVr:r-r=rrrr�test_large_filesize>s
����"�z"LargeMmapTests.test_large_filesizec	Cs�d}|t|�d}|t|�}|�||��6}tj|��dtjd��}|�|||�|�Wd�n1s7wYWd�dSWd�dS1sOwYdS)Ns  DEARdear  rrrI)r/r�r
r)rVr-)r�boundaryr�rBrCr>r?rrr�_test_around_boundaryLs��"�z$LargeMmapTests._test_around_boundaryz!test cannot run on 32-bit systemscC�|�t�dSr)rrrrrr�test_around_2GBT�zLargeMmapTests.test_around_2GBcCrr)rrrrrr�test_around_4GBXr	zLargeMmapTests.test_around_4GBN)r�r�r�rrr�rrrr�r�rZr�rrr
rrrrr� s
r��__main__)Ztest.supportrrrrrZtest.support.import_helperrZtest.support.os_helperrr	r�r
r4r�r�rZr�r
r'ZTestCaserr�r��mainrrrr�<module>s.=�
© 2025 GrazzMean