AlkantarClanX12

Your IP : 3.16.69.243


Current Path : /opt/alt/python37/lib64/python3.7/dbm/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/dbm/__pycache__/dumb.cpython-37.opt-1.pyc

B

� f�/�@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�-/opt/alt/python37/lib64/python3.7/dbm/dumb.py�__init__0s




z_Database.__init__cCs�|dkrFx<|j|j|jfD](}yt�|�Wqtk
r@YqXqWytj|jddd�}Wn^tk
r�|dkr�ddl}|j	dt
dd	�tj|jd
dd��}|�|j�WdQRXYn
X|��dS)N�nrzLatin-1)�encoding)rrrzIThe database file is missing, the semantics of the 'c' flag will be used.�)�
stacklevel�w)
r
rr	�_os�remove�OSError�_ior�warnings�warn�DeprecationWarning�_chmod�close)rr�filename�frrrrr
Is 

z_Database._createc	Cs�i|_ytj|jddd�}Wn>tk
rZ|j|_|dkrVddl}|jdt	dd�YnPXd	|_|�>x6|D].}|�
�}t�|�\}}|�
d�}||j|<qnWWdQRXdS)
NrzLatin-1)r)rrrzFThe index file is missing, the semantics of the 'c' flag will be used.r)rF)rrrr	rr�	_modifiedrrr �rstrip�_astZliteral_eval�encode)rrr$r�line�key�pos_and_siz_pairrrrr_s 


z_Database._updatec	Cs�|jdks|jsdSy|j�|j�Wntk
r:YnXy|j�|j|j�Wntk
rfYnX|jj	|jddd��F}|�
|j�x2|j��D]$\}}d|�d�|f}|�
|�q�WWdQRXdS)NrzLatin-1)rz%r, %r
)rr%r�unlinkrr�renamer	rrr!�items�decode�write)rr$r*r+�entryrrr�_commitvsz_Database._commitcCs|jdkrtd��dS)Nz"DBM object has already been closed)rr)rrrr�_verify_open�s
z_Database._verify_openc	Cs\t|t�r|�d�}|��|j|\}}t�|jd��}|�|�|�	|�}WdQRX|S)Nzutf-8�rb)
�
isinstance�strr(r3rrrr
�seek�read)rr*�pos�sizr$Zdatrrr�__getitem__�s


z_Database.__getitem__c	Csrt�|jd��R}|�dd�t|���}|tdtt}|�d||�|}|�|�WdQRX|t|�fS)Nzrb+r���)	rrr
r7�int�tell�
_BLOCKSIZEr0�len)r�valr$r9Znposrrr�_addval�sz_Database._addvalc	Cs:t�|jd��}|�|�|�|�WdQRX|t|�fS)Nzrb+)rrr
r7r0rB)rr9rCr$rrr�_setval�s
z_Database._setvalc	CsP||j|<tj|jddd��*}|�|j�|�d|�d�|f�WdQRXdS)N�azLatin-1)rz%r, %r
)rrrr	r!r0r/)rr*r+r$rrr�_addkey�s
z_Database._addkeycCs|jrddl}|jdtdd�t|t�r4|�d�}nt|ttf�sJt	d��t|t�r`|�d�}nt|ttf�svt	d��|�
�d|_||jkr�|�
||�|��n^|j|\}}|td	t}t|�td	t}||kr�|�||�|j|<n|�|�|j|<dS)
Nrz'The database is opened for reading onlyr<)rzutf-8zkeys must be bytes or stringszvalues must be bytes or stringsTr=)rrrr r5r6r(�bytes�	bytearray�	TypeErrorr3r%rrGrDrArBrE)rr*rCrr9r:Z	oldblocksZ	newblocksrrr�__setitem__�s,



z_Database.__setitem__cCsT|jrddl}|jdtdd�t|t�r2|�d�}|��d|_|j	|=|�
�dS)Nrz'The database is opened for reading onlyr<)rzutf-8T)rrrr r5r6r(r3r%rr2)rr*rrrr�__delitem__�s


z_Database.__delitem__cCs.y
t|j�Stk
r(td�d�YnXdS)Nz"DBM object has already been closed)�listrrJr)rrrr�keys�s
z_Database.keyscs ����fdd��j��D�S)Ncsg|]}|�|f�qSrr)�.0r*)rrr�
<listcomp>sz#_Database.items.<locals>.<listcomp>)r3rrN)rr)rrr.�sz_Database.itemscCsPt|t�r|�d�}y
||jkStk
rJ|jdkrDtd�d�n�YnXdS)Nzutf-8z"DBM object has already been closed)r5r6r(rrJr)rr*rrr�__contains__s



z_Database.__contains__cCs.y
t|j�Stk
r(td�d�YnXdS)Nz"DBM object has already been closed)�iterrrJr)rrrr�iterkeys
s
z_Database.iterkeyscCs.y
t|j�Stk
r(td�d�YnXdS)Nz"DBM object has already been closed)rBrrJr)rrrr�__len__s
z_Database.__len__c	Cs,z|��Wdd|_|_|_|_XdS)N)r2rr
r	r)rrrrr"sz_Database.closecCs t|jd�r|j�||j�dS)N�chmod)�hasattrrrUr)r�filerrrr!"sz_Database._chmodcCs|S)Nr)rrrr�	__enter__&sz_Database.__enter__cGs|��dS)N)r")r�argsrrr�__exit__)sz_Database.__exit__N)r)�__name__�
__module__�__qualname__rrrr
rr2�syncr3r;rDrErGrKrLrNr.rQrS�__iter__rTr"�__del__r!rXrZrrrrr#s2

	'rr�cCsfyt�d�}t�|�Wntk
r,YnX||@}|dkrXddl}|jdtdd�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)rrrrNz)Flag must be one of 'r', 'w', 'c', or 'n'r<)r)r)r�umask�AttributeErrorrrr r)rWrrZumrrrrr-s


)rra)�__doc__Zastr'�ior�osrZcollections.abc�collections�__all__rArr�abc�MutableMappingrrrrrr�<module>s