grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026 ü“qc–+ã@s}dZddlZddlZddlZddlZddgZdZ e Z Gdd„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 „Z dd„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ƒWdQRXYn X|j ƒdS)NÚnrÚencodingzLatin-1Úw) r r r Ú_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|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__c Cs9yt|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ú îs z#_Database.items..)r.r rH)rr)rrr)ìs z_Database.itemsc Cslt|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__c Cs9yt|jƒSWn!tk r4tdƒd‚YnXdS)Nz"DBM object has already been closed)Úiterr rDr)rrrrÚiterkeysûs z_Database.iterkeysc Cs9yt|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Ús     ø