Your IP : 3.21.244.34


Current Path : /opt/alt/python310/lib64/python3.10/dbm/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/dbm/__pycache__/dumb.cpython-310.opt-2.pyc

o

6��f-�@sT	ddlZddlZddlZddlZddgZdZ	e
ZGdd�dejj
�Zd
d	d�ZdS)�N�error�openic@s�eZdZeZeZd+dd�Zdd�Zdd�Zdd	�ZeZ	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�ZeZd d!�Zd"d#�ZeZd$d%�Zd&d'�Zd(d)�Zd*S),�	_Database�ccCsL||_|dk|_|d|_|d|_|d|_d|_|�|�|�|�dS)N�rz.dirz.datz.bak)�_mode�	_readonly�_dirfile�_datfile�_bakfile�_index�_create�_update)�selfZfilebasename�mode�flag�r�//opt/alt/python310/lib64/python3.10/dbm/dumb.py�__init__0s




z_Database.__init__cCs�|dkr|j|j|jfD]}zt�|�WqtyYqwztj|jddd�}Wn0tyZ|dvr6�tj|jddd��}|�|j�Wd�YdS1sRwYYdSw|�	�dS)N�nr�Latin-1��encoding�rr�w)
r
rr	�_os�remove�OSError�_ior�_chmod�close)rr�filename�frrrr
Is"�&��z_Database._createcCs�d|_i|_ztj|jddd�}Wnty#|dvr�d|_YdSw|�#|D]}|��}t�|�\}}|�	d�}||j|<q)Wd�dS1sLwYdS)NFrrrrT)
�	_modifiedrrrr	r�rstrip�_astZliteral_eval�encode)rrr"�line�key�pos_and_siz_pairrrrr\s"�
�"�z_Database._updatecCs�|jdus|js
dSz	|j�|j�Wn	tyYnwz|j�|j|j�Wn	ty1Ynw|jj	|jddd��'}|�
|j�|j��D]\}}d|�d�|f}|�
|�qHWd�dS1sfwYdS)Nrrr�%r, %r
)rr#r�unlinkrr�renamer	rrr�items�decode�write)rr"r(r)�entryrrr�_commitps&���"�z_Database._commitcCs|jdur	td��dS�N�"DBM object has already been closed)rr�rrrr�_verify_open�s
�z_Database._verify_opencCsrt|t�r
|�d�}|��|j|\}}t�|jd��}|�|�|�	|�}Wd�|S1s2wY|S)N�utf-8�rb)
�
isinstance�strr&r5rrrr
�seek�read)rr(�pos�sizr"Zdatrrr�__getitem__�s



��z_Database.__getitem__cCs�t�|jd��.}|�dd�t|���}|tdtt}|�d||�|}|�|�Wd�n1s8wY|t|�fS)N�rb+r���)	rrr
r:�int�tell�
_BLOCKSIZEr/�len)r�valr"r<Znposrrr�_addval�s�z_Database._addvalcCsNt�|jd��}|�|�|�|�Wd�n1swY|t|�fS)Nr?)rrr
r:r/rF)rr<rGr"rrr�_setval�s

�z_Database._setvalcCsf||j|<tj|jddd��}|�|j�|�d|�d�|f�Wd�dS1s,wYdS)N�arrr*)rrrr	rr/r.)rr(r)r"rrr�_addkey�s

"�z_Database._addkeycCs�|jrtd��t|t�r|�d�}nt|ttf�std��t|t�r(|�d�}nt|ttf�s3td��|��d|_	||j
vrJ|�||�|��dS|j
|\}}|t
dt
}t|�t
dt
}||krr|�||�|j
|<dS|�|�|j
|<dS)N�'The database is opened for reading onlyr6zkeys must be bytes or stringszvalues must be bytes or stringsTrA)rrr8r9r&�bytes�	bytearray�	TypeErrorr5r#rrKrHrErFrI)rr(rGr<r=Z	oldblocksZ	newblocksrrr�__setitem__�s(


z_Database.__setitem__cCsD|jrtd��t|t�r|�d�}|��d|_|j|=|��dS)NrLr6T)	rrr8r9r&r5r#rr1�rr(rrr�__delitem__�s

z_Database.__delitem__cC�&zt|j�WStytd�d�wr2)�listrrOrr4rrr�keys��

�z_Database.keyscs ����fdd��j��D�S)Ncsg|]}|�|f�qSrr)�.0r(r4rr�
<listcomp>�sz#_Database.items.<locals>.<listcomp>)r5rrUr4rr4rr-�sz_Database.itemscCsFt|t�r
|�d�}z||jvWSty"|jdur!td�d��w)Nr6r3)r8r9r&rrOrrQrrr�__contains__�s



�z_Database.__contains__cCrSr2)�iterrrOrr4rrr�iterkeysrVz_Database.iterkeyscCrSr2)rFrrOrr4rrr�__len__
rVz_Database.__len__c	CsBz|��Wd|_|_|_|_dSd|_|_|_|_w�N)r1rr
r	rr4rrrr s
6z_Database.closecCs|j�||j�dSr])r�chmodr)r�filerrrrsz_Database._chmodcCs|Sr]rr4rrr�	__enter__sz_Database.__enter__cGs|��dSr])r )r�argsrrr�__exit__sz_Database.__exit__N)r)�__name__�
__module__�__qualname__rrrr
rr1�syncr5r>rHrIrKrPrRrUr-rYr[�__iter__r\r �__del__rr`rbrrrrr#s4

	%rr�cCsV	zt�d�}t�|�Wn	tyYnw||@}|dvr$td��t|||d�S)Nr)rrrrz)Flag must be one of 'r', 'w', 'c', or 'n')r)r�umask�AttributeError�
ValueErrorr)r_rrZumrrrr"s
�
)rri)�astr%�ior�osrZcollections.abc�collections�__all__rErr�abc�MutableMappingrrrrrr�<module>s

?>