AlkantarClanX12

Your IP : 18.118.162.8


Current Path : /opt/alt/python34/lib64/python3.4/dbm/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/dbm/__pycache__/dumb.cpython-34.pyc

�
i fq)�@s}dZddlZddlZddlZddlZddgZdZ	e
ZGdd�dej�Z
ddd	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@seZdZeZeZdd�Zdd�Zdd�ZeZdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�ZeZdd�Zdd �ZeZd!d"�Zd#d$�Zd%d&�Zd'S)(�	_DatabasecCs�||_|d|_|d|_|d|_d|_ytj|jddd�}WnFtk
r�tj|jddd��}|j|j�WdQXYnX|j	�|j
�dS)Nz.dirz.datz.bak�r�encodingzLatin-1�w)�_mode�_dirfile�_datfile�_bakfile�_index�_ior�OSError�_chmod�close�_update)�selfZfilebasename�mode�f�r�-/opt/alt/python34/lib64/python3.4/dbm/dumb.py�__init__0s	


	

z_Database.__init__cCs�i|_ytj|jddd�}Wntk
r<Yn\X|�SxK|D]C}|j�}tj|�\}}|jd�}||j|<qKWWdQXdS)NrrzLatin-1)	rr
rr	r�rstrip�_astZliteral_eval�encode)rr�line�key�pos_and_siz_pairrrrrOs	

z_Database._updatecCs�|jdkrdSy|jj|j�Wntk
r>YnXy|jj|j|j�Wntk
rpYnX|jj|jddd��]}|j	|j�xC|jj
�D]2\}}d|jd�|f}|j|�q�WWdQXdS)NrrzLatin-1z%r, %r
)
r�_os�unlinkrr�renamer	r
rr�items�decode�write)rrrr�entryrrr�_commit`s

!z_Database._commitcCs"|jdkrtd��ndS)Nz"DBM object has already been closed)rr)rrrr�_verify_open{sz_Database._verify_openc	Cs|t|t�r!|jd�}n|j�|j|\}}tj|jd��#}|j|�|j	|�}WdQX|S)Nzutf-8�rb)
�
isinstance�strrr&rr
rr
�seek�read)rr�pos�sizrZdatrrr�__getitem__s

z_Database.__getitem__cCs�tj|jd��g}|jdd�t|j��}|tdtt}|jd||�|}|j|�WdQX|t|�fS)Nzrb+r��s)	r
rr
r*�int�tell�
_BLOCKSIZEr#�len)r�valrr,Znposrrr�_addval�sz_Database._addvalc	CsHtj|jd��!}|j|�|j|�WdQX|t|�fS)Nzrb+)r
rr
r*r#r4)rr,r5rrrr�_setval�s
z_Database._setvalcCse||j|<tj|jddd��7}|j|j�|jd|jd�|f�WdQXdS)N�arzLatin-1z%r, %r
)rr
rr	rr#r")rrrrrrr�_addkey�s
z_Database._addkeycCs>t|t�r!|jd�}n$t|ttf�sEtd��nt|t�rf|jd�}n$t|ttf�s�td��n|j�||jkr�|j||j	|��n{|j|\}}|t
dt
}t|�t
dt
}||kr$|j||�|j|<n|j	|�|j|<dS)Nzutf-8zkeys must be bytes or stringszvalues must be bytes or stringsr0)
r(r)r�bytes�	bytearray�	TypeErrorr&rr9r6r3r4r7)rrr5r,r-Z	oldblocksZ	newblocksrrr�__setitem__�s"
z_Database.__setitem__cCsCt|t�r!|jd�}n|j�|j|=|j�dS)Nzutf-8)r(r)rr&rr%)rrrrr�__delitem__�s


z_Database.__delitem__cCs9yt|j�SWn!tk
r4td�d�YnXdS)Nz"DBM object has already been closed)�listrr<r)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r@)rr)rrr!�s
z_Database.itemscCsot|t�r!|jd�}ny||jkSWn6tk
rj|jdkrctd�d�n�YnXdS)Nzutf-8z"DBM object has already been closed)r(r)rrr<r)rrrrr�__contains__�s
z_Database.__contains__cCs9yt|j�SWn!tk
r4td�d�YnXdS)Nz"DBM object has already been closed)�iterrr<r)rrrr�iterkeys�s
z_Database.iterkeyscCs9yt|j�SWn!tk
r4td�d�YnXdS)Nz"DBM object has already been closed)r4rr<r)rrrr�__len__�s
z_Database.__len__cCs4z|j�Wdd|_|_|_|_XdS)N)r%rr
r	r)rrrrr�sz_Database.closecCs/t|jd�r+|jj||j�ndS)N�chmod)�hasattrrrGr)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__rr
rrr%�syncr&r.r6r7r9r=r>r@r!rCrE�__iter__rFr�__del__rrJrLrrrrr#s0
	"ri�cCsMy tjd�}tj|�Wntk
r4YnX||@}t||�S)a�Open the database file, filename, and return corresponding object.

    The flag argument, used to control how the database is opened in the
    other DBM implementations, is ignored in the dbm.dumb module; the
    database is 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)r�umask�AttributeErrorr)rIZflagrZumrrrr
s
)�__doc__Zastr�ior
�osr�collections�__all__r3rr�MutableMappingrrrrrr�<module>s�