class documentation

class DirDBM: (source)

Known subclasses: twisted.persisted.dirdbm.Shelf

Constructor: DirDBM(name)

View In Hierarchy

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.

Method __contains__ No summary
Method __delitem__ del dirdbm[foo] Delete a file in this directory.
Method __getitem__ dirdbm[k] Get the contents of a file in this directory as a string.
Method __init__ No summary
Method __len__ No summary
Method __setitem__ dirdbm[k] = v Create or modify a textfile in this directory
Method clear Delete all key/value pairs in this dirdbm.
Method close Close this dbm: no-op, for dbm-style interface compliance.
Method copyTo Copy the contents of this dirdbm to the dirdbm at path.
Method get No summary
Method getModificationTime Returns modification time of an entry.
Method has_key No summary
Method items No summary
Method keys No summary
Method setdefault No summary
Method update Add all the key/value pairs in dict to this dirdbm. Any conflicting keys will be overwritten with the values from dict.
Method values No summary
Instance Variable dname Undocumented
Method _decode Decode a filename to get the key.
Method _encode Encode a key so it can be used as a filename.
Method _readFile Read in the contents of a file.
Method _writeFile Write data to a file.
Instance Variable _dnamePath Undocumented
def __contains__(self, key: bytes) -> bool: (source)
def __delitem__(self, k: bytes): (source)

del dirdbm[foo] Delete a file in this directory.

Parameters
k:byteskey to delete
Raises
KeyErrorRaised when there is no such key
def __getitem__(self, k: bytes) -> bytes: (source)

dirdbm[k] Get the contents of a file in this directory as a string.

Parameters
k:byteskey to lookup
Returns
bytesThe value associated with k
Raises
KeyErrorRaised when there is no such key
def __init__(self, name: bytes): (source)
Parameters
name:bytesBase path to use for the directory storage.
def __len__(self) -> int: (source)
Returns
intThe number of key/value pairs in this Shelf
def __setitem__(self, k: bytes, v: bytes): (source)

dirdbm[k] = v Create or modify a textfile in this directory

Parameters
k:byteskey to set
v:bytesvalue to associate with k
def clear(self): (source)

Delete all key/value pairs in this dirdbm.

def close(self): (source)

Close this dbm: no-op, for dbm-style interface compliance.

def copyTo(self, path: bytes) -> DirDBM: (source)

Copy the contents of this dirdbm to the dirdbm at path.

Parameters
path:bytesThe path of the dirdbm to copy to. If a dirdbm exists at the destination path, it is cleared first.
Returns
DirDBMThe dirdbm this dirdbm was copied to.
@overload
def get(self, key: bytes) -> bytes:
@overload
def get(self, key: bytes, default: _T) -> bytes | _T:
(source)
Parameters
key:bytesThe key to lookup
default:_T | NoneThe value to return if the given key does not exist
Returns
bytes | _T | NoneThe value associated with key or default if not DirDBM.has_key(key)
def getModificationTime(self, key: bytes) -> float: (source)

Returns modification time of an entry.

Returns
floatLast modification date (seconds since epoch) of entry key
Raises
KeyErrorRaised when there is no such key
def has_key(self, key: bytes) -> bool: (source)
Parameters
key:bytesThe key to test
Returns
boolA true value if this dirdbm has the specified key, a false value otherwise.
def items(self) -> Iterable[tuple[bytes, bytes]]: (source)
Returns
Iterable[tuple[bytes, bytes]]a list of 2-tuples containing key/value pairs.
def keys(self) -> Iterable[bytes]: (source)
Returns
Iterable[bytes]a list of filenames (keys).
def setdefault(self, key: bytes, value: bytes) -> bytes: (source)
Parameters
key:bytesThe key to lookup
value:bytesThe value to associate with key if key is not already associated with a value.
Returns
bytesUndocumented
def update(self, other: Mapping[bytes, bytes]): (source)

Add all the key/value pairs in dict to this dirdbm. Any conflicting keys will be overwritten with the values from dict.

Parameters
other:Mapping[bytes, bytes]Undocumented
dictA mapping of key/value pairs to add to this dirdbm.
def values(self) -> Iterable[bytes]: (source)
Returns
Iterable[bytes]a list of file-contents (values).

Undocumented

def _decode(self, k: bytes) -> bytes: (source)

Decode a filename to get the key.

def _encode(self, k: bytes) -> bytes: (source)

Encode a key so it can be used as a filename.

def _readFile(self, path: FilePath[AnyStr]) -> bytes: (source)

Read in the contents of a file.

Override in subclasses to e.g. provide transparently encrypted dirdbm.

def _writeFile(self, path: FilePath[AnyStr], data: bytes): (source)

Write data to a file.

Override in subclasses to e.g. provide transparently encrypted dirdbm.

_dnamePath = (source)

Undocumented