class documentation

class twisted.persisted.dirdbm.DirDBM: (source)

Known subclasses: twisted.persisted.dirdbm.Shelf

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 __init__
Instance Variable dname Undocumented
Method __len__
Method __setitem__ dirdbm[k] = v Create or modify a textfile in this directory
Method __getitem__ dirdbm[k] Get the contents of a file in this directory as a string.
Method __delitem__ del dirdbm[foo] Delete a file in this directory.
Method keys
Method values
Method items
Method has_key
Method setdefault
Method get
Method __contains__
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 copyTo Copy the contents of this dirdbm to the dirdbm at path.
Method clear Delete all key/value pairs in this dirdbm.
Method close Close this dbm: no-op, for dbm-style interface compliance.
Method getModificationTime Returns modification time of an entry.
Instance Variable _dnamePath Undocumented
Method _encode Encode a key so it can be used as a filename.
Method _decode Decode a filename to get the key.
Method _readFile Read in the contents of a file.
Method _writeFile Write data to a file.
def __init__(self, name): (source)
ParametersnameBase path to use for the directory storage. (type: str)
dname = (source)

Undocumented

_dnamePath = (source)

Undocumented

def _encode(self, k): (source)

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

def _decode(self, k): (source)

Decode a filename to get the key.

def _readFile(self, path): (source)

Read in the contents of a file.

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

def _writeFile(self, path, data): (source)

Write data to a file.

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

def __len__(self): (source)
ReturnsThe number of key/value pairs in this Shelf
def __setitem__(self, k, v): (source)

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

Parameterskkey to set (type: bytes)
vvalue to associate with k (type: bytes)
def __getitem__(self, k): (source)

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

Parameterskkey to lookup (type: bytes)
ReturnsThe value associated with k
RaisesKeyErrorRaised when there is no such key
def __delitem__(self, k): (source)

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

Parameterskkey to delete (type: bytes)
RaisesKeyErrorRaised when there is no such key
def keys(self): (source)
Returnsa list of filenames (keys).
def values(self): (source)
Returnsa list of file-contents (values).
def items(self): (source)
Returnsa list of 2-tuples containing key/value pairs.
def has_key(self, key): (source)
ParameterskeyThe key to test (type: bytes)
ReturnsA true value if this dirdbm has the specified key, a false value otherwise.
def setdefault(self, key, value): (source)
ParameterskeyThe key to lookup (type: bytes)
valueThe value to associate with key if key is not already associated with a value.
def get(self, key, default=None): (source)
ParameterskeyThe key to lookup (type: bytes)
defaultThe value to return if the given key does not exist
ReturnsThe value associated with key or default if not DirDBM.has_key(key)
def __contains__(self, key): (source)
See AlsoDirDBM.has_key
def update(self, dict): (source)

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

ParametersdictA mapping of key/value pairs to add to this dirdbm. (type: mapping)
def copyTo(self, path): (source)

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

ParameterspathThe path of the dirdbm to copy to. If a dirdbm exists at the destination path, it is cleared first. (type: str)
ReturnsThe dirdbm this dirdbm was copied to. (type: DirDBM)
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 getModificationTime(self, key): (source)

Returns modification time of an entry.

ReturnsLast modification date (seconds since epoch) of entry key
RaisesKeyErrorRaised when there is no such key
API Documentation for Twisted, generated by pydoctor 20.12.1 at 2021-02-28 19:53:36.