Plan 9 from Bell Labs’s /usr/web/sources/contrib/stallion/root/sys/lib/python2.7/dumbdbm.pyo

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


�`^c@skdZddlZddlZddlZejZdZeZ	dej
fd��YZddd�ZdS(s�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')

i�Nit	_DatabasecBs�eZeZeZd�Zd�Zd�ZeZd�Zd�Z	d�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�ZeZd
�Zd�ZeZd�ZRS(cCs�||_|tjd|_|tjd|_|tjd|_d|_yt|jd�}Wn<t	k
r�t|jd��}|j
|j�WdQXnX|j�|j�dS(Ntdirtdattbaktrtw(
t_modet_ostextsept_dirfilet_datfilet_bakfiletNonet_indext_opentIOErrort_chmodtcloset_update(tselftfilebasenametmodetf((s/sys/lib/python2.7/dumbdbm.pyt__init__/s		

cCs}i|_yt|j�}Wntk
r/nJX|�x9|D]1}|j�}t|�\}}||j|<q>WWdQXdS(N(R
RR	Rtrstripteval(RRtlinetkeytpos_and_siz_pair((s/sys/lib/python2.7/dumbdbm.pyRNs	

c	Cs�|jdkrdSy|jj|j�Wn|jjk
rCnXy|jj|j|j�Wn|jjk
rznX|j|jd��}|j	|j�x4|jj
�D]#\}}|jd||f�q�WWdQXdS(NRs%r, %r
(R
RRtunlinkRterrortrenameR	RRt	iteritemstwrite(RRRR((s/sys/lib/python2.7/dumbdbm.pyt_commit^scCsN|j|\}}t|jd��}|j|�|j|�}WdQX|S(Ntrb(R
RR
tseektread(RRtpostsizRR((s/sys/lib/python2.7/dumbdbm.pyt__getitem__vs

cCs�t|jd��}|jdd�t|j��}|tdtt}|jd||�|}|j|�WdQX|t|�fS(Nsrb+iiit(RR
R$tintttellt
_BLOCKSIZER!tlen(RtvalRR&tnpos((s/sys/lib/python2.7/dumbdbm.pyt_addval�scCsEt|jd��}|j|�|j|�WdQX|t|�fS(Nsrb+(RR
R$R!R-(RR&R.R((s/sys/lib/python2.7/dumbdbm.pyt_setval�s
cCsS||j|<t|jd��}|j|j�|jd||f�WdQXdS(Ntas%r, %r
(R
RR	RR!(RRRR((s/sys/lib/python2.7/dumbdbm.pyt_addkey�s
cCs�t|�td�ko)t|�kns:td�n||jkre|j||j|��n{|j|\}}|tdt}t|�tdt}||kr�|j||�|j|<n|j|�|j|<dS(Ntskeys and values must be stringsi(ttypet	TypeErrorR
R3R0R,R-R1(RRR.R&R't	oldblockst	newblocks((s/sys/lib/python2.7/dumbdbm.pyt__setitem__�s.cCs|j|=|j�dS(N(R
R"(RR((s/sys/lib/python2.7/dumbdbm.pyt__delitem__�s
cCs
|jj�S(N(R
tkeys(R((s/sys/lib/python2.7/dumbdbm.pyR;�scCs
||jkS(N(R
(RR((s/sys/lib/python2.7/dumbdbm.pythas_key�scCs
||jkS(N(R
(RR((s/sys/lib/python2.7/dumbdbm.pyt__contains__�scCs
|jj�S(N(R
titerkeys(R((s/sys/lib/python2.7/dumbdbm.pyR>�scCs
t|j�S(N(R-R
(R((s/sys/lib/python2.7/dumbdbm.pyt__len__�scCs,|j�d|_|_|_|_dS(N(R"RR
R
R	R(R((s/sys/lib/python2.7/dumbdbm.pyR�s
cCs/t|jd�r+|jj||j�ndS(Ntchmod(thasattrRR@R(Rtfile((s/sys/lib/python2.7/dumbdbm.pyR�s(t__name__t
__module__RRRRR"tsyncR(R0R1R3R9R:R;R<R=R>t__iter__R?Rt__del__R(((s/sys/lib/python2.7/dumbdbm.pyR"s*
																	i�cCsLy tjd�}tj|�Wntk
r3nX||@}t||�S(s�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 dumbdbm 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 0666 (and
    will be modified by the prevailing umask).

    i(RtumasktAttributeErrorR(RBtflagRtum((s/sys/lib/python2.7/dumbdbm.pytopen�s
(
t__doc__tosRt__builtin__tUserDictRLRR,RRt	DictMixinRR(((s/sys/lib/python2.7/dumbdbm.pyt<module>s	

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to [email protected].