HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/persisted/__pycache__/dirdbm.cpython-38.pyc
U

��W[�'�@s�dZddlZddlZddlZzddlZWnek
rDddlZYnXddlmZze	Wne
k
rreZ	YnXGdd�d�ZGdd�de�Z
d
dd	�Zd	ddgZdS)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@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd-dd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�ZdS).�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.
    cCs�tj�|�|_t|�|_|j��s.|j��nrt�|j�	d�j�D]}t�
|�qBt�|j�	d�j�}|D]4}|dd�}tj�|�r�t�
|�qjt�||�qjdS)zb
        @type name: str
        @param name: Base path to use for the directory storage.
        z*.newz*.rplN���)
�os�path�abspathZdnamer�
_dnamePath�isdirZcreateDirectory�glob�child�remove�exists�rename)�self�name�fZreplacements�old�r�:/usr/lib/python3/dist-packages/twisted/persisted/dirdbm.py�__init__2s


zDirDBM.__init__cCst�|��dd��dd�S)z?
        Encode a key so it can be used as a filename.
        �
�_�/�-)�base64Zencodestring�replace�r�krrr�_encodeOszDirDBM._encodecCst�|�dd��dd��S)z3
        Decode a filename to get the key.
        rrrr)rZdecodestringrrrrr�_decodeWszDirDBM._decodec	Cs$t|jd��}|��}W5QRX|S)z�
        Read in the contents of a file.

        Override in subclasses to e.g. provide transparently encrypted dirdbm.
        �rb)�_openr�read)rrr�srrr�	_readFile^szDirDBM._readFilec	Cs.t|jd��}|�|�|��W5QRXdS)zw
        Write data to a file.

        Override in subclasses to e.g. provide transparently encrypted dirdbm.
        �wbN)r!r�write�flush)rr�datarrrr�
_writeFileis
zDirDBM._writeFilecCst|j���S)zF
        @return: The number of key/value pairs in this Shelf
        )�lenr�listdir�rrrr�__len__tszDirDBM.__len__cCs�t|�tkstd��t|�tks(td��|�|�}|j�|�}|��rR|�d�}n
|�d�}z|�||�Wn|�	��YnX|��r�|�	�|�
|�dS)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 byteszDirDBM value must be bytesz.rplz.newN)�type�bytes�	TypeErrorrrrr
ZsiblingExtensionr)rZmoveTo)rr�vr�newrrr�__setitem__{s"

zDirDBM.__setitem__cCsTt|�tkstd��|j�|�|��}z|�|�WStk
rNt|��YnXdS)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.N)	r/r0r1rrrr$�EnvironmentError�KeyError)rrrrrr�__getitem__�szDirDBM.__getitem__cCsZt|�tkstd��|�|�}z|j�|���Wn"tk
rTt|�	|���YnXdS)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/r0r1rrrrr5r6rrrrr�__delitem__�s

zDirDBM.__delitem__cCstt|j|j������S)z9
        @return: a L{list} of filenames (keys).
        )�list�maprrZasBytesModer+r,rrr�keys�szDirDBM.keyscCs(g}|��}|D]}|�||�q|S)z?
        @return: a L{list} of file-contents (values).
        �r;�append)rZvalsr;�keyrrr�values�s
z
DirDBM.valuescCs,g}|��}|D]}|�|||f�q|S)zL
        @return: a L{list} of 2-tuples containing key/value pairs.
        r<)r�itemsr;r>rrrr@�s
zDirDBM.itemscCs.t|�tkstd��|�|�}|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/r0r1rrr�isfile�rr>rrr�has_key�s
zDirDBM.has_keycCs||kr|||<|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)rr>�valuerrr�
setdefault�szDirDBM.setdefaultNcCs||kr||S|SdS)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)}
        Nr)rr>�defaultrrr�get�s
z
DirDBM.getcCs
|�|�S)z)
        @see: L{DirDBM.has_key}
        )rCrBrrr�__contains__
szDirDBM.__contains__cCs|��D]\}}|||<qdS)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)r@)r�dictr>�valrrr�updatesz
DirDBM.updatecCsHt|�}||jkst�|�|j�}|��|��D]}||||<q2|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.
        )rr�AssertionError�	__class__r�clearr;)rr�drrrr�copyTo sz
DirDBM.copyTocCs|��D]
}||=qdS)z<
        Delete all key/value pairs in this dirdbm.
        N)r;rrrrrN5szDirDBM.clearcCsdS)zL
        Close this dbm: no-op, for dbm-style interface compliance.
        Nrr,rrr�close=szDirDBM.closecCsBt|�tkstd��|j�|�|��}|��r6|��St|��dS)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.N)	r/r0r1rrrrA�getModificationTimer6)rr>rrrrrRCszDirDBM.getModificationTime)N)�__name__�
__module__�__qualname__�__doc__rrrr$r)r-r4r7r8r;r?r@rCrErGrHrKrPrNrQrRrrrrr*s,"
rc@s eZdZdZdd�Zdd�ZdS)�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.
    cCst�|�}t�|||�dS)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�dumpsrr4)rrr2rrrr4\s

zShelf.__setitem__cCst�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
        )rX�loadsrr7rrrrr7jszShelf.__getitem__N)rSrTrUrVr4r7rrrrrWTsrWcCst|�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�moderrr�openys	r^)NN)rVrrr
ZcPicklerX�ImportErrorZtwisted.python.filepathrr!�	NameErrorr^rrW�__all__rrrr�<module>s$
,%