Known subclasses: twisted.persisted.dirdbm.Shelf

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__
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.
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):
ParametersnameBase path to use for the directory storage. (type: str)
def _encode(self, k):

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

def _decode(self, k):

Decode a filename to get the key.

def _readFile(self, path):

Read in the contents of a file.

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

def _writeFile(self, path, data):

Write data to a file.

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

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

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):

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):

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

Parameterskkey to delete (type: bytes)
RaisesKeyErrorRaised when there is no such key
def keys(self):
Returnsa list of filenames (keys).
def values(self):
Returnsa list of file-contents (values).
def items(self):
Returnsa list of 2-tuples containing key/value pairs.
def has_key(self, key):
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):
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):
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):
See AlsoDirDBM.has_key
def update(self, dict):

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):

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):

Delete all key/value pairs in this dirdbm.

def close(self):

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

def getModificationTime(self, key):

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 at 2020-03-25 17:34:30.