§
    Ètºfv'  ã                   óž   — d Z ddlZddlZddlZddlZddlmZ 	 e n# e$ r e	ZY nw xY w G d„ d¦  «        Z
 G d„ de
¦  «        Zd
d„Z	g d	¢ZdS )a„  
DBM-style interface to a directory.

Each key is stored as a single file.  This is not expected to be very fast or
efficient, but it's good for easy debugging.

DirDBMs are *not* thread-safe, they should only be accessed by one thread at
a time.

No files should be placed in the working directory of a DirDBM save those
created by the DirDBM itself!

Maintainer: Itamar Shtull-Trauring
é    N)ÚFilePathc                   ó’   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zdd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚDirDBMz®
    A directory with a DBM interface.

    This class presents a hash-like interface to a directory of small,
    flat files. It can only use strings as keys or values.
    c                 ó€  — t           j                             |¦  «        | _        t	          |¦  «        | _        | j                             ¦   «         s| j                             ¦   «          dS t          j        | j         	                    d¦  «        j        ¦  «        D ]}t          j
        |¦  «         Œt          j        | j         	                    d¦  «        j        ¦  «        }|D ]U}|dd…         }t           j                             |¦  «        rt          j
        |¦  «         Œ@t          j        ||¦  «         ŒVdS )zb
        @type name: str
        @param name: Base path to use for the directory storage.
        z*.newz*.rplNéüÿÿÿ)ÚosÚpathÚabspathÚdnamer   Ú
_dnamePathÚisdirÚcreateDirectoryÚglobÚchildÚremoveÚexistsÚrename)ÚselfÚnameÚfÚreplacementsÚolds        úW/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/persisted/dirdbm.pyÚ__init__zDirDBM.__init__,   s  € õ
 ”W—_’_ TÑ*Ô*ˆŒ
Ý" 4™.œ.ˆŒØŒ×$Ò$Ñ&Ô&ð 	&ØŒO×+Ò+Ñ-Ô-Ð-Ð-Ð-õ ”Y˜tœ×4Ò4°WÑ=Ô=ÔBÑCÔCð ð �Ý”	˜!‘”��Ýœ9 T¤_×%:Ò%:¸7Ñ%CÔ%CÔ%HÑIÔIˆLØ!ð &ð &�Ø˜˜˜”f�Ý”7—>’> #Ñ&Ô&ð &Ý”I˜a‘L”L�L�Lå”I˜a Ñ%Ô%Ð%Ð%ð&ð &ó    c                 óz   — t          j        |¦  «                             dd¦  «                             dd¦  «        S )z?
        Encode a key so it can be used as a filename.
        ó   
ó   _ó   /ó   -)Úbase64ÚencodebytesÚreplace©r   Úks     r   Ú_encodezDirDBM._encodeH   s5   € õ
 Ô! !Ñ$Ô$×,Ò,¨U°DÑ9Ô9×AÒAÀ$ÈÑMÔMÐMr   c                 óz   — t          j        |                     dd¦  «                             dd¦  «        ¦  «        S )z3
        Decode a filename to get the key.
        r   r   r    r   )r!   Údecodebytesr#   r$   s     r   Ú_decodezDirDBM._decodeO   s3   € õ Ô! !§)¢)¨D°%Ñ"8Ô"8×"@Ò"@ÀÀtÑ"LÔ"LÑMÔMÐMr   c                 óˆ   — t          |j        d¦  «        5 }|                     ¦   «         }ddd¦  «         n# 1 swxY w Y   |S )z�
        Read in the contents of a file.

        Override in subclasses to e.g. provide transparently encrypted dirdbm.
        ÚrbN)Ú_openr	   Úread)r   r	   r   Úss       r   Ú	_readFilezDirDBM._readFileU   sz   € õ �4”9˜dÑ#Ô#ð 	 qØ—’‘”ˆAð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	àˆs   –7·;¾;c                 ó´   — t          |j        d¦  «        5 }|                     |¦  «         |                     ¦   «          ddd¦  «         dS # 1 swxY w Y   dS )zw
        Write data to a file.

        Override in subclasses to e.g. provide transparently encrypted dirdbm.
        ÚwbN)r,   r	   ÚwriteÚflush)r   r	   Údatar   s       r   Ú
_writeFilezDirDBM._writeFile_   s“   € õ �4”9˜dÑ#Ô#ð 	 qØ�GŠG�D‰MŒMˆMØ�GŠG‰IŒIˆIð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	ð 	ð 	s   –*AÁAÁAc                 óN   — t          | j                             ¦   «         ¦  «        S )zF
        @return: The number of key/value pairs in this Shelf
        )Úlenr   Úlistdir©r   s    r   Ú__len__zDirDBM.__len__i   s    € õ �4”?×*Ò*Ñ,Ô,Ñ-Ô-Ð-r   c                 ól  — t          |¦  «        t          k    st          d¦  «        ‚t          |¦  «        t          k    st          d¦  «        ‚|                      |¦  «        }| j                             |¦  «        }|                     ¦   «         r|                     d¦  «        }n|                     d¦  «        }	 |                      ||¦  «         |                     ¦   «         r| 	                    ¦   «          | 
                    |¦  «         dS # t          $ r | 	                    ¦   «          ‚ w xY w)zÔ
        C{dirdbm[k] = v}
        Create or modify a textfile in this directory

        @type k: bytes
        @param k: key to set

        @type v: bytes
        @param v: value to associate with C{k}
        úDirDBM key must be byteszDirDBM value must be bytesz.rplz.newN)ÚtypeÚbytesÚ	TypeErrorr&   r   r   r   ÚsiblingExtensionr5   r   ÚmoveToÚBaseException)r   r%   Úvr   Únews        r   Ú__setitem__zDirDBM.__setitem__o   s  € õ �A‰wŒw�%ÒÐÝÐ6Ñ7Ô7Ð7Ý�A‰wŒw�%ÒÐÝÐ8Ñ9Ô9Ð9Ø�LŠL˜‰OŒOˆð Œo×#Ò# AÑ&Ô&ˆØ�:Š:‰<Œ<ð 	/Ø×&Ò& vÑ.Ô.ˆCˆCà×&Ò& vÑ.Ô.ˆCð	Ø�OŠO˜C Ñ#Ô#Ð#ð
 �zŠz‰|Œ|ð Ø—
’
‘”�Ø�JŠJ�s‰OŒOˆOˆOˆOøõ ð 	ð 	ð 	Ø�JŠJ‰LŒLˆLØð	øøøs   Â>D Ä D3c                 ó  — t          |¦  «        t          k    st          d¦  «        ‚| j                             |                      |¦  «        ¦  «        }	 |                      |¦  «        S # t          $ r t          |¦  «        ‚w xY w)a  
        C{dirdbm[k]}
        Get the contents of a file in this directory as a string.

        @type k: bytes
        @param k: key to lookup

        @return: The value associated with C{k}
        @raise KeyError: Raised when there is no such key
        r<   )	r=   r>   r?   r   r   r&   r/   ÚOSErrorÚKeyError)r   r%   r	   s      r   Ú__getitem__zDirDBM.__getitem__‘   s�   € õ �A‰wŒw�%ÒÐÝÐ6Ñ7Ô7Ð7ØŒ×$Ò$ T§\¢\°!¡_¤_Ñ5Ô5ˆð	Ø—>’> $Ñ'Ô'Ð'øÝð 	ð 	ð 	Ý˜1‘+”+Ðð	øøøs   ÁA+ Á+Bc                 ó8  — t          |¦  «        t          k    st          d¦  «        ‚|                      |¦  «        }	 | j                             |¦  «                             ¦   «          dS # t          $ r# t          |  	                    |¦  «        ¦  «        ‚w xY w)zÀ
        C{del dirdbm[foo]}
        Delete a file in this directory.

        @type k: bytes
        @param k: key to delete

        @raise KeyError: Raised when there is no such key
        r<   N)
r=   r>   r?   r&   r   r   r   rG   rH   r)   r$   s     r   Ú__delitem__zDirDBM.__delitem__¤   s“   € õ �A‰wŒw�%ÒÐÝÐ6Ñ7Ô7Ð7Ø�LŠL˜‰OŒOˆð	,ØŒO×!Ò! !Ñ$Ô$×+Ò+Ñ-Ô-Ð-Ð-Ð-øÝð 	,ð 	,ð 	,Ý˜4Ÿ<š<¨™?œ?Ñ+Ô+Ð+ð	,øøøs   ¾,A, Á,-Bc                 ó˜   — t          t          | j        | j                             ¦   «                              ¦   «         ¦  «        ¦  «        S )z9
        @return: a L{list} of filenames (keys).
        )ÚlistÚmapr)   r   ÚasBytesModer8   r9   s    r   ÚkeyszDirDBM.keys¶   s8   € õ •C˜œ d¤o×&AÒ&AÑ&CÔ&C×&KÒ&KÑ&MÔ&MÑNÔNÑOÔOÐOr   c                 ór   — g }|                       ¦   «         }|D ]}|                     | |         ¦  «         Œ|S )z?
        @return: a L{list} of file-contents (values).
        ©rP   Úappend)r   ÚvalsrP   Úkeys       r   ÚvalueszDirDBM.values¼   sC   € ð ˆØ�yŠy‰{Œ{ˆØð 	#ð 	#ˆCØ�KŠK˜˜Sœ	Ñ"Ô"Ð"Ð"Øˆr   c                 óv   — g }|                       ¦   «         }|D ]}|                     || |         f¦  «         Œ |S )zL
        @return: a L{list} of 2-tuples containing key/value pairs.
        rR   )r   ÚitemsrP   rU   s       r   rX   zDirDBM.itemsÆ   sH   € ð ˆØ�yŠy‰{Œ{ˆØð 	+ð 	+ˆCØ�LŠL˜#˜t CœyÐ)Ñ*Ô*Ð*Ð*Øˆr   c                 óÒ   — t          |¦  «        t          k    st          d¦  «        ‚|                      |¦  «        }| j                             |¦  «                             ¦   «         S )z¬
        @type key: bytes
        @param key: The key to test

        @return: A true value if this dirdbm has the specified key, a false
        value otherwise.
        r<   )r=   r>   r?   r&   r   r   Úisfile©r   rU   s     r   Úhas_keyzDirDBM.has_keyÐ   sW   € õ �C‰yŒy�EÒ!Ð!ÝÐ6Ñ7Ô7Ð7Ø�lŠl˜3ÑÔˆØŒ×$Ò$ SÑ)Ô)×0Ò0Ñ2Ô2Ð2r   c                 ó(   — || vr|| |<   |S | |         S )z¶
        @type key: bytes
        @param key: The key to lookup

        @param value: The value to associate with key if key is not already
        associated with a value.
        © )r   rU   Úvalues      r   Ú
setdefaultzDirDBM.setdefaultÝ   s%   € ð �dˆ?ˆ?ØˆD�‰IØˆLØ�CŒyÐr   Nc                 ó   — || v r| |         S |S )zü
        @type key: bytes
        @param key: The key to lookup

        @param default: The value to return if the given key does not exist

        @return: The value associated with C{key} or C{default} if not
        L{DirDBM.has_key(key)}
        r^   )r   rU   Údefaults      r   Úgetz
DirDBM.getê   s   € ð �$ˆ;ˆ;Ø˜”9ÐàˆNr   c                 ó,   — |                       |¦  «        S )z)
        @see: L{DirDBM.has_key}
        )r\   r[   s     r   Ú__contains__zDirDBM.__contains__ù   s   € ð �|Š|˜CÑ Ô Ð r   c                 óD   — |                      ¦   «         D ]
\  }}|| |<   ŒdS )zþ
        Add all the key/value pairs in L{dict} to this dirdbm.  Any conflicting
        keys will be overwritten with the values from L{dict}.

        @type dict: mapping
        @param dict: A mapping of key/value pairs to add to this dirdbm.
        N)rX   )r   ÚdictrU   Úvals       r   ÚupdatezDirDBM.updateÿ   s4   € ð Ÿ
š
™œð 	ð 	‰HˆC�ØˆD�‰IˆIð	ð 	r   c                 óÞ   — t          |¦  «        }|| j        k    sJ ‚|                      |j        ¦  «        }|                     ¦   «          |                      ¦   «         D ]}| |         ||<   Œ|S )a<  
        Copy the contents of this dirdbm to the dirdbm at C{path}.

        @type path: L{str}
        @param path: The path of the dirdbm to copy to.  If a dirdbm
        exists at the destination path, it is cleared first.

        @rtype: C{DirDBM}
        @return: The dirdbm this dirdbm was copied to.
        )r   r   Ú	__class__r	   ÚclearrP   )r   r	   Údr%   s       r   ÚcopyTozDirDBM.copyTo
  sm   € õ ˜‰~Œ~ˆØ�t”Ò&Ð&Ð&Ð&à�NŠN˜4œ9Ñ%Ô%ˆØ	�Š‰	Œ	ˆ	Ø—’‘”ð 	ð 	ˆAØ˜”7ˆAˆa‰DˆDØˆr   c                 ó:   — |                       ¦   «         D ]}| |= ŒdS )z<
        Delete all key/value pairs in this dirdbm.
        N)rP   r$   s     r   rl   zDirDBM.clear  s.   € ð —’‘”ð 	ð 	ˆAØ�Q��ð	ð 	r   c                 ó   — dS )zL
        Close this dbm: no-op, for dbm-style interface compliance.
        Nr^   r9   s    r   ÚclosezDirDBM.close%  s   € € € r   c                 ó  — t          |¦  «        t          k    st          d¦  «        ‚| j                             |                      |¦  «        ¦  «        }|                     ¦   «         r|                     ¦   «         S t          |¦  «        ‚)zÁ
        Returns modification time of an entry.

        @return: Last modification date (seconds since epoch) of entry C{key}
        @raise KeyError: Raised when there is no such key
        r<   )	r=   r>   r?   r   r   r&   rZ   ÚgetModificationTimerH   )r   rU   r	   s      r   rs   zDirDBM.getModificationTime*  ss   € õ �C‰yŒy�EÒ!Ð!ÝÐ6Ñ7Ô7Ð7ØŒ×$Ò$ T§\¢\°#Ñ%6Ô%6Ñ7Ô7ˆØ�;Š;‰=Œ=ð 	 Ø×+Ò+Ñ-Ô-Ð-å˜3‘-”-Ðr   )N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r&   r)   r/   r5   r:   rE   rI   rK   rP   rV   rX   r\   r`   rc   re   ri   rn   rl   rq   rs   r^   r   r   r   r   $   sh  € € € € € ðð ð&ð &ð &ð8Nð Nð NðNð Nð Nðð ð ðð ð ð.ð .ð .ð ð  ð  ðDð ð ð&,ð ,ð ,ð$Pð Pð Pðð ð ðð ð ð3ð 3ð 3ðð ð ðð ð ð ð!ð !ð !ð	ð 	ð 	ðð ð ð(ð ð ðð ð ð
 ð  ð  ð  ð  r   r   c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚShelfzÃ
    A directory with a DBM shelf interface.

    This class presents a hash-like interface to a directory of small,
    flat files. Keys must be strings, but values can be any given object.
    c                 óf   — t          j        |¦  «        }t                               | ||¦  «         dS )zÉ
        C{shelf[foo] = bar}
        Create or modify a textfile in this directory.

        @type k: str
        @param k: The key to set

        @param v: The value to associate with C{key}
        N)ÚpickleÚdumpsr   rE   )r   r%   rC   s      r   rE   zShelf.__setitem__B  s/   € õ ŒL˜‰OŒOˆÝ×Ò˜4  AÑ&Ô&Ð&Ð&Ð&r   c                 ó\   — t          j        t                               | |¦  «        ¦  «        S )a  
        C{dirdbm[foo]}
        Get and unpickle the contents of a file in this directory.

        @type k: bytes
        @param k: The key to lookup

        @return: The value associated with the given key
        @raise KeyError: Raised if the given key does not exist
        )r{   Úloadsr   rI   r$   s     r   rI   zShelf.__getitem__O  s$   € õ Œ|�F×.Ò.¨t°QÑ7Ô7Ñ8Ô8Ð8r   N)rt   ru   rv   rw   rE   rI   r^   r   r   ry   ry   :  s<   € € € € € ðð ð'ð 'ð 'ð9ð 9ð 9ð 9ð 9r   ry   c                 ó    — t          | ¦  «        S )z£
    This is for 'anydbm' compatibility.

    @param file: The parameter to pass to the DirDBM constructor.

    @param flag: ignored
    @param mode: ignored
    )r   )ÚfileÚflagÚmodes      r   Úopenrƒ   ]  s   € õ �$‰<Œ<Ðr   )rƒ   r   ry   )NN)rw   r!   r   r   r{   Útwisted.python.filepathr   r,   Ú	NameErrorrƒ   r   ry   Ú__all__r^   r   r   ú<module>r‡      sø   ððð ð  €€€Ø €€€Ø 	€	€	€	Ø €€€à ,Ð ,Ð ,Ð ,Ð ,Ð ,ðØ	€E€EøØð ð ð Ø€E€E€EðøøøðS ð S ð S ð S ð S ñ S ô S ð S ðl 9ð  9ð  9ð  9ð  9ˆFñ  9ô  9ð  9ðF	ð 	ð 	ð 	ð &Ð
%Ð
%€€€s   š �'¦'