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.opt-1.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]}q�td�D]}q�td�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�s"0Y|�}|�td�|d��|�td�|d��~dS)Nr�dr�2�rb�*�)�assert_equal�len�ranger�
assert_raises�KeyError�__delitem__r�write�openrr�readZ	hexdigest�clear�
setdefault)�self�clsZ
make_valueZsha�idxr�filepath�fdrrr�
_generic_testsN
:
 
6zHashIndexTestCase._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@|�|�t|�D]}|t	|�=qh|�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 rZ	iteritems�listrrr!�
StopIteration�next)r)r+r�iterator�allZsecond_halfrrr�test_iteritemsrsz HashIndexTestCase.test_iteritemscCsbt�}d|td�<d|td�<d|td�<t�}d|td�<d|td�<d	|td
�<|�|�dS)N�r	rrr	�r��rCr���,rFrE)�rr)�rCrC)��rJrG�rr�merge�r)�idx1�idx2rrr�test_chunkindex_merges
z'HashIndexTestCase.test_chunkindex_mergecCsBt�}d|td�<d|td�<d|td�<|��\}}}}}}dS)N)r	i�rr	)rr4rCr)rEi�rFrE)rrZ	summarize)r)r+�sizeZcsizeZunique_sizeZunique_csizeZ
unique_chunks�chunksrrr�test_chunkindex_summarize�sz+HashIndexTestCase.test_chunkindex_summarizeN)
�__name__�
__module__�__qualname__r.r2r3r9r@rPrSrrrrrs<
rc@seZdZdZdd�ZdS)�HashIndexExtraTestCasezRThese tests are separate because they should not become part of the selftest.
    cCs�tdtj�d}t|�}dd�t|�D�}|dd|d�|d|dd�}}t|�D]\}}|||f||<q^t|�D]\}}|||f||<q~|D]
}||=q�t|�D]\}}q�|D]}q�|D]
}||=q�dS)Ni�
cSsg|]}t�t|�����qSrr)�.0�krrr�
<listcomp>�r0z=HashIndexExtraTestCase.test_chunk_indexer.<locals>.<listcomp>rrrE)�intrZMAX_LOAD_FACTORr �	enumerate)r)Z	key_count�indexZall_keys�keysZto_delete_keys�i�keyrrr�test_chunk_indexer�s"*z)HashIndexExtraTestCase.test_chunk_indexerN)rTrUrV�__doc__rbrrrrrW�srWc@seZdZdd�Zdd�ZdS)�HashIndexSizeTestCasecCs
t�}dSr)r�r)r+rrr�test_size_on_disk�sz'HashIndexSizeTestCase.test_size_on_diskcCsnt�}td�D]}||d|df|t|�<qt��&}|�|�tj�|�}Wd�n1s`0YdS)Ni�rrE)rr rrr$r5r6r7)r)r+r`r,rQrrr�test_size_on_disk_accurate�s
*z0HashIndexSizeTestCase.test_size_on_disk_accurateN)rTrUrVrfrgrrrrrd�srdc@steZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�ZdS)�HashIndexRefcountingTestCasecCsbt�}tjdddf|td�<td�D]}|�td��^}}q&td�D]}|�td��^}}qFdS)Nr	rrH)r�	MAX_VALUErr �incref�decref)r)r+r`�refcount�_rrr�test_chunkindex_limit�sz2HashIndexRefcountingTestCase.test_chunkindex_limitcCsdd�}|||�}|S)NcSsNt�}|ddf|td�<t�}|ddf|td�<|�|�|td�^}}|S)Nr	rrK)Z	refcount1Z	refcount2rNrOrlrmrrrrL�s
z2HashIndexRefcountingTestCase._merge.<locals>.merger)r)Z	refcountaZ	refcountbrL�resultrrr�_merge�s
z#HashIndexRefcountingTestCase._mergecCstjd}dS�Nr�rri�r)Zhalfrrr�test_chunkindex_merge_limit1�s
z9HashIndexRefcountingTestCase.test_chunkindex_merge_limit1cCsdSrrr1rrr�test_chunkindex_merge_limit2�sz9HashIndexRefcountingTestCase.test_chunkindex_merge_limit2cCstjd}dSrqrrrsrrr�test_chunkindex_merge_limit3�s
z9HashIndexRefcountingTestCase.test_chunkindex_merge_limit3cCstjd}dSrqrrrsrrr�test_chunkindex_merge_limit4�s
z9HashIndexRefcountingTestCase.test_chunkindex_merge_limit4cCs2t�}|�td�ddd�|�td�ddd�dS)Nr	rHrI�rrE)r�addr�r)rNrrr�test_chunkindex_add�sz0HashIndexRefcountingTestCase.test_chunkindex_addcCs<t�}tjddf|td�<|�td��|td�^}}dS�NrIrxr	)rrirrj�r)rNrlrmrrr�test_incref_limits
z.HashIndexRefcountingTestCase.test_incref_limitcCs<t�}tjddf|td�<|�td��|td�^}}dSr|)rrirrkr}rrr�test_decref_limits
z.HashIndexRefcountingTestCase.test_decref_limitcCsNt�}d|td�<|�t��|�td��Wd�n1s@0YdS)N)rrrr	)rrr!�AssertionErrorrkrzrrr�test_decref_zerosz-HashIndexRefcountingTestCase.test_decref_zerocCs:t�}|�td�ddd�|�td��|�td��dS)Nr	rHrIrx)rryrrjrkrzrrr�test_incref_decrefs
z/HashIndexRefcountingTestCase.test_incref_decrefcCsLt�}|�t��(tjdddf|td�<Wd�n1s>0YdS)Nr	r)rr!r�rirrzrrr�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"rjrrk�
OverflowErrorryrerrr�
test_keyerror's,,*z*HashIndexRefcountingTestCase.test_keyerrorN)rTrUrVrnrprtrurvrwr{r~rr�r�r�r�rrrrrh�s
	rhc@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._unpackcCs8t�}d|td�<d|td�<d|td�<|�|�}dS)N)r	rrEr	)i���rrr)lxl�rrrE)rrr�)r)rNZ
serializedrrr�test_identical_creationMs
z-HashIndexDataTestCase.test_identical_creationcCs,|�|j�}t�}d|td�<|�|�dS)N)l��rIrxrE)r��	HASHINDEXrrrLrMrrr�test_read_known_goodVs

z*HashIndexDataTestCase.test_read_known_goodN)
rTrUrVr�r�r�r�r�r�r�rrrrr�3s	r�c@seZdZdd�Zdd�ZdS)�HashIndexIntegrityTestCasecCs^|�|j�}tj�|d�}t|dd��}|�|�Wd�n1sF0Y|j}||fS)Nr+T)r6r$)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)rTrUrVr�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_IDXrG�little� r	�)�io�BytesIOr$�to_bytes�
index_data)r)�num_entries�num_bucketsr�rrrr^xs
zHashIndexCompactTestCase.indexcCs|j�d�t�|j�}|S)Nr)r��seekrr&)r)r^rrr�index_from_data�sz(HashIndexCompactTestCase.index_from_datacCst��}|�|�|��Sr)r�r�r$�getvalue)r)r^�datarrr�
index_to_data�s
z&HashIndexCompactTestCase.index_to_datacCs|��}|��|�|�}|Sr)r��compactr�)r)r^�
compact_indexrrr�index_from_data_compact_to_data�s
z8HashIndexCompactTestCase.index_from_data_compact_to_datacGs.|j�|�|D]}|j�|�dd��qdS)NrGr�)r�r$r�)r)ra�values�valuerrr�write_entry�sz$HashIndexCompactTestCase.write_entrycCs|�|ddd�dS)Nl��r�r��r)rarrr�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�dS)
NrErI�r�r�rr	rrHrxrG��	rX)r^r�rr�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�dS�
NrErIr�r	rrrHrxrGr�r�rX�r^r�rr�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�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�dSr�r�r�rrr�test_too_few_empty_slots�sz1HashIndexCompactTestCase.test_too_few_empty_slotscCs||jddd�|�td��|�td��|�td��|�td��|�td��|�td��|��}|jddd�dS)	NrrIr�r	rErrHrG)r^r�rr�r�r�rrr�
test_empty�sz#HashIndexCompactTestCase.test_emptycCsFt�}t�}d|td�<d|td�<d|td�<|��|�|�dS)NrAr	rBrrDrE)rrr�rL)r)ZmasterrNrrr�
test_merge�s
z#HashIndexCompactTestCase.test_mergeN)rTrUrVr^r�r�r�r�r�r�r�r�r�r�r�r�rrrrr�wsr�c@seZdZdd�ZdS)�NSIndexTestCasecCs\t�}|�t��&tjddf|td�<Wd�n1s<0Ytjdf|td�<dS)Nr	rr)rr!r�rirrerrr�test_nsindex_segment_limits
4z*NSIndexTestCase.test_nsindex_segment_limitN)rTrUrVr�rrrrr�sr�c@seZdZdd�ZdS)�AllIndexTestCasecCsdSrrr1rrr�test_max_load_factor
sz%AllIndexTestCase.test_max_load_factorN)rTrUrVr�rrrrr�sr�c@seZdZdd�ZdS)�IndexCorruptionTestCasecs|ddlm��fdd��t��td�D]}d|f��d|�<q&td�D]}��d|�=qFtd�D]}d|f��d|�<q`dS)	Nr��packcs�d||ddd�S)Nz<IIQQQrr)r�yr�rr�HHsz1IndexCorruptionTestCase.test_bug_4829.<locals>.HHi�rJiJiX)�structr�rr )r)r�r)r�r+r�r�
test_bug_4829s	z%IndexCorruptionTestCase.test_bug_4829N)rTrUrVr�rrrrr�sr�)r�rr�r5r�r�rrrr�Zcrypto.file_integrityrrr
rrrrrWrdrhr�r�r�r�r�r�rrrr�<module>s.f/