U e5d-@sRddlZddlZddlZddlZddgZdZ e Z Gdddej j Zd d dZdS) Nerroropenic@seZdZeZeZd+ddZddZddZdd ZeZ d d Z d d Z ddZ ddZ ddZddZddZddZddZddZddZeZd d!Zd"d#ZeZd$d%Zd&d'Zd(d)Zd*S), _DatabaseccCsL||_|dk|_|d|_|d|_|d|_d|_||||dS)Nrz.dirz.datz.bak)_mode _readonly_dirfile_datfile_bakfile_index_create_update)selfZ filebasenamemodeflagr /usr/lib64/python3.8/dbm/dumb.py__init__0s     z_Database.__init__c Cs|dkrB|j|j|jfD](}zt|Wqtk r>YqXqztj|jddd}WnHtk r|dkrrtj|jddd}||jW5QRXYn X| dS)NnrLatin-1encodingrrw) r r r _osremoveOSError_ior_chmodclose)rrfilenamefrrrr Isz_Database._createc Csd|_i|_ztj|jddd}Wn$tk rF|dkr<d|_YnFX|:|D].}|}t|\}}| d}||j|<qRW5QRXdS)NFrrrrT) _modifiedr rrr rrstrip_astZ literal_evalencode)rrr"linekeypos_and_siz_pairrrrr\s  z_Database._updatec Cs|jdks|jsdSz|j|jWntk r:YnXz|j|j|jWntk rfYnX|jj |jdddB}| |j|j D]$\}}d| d|f}| |qW5QRXdS)Nrrr%r, %r )r r#runlinkr rrenamer rrritemsdecodewrite)rr"r(r)entryrrr_commitps z_Database._commitcCs|jdkrtddSN"DBM object has already been closed)r rrrrr _verify_opens z_Database._verify_openc Cs\t|tr|d}||j|\}}t|jd}||| |}W5QRX|S)Nutf-8rb) isinstancestrr&r5r rrr seekread)rr(possizr"Zdatrrr __getitem__s   z_Database.__getitem__c Csrt|jdR}|ddt|}|tdtt}|d|||}||W5QRX|t|fS)Nrb+r) rrr r:inttell _BLOCKSIZEr/len)rvalr"r<Znposrrr_addvals  z_Database._addvalc Cs:t|jd}||||W5QRX|t|fS)Nr?)rrr r:r/rF)rr<rGr"rrr_setvals z_Database._setvalc CsP||j|<tj|jddd*}||j|d|d|fW5QRXdS)Narrr*)r rrr rr/r.)rr(r)r"rrr_addkeys  z_Database._addkeycCs|jrtdt|tr$|d}nt|ttfs:tdt|trP|d}nt|ttfsftd|d|_ ||j kr| || |n^|j |\}}|t dt }t|t dt }||kr||||j |<n| ||j |<dS)N'The database is opened for reading onlyr6zkeys must be bytes or stringszvalues must be bytes or stringsTrA)rrr8r9r&bytes bytearray TypeErrorr5r#r rKrHrErFrI)rr(rGr<r=Z oldblocksZ newblocksrrr __setitem__s(     z_Database.__setitem__cCsD|jrtdt|tr"|d}|d|_|j|=|dS)NrLr6T) rrr8r9r&r5r#r r1rr(rrr __delitem__s  z_Database.__delitem__cCs0z t|jWStk r*tddYnXdSr2)listr rOrr4rrrkeyss z_Database.keyscs fddjDS)Ncsg|]}||fqSrr).0r(r4rr sz#_Database.items..)r5r rTr4rr4rr-sz_Database.itemscCsRt|tr|d}z ||jkWStk rL|jdkrFtddnYnXdS)Nr6r3)r8r9r&r rOrrQrrr __contains__s     z_Database.__contains__cCs0z t|jWStk r*tddYnXdSr2)iterr rOrr4rrriterkeyss z_Database.iterkeyscCs0z t|jWStk r*tddYnXdSr2)rFr rOrr4rrr__len__ s z_Database.__len__c Cs,z |W5d|_|_|_|_XdSN)r r r r r1r4rrrr s z_Database.closecCs|j||jdSr[)rchmodr)rfilerrrrsz_Database._chmodcCs|Sr[rr4rrr __enter__sz_Database.__enter__cGs |dSr[)r )rargsrrr__exit__sz_Database.__exit__N)r)__name__ __module__ __qualname__rrrr rr1syncr5r>rHrIrKrPrRrTr-rWrY__iter__rZr __del__rr^r`rrrrr#s2   % rrcCsVztd}t|Wntk r,Yn X||@}|dkrHtdt|||dS)Nr)rrrrz)Flag must be one of 'r', 'w', 'c', or 'n')r)rumaskAttributeError ValueErrorr)r]rrZumrrrr"s  )rrg)Zastr%iorosrZcollections.abc collections__all__rErrabcMutableMappingrrrrrrs