HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //usr/local/lib/python3.7/test/__pycache__/test_dbm_dumb.cpython-37.opt-1.pyc
B

��g+�@s�dZddlZddlZddlZddlZddlZddlmZddl	m
Z
ddlmZe
j
Zdd�ZGdd�dej�Zed	kr�e��dS)
zATest script for the dumbdbm module
   Original by Roger E. Masse
�N)�support)�partialc	Cs:x4dD],}yt�t|�Wqtk
r0YqXqWdS)N)z.dirz.datz.bak)�os�unlink�_fname�OSError)Zext�r�./usr/local/lib/python3.7/test/test_dbm_dumb.py�
_delete_filess

r
c@sJeZdZddddddddd	d
ddd
dd�d�diZdd�Ze�ee	d�d�e�ee	d�d�dd���Z
dd�Zdd�Zdd�Z
d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Zd<d=�Zd>d?�Zd@dA�Ze�ee	d�d�dBdC��Ze�e j!dD�dEdF��Z"dGdH�Z#dIdJ�Z$dKS)L�DumbDBMTestCase�0��asPython:�bsProgramming�csthe�dsway�fsGuido�gsintended�üzutf-8�!cCsTt�td�}|�t|���g�x|jD]}|j|||<q(W|�|�|��dS)N�c)	�dumbdbm�openr�assertEqual�list�keys�_dict�read_helper�close)�self�f�keyrrr	�test_dumbdbm_creation"s
z%DumbDBMTestCase.test_dumbdbm_creation�umaskztest needs os.umask()�chmodztest needs os.chmod()c	Cs�z$t�d�}t�tdd�}|��Wdt�|�Xd}tjdkrDd}ddl}t�td�}|�|�	|j
�|�t�td	�}|�|�	|j
�|�dS)
N�ri�i��posixi�rz.datz.dir)rr#rrrr�name�statr�S_IMODE�st_mode)rZ	old_umaskr Z
expected_moder(�strrr	�test_dumbdbm_creation_mode*s

z*DumbDBMTestCase.test_dumbdbm_creation_modecCs6t�t�}d|d<|�|dd�|��|��dS)Nrr)rrrrr)rr rrr	�test_close_twice@s

z DumbDBMTestCase.test_close_twicecCs`|��t�td�}d|jd<|d<|�|�|�|�dd�d�|�|dd�|��dS)N�wsindentedrsxxxsfoo)	�init_dbrrrrrr�
setdefaultr)rr rrr	�test_dumbdbm_modificationGs
z)DumbDBMTestCase.test_dumbdbm_modificationc	Cs�|��t�td�}|�|�|�td��d|d<WdQRX|�td��|d=WdQRX|�|�d�|j	d�|�|�dd�d�|�
|�d��|�t��|dWdQRX|�
�dS)	N�rz'The database is opened for reading only�xrrrsxxxsfoo)r/rrrr�assertWarnsRegex�DeprecationWarningr�getrZassertIsNone�assertRaises�KeyErrorr)rr rrr	�test_dumbdbm_readQs
z!DumbDBMTestCase.test_dumbdbm_readcCs(|��t�t�}|�|�}|��dS)N)r/rrr�keys_helperr)rr rrrr	�test_dumbdbm_keyscs

z!DumbDBMTestCase.test_dumbdbm_keyscCs*t�t�}d|d<|�d|�|��dS)Nshello�1)rrr�assertInr)rr rrr	�test_write_containsis
z#DumbDBMTestCase.test_write_containscCsHt�t�}d|d<d|d<|��t�t�}|�|dd�|��dS)Nshellor<shello2)rrrrr)rr rrr	�test_write_write_reados

z%DumbDBMTestCase.test_write_write_readcCs4|��t�td�}|�|d|jd�d��dS)Nr2rzutf-8)r/rrrrr�encode)rr rrr	�
test_str_readyszDumbDBMTestCase.test_str_readcCsx|��t�t�}d|d<d|d<|��t�td�}|�d|�|�|d�d�|jd�d��|�|dd�dS)	Nrr�a�1r2zutf-8r<r)	r/rrrrr=rr@r)rr rrr	�test_str_write_contains~s
z'DumbDBMTestCase.test_str_write_containsc	Cs�t�t�}d|d<d|d<|��t�tdd��}|��}WdQRXtjdkr^|�dd	�}n|�d	d�}t�tdd
��}|�	|�WdQRXt�t�}|�
|dd�|�
|dd�dS)Nshellor<shello2�2z.dir�rb�
�
s
�wb)rrrr�io�readr�linesep�replace�writer)rr �file�datarrr	�test_line_endings�s


z!DumbDBMTestCase.test_line_endingscCs4|�|�}x$|jD]}|�|j|||�qWdS)N)r:rr)rr rr!rrr	r�s
zDumbDBMTestCase.read_helpercCs6t�td�}x|jD]}|j|||<qW|��dS)N�n)rrrrr)rr �krrr	r/�szDumbDBMTestCase.init_dbcCs*t|���}t|j���}|�||�|S)N)�sortedrrr)rr rZdkeysrrr	r:�szDumbDBMTestCase.keys_helperc	Cs�ddl}i}x�td�D]�}t�t�}xptd�D]d}|�d�}|��dkr^||kr�||=||=q.|�d�|�d�}|||<|||<|�|||�q.W|��t�t�}t	dd	�|�
�D��}t	|�
��}|�||�|��qWdS)
Nr��dZ
abcdefghijklmg�������?)rrri'css |]\}}|�d�|fVqdS)zlatin-1N)r@)�.0rS�vrrr	�	<genexpr>�sz.DumbDBMTestCase.test_random.<locals>.<genexpr>)�random�rangerrr�choiceZ	randrangerrrT�items)	rrZ�dZdummyr rSrXZexpectedZgotrrr	�test_random�s(


zDumbDBMTestCase.test_randomc	Csrt�td��}d|d<WdQRXt�td��}|�t|���dg�WdQRX|�tj��|��WdQRXdS)Nrzcontext managerzdumbdbm context managerr2sdumbdbm context manager)rrrrrrr7�error)r�dbrrr	�test_context_manager�s z$DumbDBMTestCase.test_context_managerc
Cs�t�td�}|��xhttj|�ttj|d�ttj|�ttj	|�fD]6}|�
tj��}|d�WdQRX|�t
|j�d�qDWxXt�d�t�d�t�d�tfD]6}|�
tj��}||�WdQRX|�t
|j�d�q�WdS)Nr�b�testz"DBM object has already been closedrZiterkeysr])rrrrr�operator�delitem�setitem�getitem�containsr7r`r�strZ	exception�methodcaller�len)rr Zmeth�cmrrr	�test_check_closed�s$



z!DumbDBMTestCase.test_check_closedc	Csbt�td��$}x|jD]}|j|||<qWWdQRXt�td��}|�|��g�WdQRXdS)NrR)rrrrrr)rr rSrrr	�test_create_new�s
zDumbDBMTestCase.test_create_newcCsxttdd��}|�d�WdQRXt���B}|�t��t�t��}WdQRXWdQRX|�|�	�d�WdQRXdS)Nz.dirr.zstr(print('Hacked!')), 0
�)
rrrNrZcaptured_stdoutr7�
ValueErrorrr�getvalue)r�stream�stdoutr rrr	�	test_eval�s
zDumbDBMTestCase.test_evalc
CsDx>dD]6}t�|�td��t�t|�}WdQRX|��qWdS)N)r2r.zIThe database file is missing, the semantics of the 'c' flag will be used.)r
r4r5rrrr)r�valuer rrr	�test_warn_on_ignored_flags�s
z*DumbDBMTestCase.test_warn_on_ignored_flagsc
Cs�t�td��}WdQRXt�td�xjdD]b}|�td��t�t|�}WdQRX|��|�tj	�
td�|dk�|�tj	�
td��q,WdS)NrRz.dir)r2r.zFThe index file is missing, the semantics of the 'c' flag will be used.r.z.bak)rrrrrr4r5rr�path�existsZassertFalse)rr rvrrr	�test_missing_indexs

z"DumbDBMTestCase.test_missing_indexc
Cs>x8dD]0}|�td��t�t|�}WdQRX|��qWdS)N)�xZrfNz)Flag must be one of 'r', 'w', 'c', or 'n')r4r5rrrr)r�flagr rrr	�test_invalid_flags

z!DumbDBMTestCase.test_invalid_flagc
Cs�t����}tj�|d�}t�|d��8}|�t|�	��g�x|j
D]}|j
|||<qBWWdQRXt�|dtj
�t�|dtj
�t�|tj
tjB�t�|d��(}|�t|�	��t|j
��|��WdQRXWdQRXdS)NrarRz.dirz.datr2)rZtemp_dirrrx�joinrrrrrrr$r(�S_IRUSR�S_IXUSRrTr)r�dirZfnamer r!rrr	�test_readonly_filess
z#DumbDBMTestCase.test_readonly_filesz*requires OS support of non-ASCII encodingsc	Cs�tj}xdD]}|�tj||�qWt�|d��}d|d<WdQRX|�tj�	|d��|�tj�	|d��t�|d��:}|�
t|���dg�|�d|k�|�
|dd�WdQRXdS)N)z.dirz.datz.bakrsvalueskeyz.datz.dirr2)
r�TESTFN_NONASCIIZ
addCleanuprrrZ
assertTruerrxryrrr)r�filename�suffixrarrr	�test_nonascii_filename,s
z&DumbDBMTestCase.test_nonascii_filenamecCs
t�dS)N)r
)rrrr	�tearDown;szDumbDBMTestCase.tearDowncCs
t�dS)N)r
)rrrr	�setUp>szDumbDBMTestCase.setUpN)%�__name__�
__module__�__qualname__r@rr"�unittestZ
skipUnless�hasattrrr,r-r1r9r;r>r?rArDrQrr/r:r_rbrnrorurwrzr}r�rr�r�r�r�rrrr	rsH


	
r�__main__)�__doc__rJrerr(r�Zdbm.dumbZdumbrrdr�	functoolsrZTESTFNrr
ZTestCaserr��mainrrrr	�<module>s-