AlkantarClanX12

Your IP : 18.226.248.88


Current Path : /opt/alt/python35/lib64/python3.5/dbm/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/dbm/__pycache__/dumb.cpython-35.pyc



��Yf�+�@s}dZddlZddlZddlZddlZddgZdZ	e
ZGdd�dej�Z
dd	d
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!eZdZeZeZddd�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�ccCsc||_|dk|_|d|_|d|_|d|_d|_|j|�|j�dS)N�rz.dirz.datz.bak)�_mode�	_readonly�_dirfile�_datfile�_bakfile�_index�_create�_update)�selfZfilebasename�mode�flag�r�-/opt/alt/python35/lib64/python3.5/dbm/dumb.py�__init__0s	


	
z_Database.__init__cCs�|dkrUxF|j|j|jfD],}ytj|�Wq%tk
rPYq%Xq%Wytj|jddd�}WnGtk
r�tj|jddd��}|j|j�WdQRXYnX|j	�dS)N�nr�encodingzLatin-1�w)
r
rr	�_os�remove�OSError�_ior�_chmod�close)rr�filename�frrrr
Is
	
z_Database._createcCs�i|_ytj|jddd�}Wntk
rI|j|_YnfXd|_|�SxK|D]C}|j�}tj	|�\}}|j
d�}||j|<qaWWdQRXdS)NrrzLatin-1F)rrrr	rr�	_modified�rstrip�_astZliteral_eval�encode)rr�line�key�pos_and_siz_pairrrrrZs	
	
z_Database._updatecCs�|jdks|jrdSy|jj|j�Wntk
rHYnXy|jj|j|j�Wntk
rzYnX|jj	|jddd��]}|j
|j�xC|jj�D]2\}}d|jd�|f}|j
|�q�WWdQRXdS)NrrzLatin-1z%r, %r
)rr r�unlinkrr�renamer	rrr�items�decode�write)rrr%r&�entryrrr�_commitls

!z_Database._commitcCs|jdkrtd��dS)Nz"DBM object has already been closed)rr)rrrr�_verify_open�sz_Database._verify_openc	Cszt|t�r|jd�}|j�|j|\}}tj|jd��#}|j|�|j	|�}WdQRX|S)Nzutf-8�rb)
�
isinstance�strr#r.rrrr
�seek�read)rr%�pos�sizrZdatrrr�__getitem__�s

z_Database.__getitem__cCs�tj|jd��g}|jdd�t|j��}|tdtt}|jd||�|}|j|�WdQRX|t|�fS)Nzrb+r��s)	rrr
r2�int�tell�
_BLOCKSIZEr+�len)r�valrr4Znposrrr�_addval�sz_Database._addvalc
CsItj|jd��!}|j|�|j|�WdQRX|t|�fS)Nzrb+)rrr
r2r+r<)rr4r=rrrr�_setval�s
z_Database._setvalcCsf||j|<tj|jddd��7}|j|j�|jd|jd�|f�WdQRXdS)N�arzLatin-1z%r, %r
)rrrr	rr+r*)rr%r&rrrr�_addkey�s
z_Database._addkeycCsAt|t�r!|jd�}n!t|ttf�sBtd��t|t�rc|jd�}n!t|ttf�s�td��|j�d|_||jkr�|j	||j
|��n{|j|\}}|tdt}t|�tdt}||kr'|j
||�|j|<n|j
|�|j|<dS)Nzutf-8zkeys must be bytes or stringszvalues must be bytes or stringsTr8)r0r1r#�bytes�	bytearray�	TypeErrorr.r rrAr>r;r<r?)rr%r=r4r5Z	oldblocksZ	newblocksrrr�__setitem__�s$
	z_Database.__setitem__cCsIt|t�r|jd�}|j�d|_|j|=|j�dS)Nzutf-8T)r0r1r#r.r rr-)rr%rrr�__delitem__�s
	
z_Database.__delitem__cCs9yt|j�SWn!tk
r4td�d�YnXdS)Nz"DBM object has already been closed)�listrrDr)rrrr�keys�s
z_Database.keyscs*�j��fdd��jj�D�S)Ncs g|]}|�|f�qSrr)�.0r%)rrr�
<listcomp>�s	z#_Database.items.<locals>.<listcomp>)r.rrH)rr)rrr)�s
z_Database.itemscCslt|t�r|jd�}y||jkSWn6tk
rg|jdkr`td�d�n�YnXdS)Nzutf-8z"DBM object has already been closed)r0r1r#rrDr)rr%rrr�__contains__�s
z_Database.__contains__cCs9yt|j�SWn!tk
r4td�d�YnXdS)Nz"DBM object has already been closed)�iterrrDr)rrrr�iterkeys�s
z_Database.iterkeyscCs9yt|j�SWn!tk
r4td�d�YnXdS)Nz"DBM object has already been closed)r<rrDr)rrrr�__len__s
z_Database.__len__cCs4z|j�Wdd|_|_|_|_XdS)N)r-rr
r	r)rrrrrsz_Database.closecCs,t|jd�r(|jj||j�dS)N�chmod)�hasattrrrOr)r�filerrrrsz_Database._chmodcCs|S)Nr)rrrr�	__enter__sz_Database.__enter__cGs|j�dS)N)r)r�argsrrr�__exit__sz_Database.__exit__N)�__name__�
__module__�__qualname__rrrr
rr-�syncr.r6r>r?rArErFrHr)rKrM�__iter__rNr�__del__rrRrTrrrrr#s2
	#
rri�c
CsSy tjd�}tj|�Wntk
r4YnX||@}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).

    rr)r�umask�AttributeErrorr)rQrrZumrrrrs
)�__doc__Zastr"�ior�osr�collections�__all__r;rr�MutableMappingrrrrrr�<module>s�