HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib64/python3.9/site-packages/borg/testsuite/__pycache__/hashindex.cpython-39.pyc
a

HZ�h�P�@s$ddlZddlZddlZddlZddlZddlZddlmZmZm	Z	ddl
mZddlmZm
Z
ddl
mZmZdd	�Zd
d�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZdS) �N�)�NSIndex�
ChunkIndex�ChunkIndexEntry)�	hashindex)�IntegrityCheckedFile�FileIntegrityError�)�BaseTestCase�unopened_tempfilecCstd|d�S)Nz%-0.32d�ascii)�bytes��x�r�>/usr/lib64/python3.9/site-packages/borg/testsuite/hashindex.py�HsrcCst�t|����S�N��hashlib�sha256rZdigestrrrr�H2src@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dS)�HashIndexTestCasec	Cs |�}|�t|�d�td�D]}||�|t|�<q|�t|�d�td�D]}|�|t|�||��qLtd�D]}||d�|t|�<qr|�t|�d�td�D] }|�|t|�||d��q�td�D]}|t|�=q�tdd�D]}t|�|vs�J�q�td�D]}t|�|v�sJ��qtd�D]}|�t|jt|���q(|�t|�d�t���}|�|�~t	|d��*}|�t
�|����
�|�Wd�n1�s�0Y|�|�}|�t|�d�tdd�D]"}|�|t|�||d���q�|��|�t|�d�|�|�~|�t|�|��d�Wd�n1�sF0Y|�}|�td�|d��td�|v�s|J�|td�|d�k�s�J�|�td�|d��td�|v�s�J�|td�|d�k�s�J�|�td�|d��|d�k�s�J�|�td�|d��|d�k�sJ�~dS)	Nr�dr�2�rb�*�r	)�assert_equal�len�ranger�
assert_raises�KeyError�__delitem__r�write�openrr�readZ	hexdigest�clear�
setdefault)�self�clsZ
make_valueZsha�idxr�filepath�fdrrr�
_generic_testsZ
:
 
6""zHashIndexTestCase._generic_testcCs|�tdd�d�dS)NcSs||fSrrrrrr�<lambda>Z�z0HashIndexTestCase.test_nsindex.<locals>.<lambda>Z@85f72b036c692c8266e4f51ccf0cff2147204282b5e316ae508d30a448d88fef)r.r�r)rrr�test_nsindexYs�zHashIndexTestCase.test_nsindexcCs|�tdd�d�dS)NcSs
|||fSrrrrrrr/^r0z3HashIndexTestCase.test_chunkindex.<locals>.<lambda>Z@c83fdf33755fc37879285f2ecfc5d1f63b97577494902126b6fb6f3e4d852488)r.rr1rrr�test_chunkindex]s�z!HashIndexTestCase.test_chunkindexcCs�d}t���}t�}|�|�tj�|�}|�t|�d�t|�D]}||f|t	|�<q@|�|�|tj�|�kstJ�t|�D]}|t	|�=q||�t|�d�|�|�|�|tj�|��Wd�n1s�0YdS)N��r)
rrr$�os�path�getsizerrr r)r)�nr,r+Zinitial_sizerrrr�test_resizeas


zHashIndexTestCase.test_resizecCs�t�}td�D]}||f|t|�<q|��}t|�}|�t|�d�|�tt	|�t|j|ddd��}|�t|�d�|�||dd��dS)Nr�1r)Zmarkerr)
rr r�	iteritems�listrrr!�
StopIteration�next)r)r+r�iterator�allZsecond_halfrrr�test_iteritemsrsz HashIndexTestCase.test_iteritemscCs�t�}d|td�<d|td�<d|td�<t�}d|td�<d|td�<d	|td
�<|�|�|td�dksrJ�|td�dks�J�|td�dks�J�|td
�d	ks�J�dS)
N�r	rrr	�r��rDr���,rGrF)�rr)�rDrD)��rKrH)rIrr)�rDrD�rr�merge�r)�idx1�idx2rrr�test_chunkindex_merges
z'HashIndexTestCase.test_chunkindex_mergecCs�t�}d|td�<d|td�<d|td�<|��\}}}}}}|dksJJ�|dksVJ�|d	ksbJ�|d
ksnJ�|dkszJ�|dks�J�dS)N)r	i�rr	)rr4rDr)rFi�rGrFi�6ixip�XrJ)rrZ	summarize)r)r+�sizeZcsizeZunique_sizeZunique_csizeZ
unique_chunks�chunksrrr�test_chunkindex_summarize�sz+HashIndexTestCase.test_chunkindex_summarizeN)
�__name__�
__module__�__qualname__r.r2r3r9rArRrVrrrrrs<
rc@seZdZdZdd�ZdS)�HashIndexExtraTestCasezRThese tests are separate because they should not become part of the selftest.
    cCstdtj�d}t|�}dd�t|�D�}|dd|d�|d|dd�}}t|�D]\}}|||f||<q^t|�D]\}}|||f||<q~|D]
}||=q�t|�D]\}}|||||fks�J�q�|D]}|�|�dus�J�q�|D]
}||=q�t|���gk�sJ�dS)Ni�
cSsg|]}t�t|�����qSrr)�.0�krrr�
<listcomp>�r0z=HashIndexExtraTestCase.test_chunk_indexer.<locals>.<listcomp>rrrF)�intr�MAX_LOAD_FACTORr �	enumerate�getr<r;)r)Z	key_count�indexZall_keys�keysZto_delete_keys�i�keyrrr�test_chunk_indexer�s"*z)HashIndexExtraTestCase.test_chunk_indexerN)rWrXrY�__doc__rgrrrrrZ�srZc@seZdZdd�Zdd�ZdS)�HashIndexSizeTestCasecCst�}|��dksJ�dS)NiF�)rrT�r)r+rrr�test_size_on_disk�sz'HashIndexSizeTestCase.test_size_on_diskcCs~t�}td�D]}||d|df|t|�<qt��&}|�|�tj�|�}Wd�n1s`0Y|��|kszJ�dS)Ni�rrF)	rr rrr$r5r6r7rT)r)r+rer,rTrrr�test_size_on_disk_accurate�s
*z0HashIndexSizeTestCase.test_size_on_disk_accurateN)rWrXrYrkrlrrrrri�sric@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�HashIndexRefcountingTestCasecCs~t�}tjdddf|td�<td�D]$}|�td��^}}|tjks&J�q&td�D]$}|�td��^}}|tjksTJ�qTdS)Nr	rrI)r�	MAX_VALUErr �incref�decref)r)r+re�refcount�_rrr�test_chunkindex_limit�sz2HashIndexRefcountingTestCase.test_chunkindex_limitcCs(dd�}|||�}||||�ks$J�|S)NcSsNt�}|ddf|td�<t�}|ddf|td�<|�|�|td�^}}|S)Nr	rrM)Z	refcount1Z	refcount2rPrQrqrrrrrrN�s
z2HashIndexRefcountingTestCase._merge.<locals>.merger)r)Z	refcountaZ	refcountbrN�resultrrr�_merge�s
z#HashIndexRefcountingTestCase._mergecCs(tjd}|�||�tjdks$J�dS�Nrr	�rrnru�r)Zhalfrrr�test_chunkindex_merge_limit1�s
z9HashIndexRefcountingTestCase.test_chunkindex_merge_limit1cCs|�dd�tjksJ�dS)Nl^�ei�5w)rurrnr1rrr�test_chunkindex_merge_limit2�sz9HashIndexRefcountingTestCase.test_chunkindex_merge_limit2cCs(tjd}|�|d|�tjks$J�dSrvrwrxrrr�test_chunkindex_merge_limit3�s
z9HashIndexRefcountingTestCase.test_chunkindex_merge_limit3cCsFtjd}|�|d|�tjks$J�|�|d|d�tjksBJ�dSrvrwrxrrr�test_chunkindex_merge_limit4�s
z9HashIndexRefcountingTestCase.test_chunkindex_merge_limit4cCsZt�}|�td�ddd�|td�dks.J�|�td�ddd�|td�dksVJ�dS)	Nr	rIrJrL�rIrJrLrrF)rJrrF)r�addr�r)rPrrr�test_chunkindex_add�s
z0HashIndexRefcountingTestCase.test_chunkindex_addcCsJt�}tjddf|td�<|�td��|td�^}}|tjksFJ�dS�NrJrLr	)rrnrro�r)rPrqrrrrr�test_incref_limits
z.HashIndexRefcountingTestCase.test_incref_limitcCsJt�}tjddf|td�<|�td��|td�^}}|tjksFJ�dSr�)rrnrrpr�rrr�test_decref_limits
z.HashIndexRefcountingTestCase.test_decref_limitcCsNt�}d|td�<|�t��|�td��Wd�n1s@0YdS)N)rrrr	)rrr!�AssertionErrorrprrrr�test_decref_zerosz-HashIndexRefcountingTestCase.test_decref_zerocCsvt�}|�td�ddd�|td�dks.J�|�td��|td�dksPJ�|�td��|td�dksrJ�dS)Nr	rIrJrLr})rJrJrL)rr~rrorprrrr�test_incref_decrefsz/HashIndexRefcountingTestCase.test_incref_decrefcCsLt�}|�t��(tjdddf|td�<Wd�n1s>0YdS)Nr	r)rr!r�rnrrrrr�test_setitem_raises"sz0HashIndexRefcountingTestCase.test_setitem_raisescCs�t�}|�t��|�td��Wd�n1s40Y|�t��|�td��Wd�n1sl0Y|�t��|td�Wd�n1s�0Y|�t��$|�td�ddd�Wd�n1s�0YdS)Nr	���r)rr!r"rorrp�
OverflowErrorr~rjrrr�
test_keyerror's,,*z*HashIndexRefcountingTestCase.test_keyerrorN)rWrXrYrsruryrzr{r|r�r�r�r�r�r�r�rrrrrm�s
	rmc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�HashIndexDataTestCases(eJzt0L0NgmAUhtHLT0LDEI6AuAEhMVYmVnSuYefC7AB3Aj9KNedJbnfyFne6P67P27w0EdG1Eac+Cm1ZybAsy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7Isy7LsL9nhc+cqTZ3XlO2Ys++Du5fX+l1/YFmWZVmWZVmWZVmWZVmWZVmWZVmWZVmWZVmWZVmWZVmWZVmWZVmWZVmWZVmWZVmWZVn2/+0O2rYccw==c	Cs�t���n}tj�|d�}|�|�t|d��,}|�|���Wd�Wd�S1s^0YWd�n1s|0YdS)Nr+r)	�tempfile�TemporaryDirectoryr5r6�joinr$r%�_packr&)r)r+�tempdir�file�frrr�_serialize_hashindex9s


z*HashIndexDataTestCase._serialize_hashindexc	Cs~t���b}tj�|d�}t|d�� }|�|�|��Wd�n1sH0Yt�	|�Wd�S1sp0YdS)Nr+�wb)
r�r�r5r6r�r%r$�_unpackrr&)r)�
bytestringr�r�r�rrr�_deserialize_hashindex@s

.z,HashIndexDataTestCase._deserialize_hashindexcCst�t�|��Sr)�base64Z	b64encode�zlib�compress�r)r�rrrr�GszHashIndexDataTestCase._packcCst�t�|��Sr)r��
decompressr�Z	b64decoder�rrrr�JszHashIndexDataTestCase._unpackcCsRt�}d|td�<d|td�<d|td�<|�|�}|�|�|�|j�ksNJ�dS)N�r	rrFr	�i���rrr�lxl�rrrF)rrr�r��	HASHINDEX)r)rPZ
serializedrrr�test_identical_creationMs
z-HashIndexDataTestCase.test_identical_creationcCs�|�|j�}|td�dks J�|td�dks4J�|td�dksHJ�t�}d|td�<|�|�|td�tjdd	fks�J�dS)
Nr	r�rr�rFr�)l��rJrLrJrL)r�r�rrrNrnrOrrr�test_read_known_goodVs
z*HashIndexDataTestCase.test_read_known_goodN)
rWrXrYr�r�r�r�r�r�r�rrrrr�3s	r�c@seZdZdd�Zdd�ZdS)�HashIndexIntegrityTestCasecCsv|�|j�}tj�|d�}t|dd��}|�|�Wd�n1sF0Y|j}d|vsbJ�d|vsnJ�||fS)Nr+T)r6r$�finalZ
HashHeader)r�r�r5r6r�rr$�integrity_data)r)r�r+r�r-r�rrr�write_integrity_checked_indexcs(z8HashIndexIntegrityTestCase.write_integrity_checked_indexc
Cs�t����}|�|�\}}t|d��}|�d�Wd�n1sB0Y|�t��Ht|d|d��}t�	|�Wd�n1s�0YWd�n1s�0YWd�n1s�0YdS)Nzr+bsFooF)r6r$r�)
r�r�r�r%r$r!rrrr&)r)r�r�r�r-rrr�test_integrity_checked_filems
(z6HashIndexIntegrityTestCase.test_integrity_checked_fileN)rWrXrYr�r�rrrrr�bs
r�c@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�HashIndexCompactTestCasecCsdt��}|�d�|�|�dd��|�|�dd��|�d�dd��|�d�dd��||_dS)NsBORG_IDXrH�little� r	�)�io�BytesIOr$�to_bytes�
index_data)r)�num_entries�num_bucketsr�rrrrcxs
zHashIndexCompactTestCase.indexcCs|j�d�t�|j�}|S)Nr)r��seekrr&)r)rcrrr�index_from_data�sz(HashIndexCompactTestCase.index_from_datacCst��}|�|�|��Sr)r�r�r$�getvalue)r)rc�datarrr�
index_to_data�s
z&HashIndexCompactTestCase.index_to_datacCs|��}|��|�|�}|Sr)r��compactr�)r)rc�
compact_indexrrr�index_from_data_compact_to_data�s
z8HashIndexCompactTestCase.index_from_data_compact_to_datacGs.|j�|�|D]}|j�|�dd��qdS)NrHr�)r�r$r�)r)rf�values�valuerrr�write_entry�sz$HashIndexCompactTestCase.write_entrycCs|�|ddd�dS)Nl��r�r��r)rfrrr�write_empty�sz$HashIndexCompactTestCase.write_emptycCs|�|ddd�dS)Nl��rr�r�rrr�
write_deleted�sz&HashIndexCompactTestCase.write_deletedcCs�|jddd�|�td�ddd�|�td��|�td��|�td�ddd�|�td	�d
dd�|�td��|��}|jddd�|�td�ddd�|�td�ddd�|�td	�d
dd�||j��ks�J�dS)
NrFrJ�r�r�rr	rrIrLrH��	r[)rcr�rr�r�r�r�r��r)r�rrr�test_simple�sz$HashIndexCompactTestCase.test_simplecCs�|jddd�|�td��|�td�ddd�|�td��|�td�ddd�|�td	�d
dd�|�td��|��}|jddd�|�td�ddd�|�td�ddd�|�td	�d
dd�||j��ks�J�dS�
NrFrJr�r	rrrIrLrHr�r�r[�rcr�rr�r�r�r�r�r�rrr�test_first_empty�sz)HashIndexCompactTestCase.test_first_emptycCs�|jddd�|�td��|�td�ddd�|�td��|�td�ddd�|�td��|�td	�d
dd�|��}|jddd�|�td�ddd�|�td�ddd�|�td	�d
dd�||j��ks�J�dSr�r�r�rrr�test_last_used�sz'HashIndexCompactTestCase.test_last_usedcCs�|jddd�|�td��|�td�ddd�|�td�ddd�|�td��|�td��|�td	�d
dd�|��}|jddd�|�td�ddd�|�td�ddd�|�td	�d
dd�||j��ks�J�dSr�r�r�rrr�test_too_few_empty_slots�sz1HashIndexCompactTestCase.test_too_few_empty_slotscCs�|jddd�|�td��|�td��|�td��|�td��|�td��|�td��|��}|jddd�||j��ks�J�dS)	NrrJr�r	rFrrIrH)rcr�rr�r�r�r�r�rrr�
test_empty�sz#HashIndexCompactTestCase.test_emptycCs�t�}t�}d|td�<d|td�<d|td�<|��|��dksHJ�|�|�|td�dksfJ�|td�dkszJ�|td�dks�J�dS)NrBr	rCrrErF�)rrr�rTrN)r)ZmasterrPrrr�
test_merge�s
z#HashIndexCompactTestCase.test_mergeN)rWrXrYrcr�r�r�r�r�r�r�r�r�r�r�r�rrrrr�wsr�c@seZdZdd�ZdS)�NSIndexTestCasecCs|t�}|�t��&tjddf|td�<Wd�n1s<0Ytd�|vsVJ�tjdf|td�<td�|vsxJ�dS)Nr	rr)rr!r�rnrrjrrr�test_nsindex_segment_limits4z*NSIndexTestCase.test_nsindex_segment_limitN)rWrXrYr�rrrrr�sr�c@seZdZdd�ZdS)�AllIndexTestCasecCs tjdksJ�tjdksJ�dS)Ng�?)rr`rr1rrr�test_max_load_factor
sz%AllIndexTestCase.test_max_load_factorN)rWrXrYr�rrrrr�sr�c@seZdZdd�ZdS)�IndexCorruptionTestCasecsddlm��fdd��t��td�D]}d|f��d|�<q&���dksNJ�td�D]}��d|�=qVtd�D]}d	|f��d	|�<qp��fd
d�tdd�D�dd�tdd�D�ks�J���fd
d�td�D�dd�td�D�ks�J���fdd�td�D�dd�td�D�k�sJ�dS)Nr��packcs�d||ddd�S)Nz<IIQQQrr)r�yr�rr�HHsz1IndexCorruptionTestCase.test_bug_4829.<locals>.HHi�i*�rKiJrScsg|]}���d|���qS�r�rb�r\r��r�r+rrr^4r0z9IndexCorruptionTestCase.test_bug_4829.<locals>.<listcomp>cSsg|]}d|f�qSr�rr�rrrr^4r0csg|]}�d|��v�qSr�rr�r�rrr^6r0cSsg|]}d�qS)Frr�rrrr^6r0csg|]}���d|���qS�rSr�r�r�rrr^9r0cSsg|]}d|f�qSr�rr�rrrr^9r0)�structr�rr rT)r)r�r)r�r+r�r�
test_bug_4829s2.z%IndexCorruptionTestCase.test_bug_4829N)rWrXrYr�rrrrr�sr�)r�rr�r5r�r�rrrr�Zcrypto.file_integrityrrr
rrrrrZrirmr�r�r�r�r�r�rrrr�<module>s.f/