Package twisted :: Package persisted :: Module dirdbm :: Class DirDBM

[frames | no frames]

## Class DirDBM

Known Subclasses:
  `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 Summary
| ``__init__`(self, name)`
| ``__contains__`(self, key)` `key in dirdbm`
| ``__delitem__`(self, k)` `del dirdbm[foo]` Delete a file in this directory.
| ``__getitem__`(self, k)` `dirdbm[k]` Get the contents of a file in this directory as a string.
| ``__len__`(self)` Return the number of key/value pairs in this Shelf
| ``__setitem__`(self, k, v)` `dirdbm[k] = v` Create or modify a textfile in this directory
| ``_decode`(self, k)` Decode a filename to get the key.
| ``_encode`(self, k)` Encode a key so it can be used as a filename.
| ``_readFile`(self, path)` Read in the contents of a file.
| ``_writeFile`(self, path, data)` Write data to a file.
| ``clear`(self)` Delete all key/value pairs in this dirdbm.
| ``close`(self)` Close this dbm: no-op, for dbm-style interface compliance.
`DirDBM` | ``copyTo`(self, path)` Copy the contents of this dirdbm to the dirdbm at `path`.
| ``get`(self, key, default)` Return the value associated with `key` or `default` if not `self.has_key(key)`
| ``getModificationTime`(self, key)` Returns modification time of an entry.
| ``has_key`(self, key)` Return a true value if this dirdbm has the specified key, a faluse value otherwise.
| ``items`(self)` Return a `list` of 2-tuples containing key/value pairs.
| ``keys`(self)` Return a `list` of filenames (keys).
| ``setdefault`(self, key, value)`
| ``update`(self, dict)` Add all the key/value pairs in `dict` to this dirdbm.
| ``values`(self)` Return a `list` of file-contents (values).

Method Details

### __init__(self, name)
(Constructor)

  Parameters:
    `name` - Base path to use for the directory storage.
    (type=str)

### __contains__(self, key)
(In operator)

`key in dirdbm`

  Parameters:
    `key` - The key to test
    (type=str)
  Returns:
    A true value if `self.has_key(key)`, a false value otherwise.

### __delitem__(self, k)
(Index deletion operator)

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

  Parameters:
    `k` - key to delete
    (type=str)
  Raises:
    `KeyError` - Raised when there is no such key

### __getitem__(self, k)
(Indexing operator)

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

  Parameters:
    `k` - key to lookup
    (type=str)
  Returns:
    The value associated with `k`
  Raises:
    `KeyError` - Raised when there is no such key

### __len__(self)
(Length operator)

  Returns:
    The number of key/value pairs in this Shelf

### __setitem__(self, k, v)
(Index assignment operator)

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

  Parameters:
    `k` - key to set
    (type=str)
    `v` - value to associate with `k`
    (type=str)

### _decode(self, k)

Decode a filename to get the key.

### _encode(self, k)

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

### _readFile(self, path)

Read in the contents of a file.

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

### _writeFile(self, path, data)

Write data to a file.

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

### clear(self)

Delete all key/value pairs in this dirdbm.

### close(self)

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

### copyTo(self, path)

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

  Parameters:
    `path` - The path of the dirdbm to copy to. If a dirdbm exists at the destination path, it is cleared first.
    (type=`str`)
  Returns:
    The dirdbm this dirdbm was copied to.
    (type=`DirDBM`)

### get(self, key, default=None)

  Parameters:
    `key` - The key to lookup
    (type=str)
    `default` - The value to return if the given key does not exist
  Returns:
    The value associated with `key` or `default` if not `self.has_key(key)`

### getModificationTime(self, key)

Returns modification time of an entry.

  Returns:
    Last modification date (seconds since epoch) of entry `key`
  Raises:
    `KeyError` - Raised when there is no such key

### has_key(self, key)

  Parameters:
    `key` - The key to test
    (type=str)
  Returns:
    A true value if this dirdbm has the specified key, a faluse value otherwise.

### items(self)

  Returns:
    a `list` of 2-tuples containing key/value pairs.

### keys(self)

  Returns:
    a `list` of filenames (keys).

### setdefault(self, key, value)

  Parameters:
    `key` - The key to lookup
    (type=str)
    `value` - The value to associate with key if key is not already associated with a value.

### 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`.

  Parameters:
    `dict` - A mapping of key/value pairs to add to this dirdbm.
    (type=mapping)

### values(self)

  Returns:
    a `list` of file-contents (values).

Generated by Epydoc 2.0 on Sat May 15 20:08:46 2004 | http://epydoc.sf.net