AlkantarClanX12

Your IP : 18.119.163.95


Current Path : /lib64/python3.8/dbm/__pycache__/
Upload File :
Current File : //lib64/python3.8/dbm/__pycache__/dumb.cpython-38.opt-1.pyc

U

e5d-�@sVdZddlZddlZddlZddlZddgZ	dZ
eZGdd�dej
j�Zdd
d�ZdS)a�A dumb and slow but simple dbm clone.

For database spam, spam.dir contains the index (a text file),
spam.bak *may* contain a backup of the index (also a text file),
while spam.dat contains the data (a binary file).

XXX TO DO:

- seems to contain a bug when updating...

- reclaim free space (currently, space once occupied by deleted or expanded
items is never reused)

- support concurrent access (currently, if two processes take turns making
updates, they can mess up the index)

- support efficient access to large databases (currently, the whole index
is read when the database is opened, and some updates rewrite the whole index)

- support opening for read-only (flag = 'm')

�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� /usr/lib64/python3.8/dbm/dumb.py�__init__0s




z_Database.__init__cCs�|dkrB|j|j|jfD](}zt�|�Wqtk
r>YqXqztj|jddd�}WnHtk
r�|dkrr�tj|jddd��}|�|j�W5QRXYn
X|�	�dS)N�nr�Latin-1��encoding�rr�w)
r
rr	�_os�remove�OSError�_ior�_chmod�close)rr�filename�frrrr
Isz_Database._createc	Cs�d|_i|_ztj|jddd�}Wn$tk
rF|dkr<�d|_YnFX|�:|D].}|��}t�|�\}}|�	d�}||j|<qRW5QRXdS)NFrrrrT)
�	_modifiedrrrr	r�rstrip�_astZliteral_eval�encode)rrr"�line�key�pos_and_siz_pairrrrr\s
z_Database._updatec	Cs�|jdks|jsdSz|j�|j�Wntk
r:YnXz|j�|j|j�Wntk
rfYnX|jj	|jddd��B}|�
|j�|j��D]$\}}d|�d�|f}|�
|�q�W5QRXdS)Nrrr�%r, %r
)rr#r�unlinkrr�renamer	rrr�items�decode�write)rr"r(r)�entryrrr�_commitpsz_Database._commitcCs|jdkrtd��dS�N�"DBM object has already been closed)rr�rrrr�_verify_open�s
z_Database._verify_openc	Cs\t|t�r|�d�}|��|j|\}}t�|jd��}|�|�|�	|�}W5QRX|S)N�utf-8�rb)
�
isinstance�strr&r5rrrr
�seek�read)rr(�pos�sizr"Zdatrrr�__getitem__�s


z_Database.__getitem__c	Csrt�|jd��R}|�dd�t|���}|tdtt}|�d||�|}|�|�W5QRX|t|�fS)N�rb+r���)	rrr
r:�int�tell�
_BLOCKSIZEr/�len)r�valr"r<Znposrrr�_addval�sz_Database._addvalc	Cs:t�|jd��}|�|�|�|�W5QRX|t|�fS)Nr?)rrr
r:r/rF)rr<rGr"rrr�_setval�s
z_Database._setvalc	CsP||j|<tj|jddd��*}|�|j�|�d|�d�|f�W5QRXdS)N�arrr*)rrrr	rr/r.)rr(r)r"rrr�_addkey�s
z_Database._addkeycCs�|jrtd��t|t�r$|�d�}nt|ttf�s:td��t|t�rP|�d�}nt|ttf�sftd��|��d|_	||j
kr�|�||�|��n^|j
|\}}|t
dt
}t|�t
dt
}||kr�|�||�|j
|<n|�|�|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__cCs0zt|j�WStk
r*td�d�YnXdSr2)�listrrOrr4rrr�keys�sz_Database.keyscs ����fdd��j��D�S)Ncsg|]}|�|f�qSrr)�.0r(r4rr�
<listcomp>�sz#_Database.items.<locals>.<listcomp>)r5rrTr4rr4rr-�sz_Database.itemscCsRt|t�r|�d�}z||jkWStk
rL|jdkrFtd�d�n�YnXdS)Nr6r3)r8r9r&rrOrrQrrr�__contains__�s


z_Database.__contains__cCs0zt|j�WStk
r*td�d�YnXdSr2)�iterrrOrr4rrr�iterkeyssz_Database.iterkeyscCs0zt|j�WStk
r*td�d�YnXdSr2)rFrrOrr4rrr�__len__
sz_Database.__len__c	Cs,z|��W5d|_|_|_|_XdS�N)rr
r	rr1r4rrrr sz_Database.closecCs|j�||j�dSr[)r�chmodr)r�filerrrrsz_Database._chmodcCs|Sr[rr4rrr�	__enter__sz_Database.__enter__cGs|��dSr[)r )r�argsrrr�__exit__sz_Database.__exit__N)r)�__name__�
__module__�__qualname__rrrr
rr1�syncr5r>rHrIrKrPrRrTr-rWrY�__iter__rZr �__del__rr^r`rrrrr#s2

	%rr�cCsVzt�d�}t�|�Wntk
r,YnX||@}|dkrHtd��t|||d�S)aEOpen the database file, filename, and return corresponding object.

    The flag argument, used to control how the database is opened in the
    other DBM implementations, supports only the semantics of 'c' and 'n'
    values.  Other values will default to the semantics of 'c' value:
    the database will always opened for update and will be created if it
    does not exist.

    The optional mode argument is the UNIX mode of the file, used only when
    the database has to be created.  It defaults to octal code 0o666 (and
    will be modified by the prevailing umask).

    r)rrrrz)Flag must be one of 'r', 'w', 'c', or 'n')r)r�umask�AttributeError�
ValueErrorr)r]rrZumrrrr"s

)rrg)�__doc__Zastr%�ior�osrZcollections.abc�collections�__all__rErr�abc�MutableMappingrrrrrr�<module>s