Package lemon :: Package external :: Module dtuple :: Class DatabaseTuple
[show private | hide private]
[frames | no frames]

Class DatabaseTuple


Wraps the return data from a DB-API fetch*() method.

Instances of this class are used to represent tuples of information,
typically returned by a database query. A TupleDescriptor is used as
a means of describing the information for a variety of access methods.
The tuple's information can be accessed via simple indexing, slices,
as a mapping where the keys are the column names (as defined by the
descriptor), or via attribute-based access (where the attribute names
are equivalent to the column names).

This object acts as a tuple, a list, a mapping, and an instance. To
retrieve "pure" tuples, lists, or mappings, the asTuple(), asList(),
and asMapping() methods may be used, each returning a value equal to
what this object pretends to be.

There exists a potential ambiguity between attempting to act as a list
or mapping and the attribute-based access to the data. In particular,
if the column names are 'index', 'count', 'keys', 'items', 'values', or
'has_key', then the attribute-based access will have precedence over
their related methods for lists and mappings. To actually use these
methods, simply apply them to the result of the asList() or asMapping()
methods.

Note that column names with leading underscores may interfere with
the implementation of this class, and as a result may not be accessible
via the attribute-access scheme. Also, column names of asTuple, asList,
and asMapping will be inaccessible via the attribute-access scheme
since those will always represent the methods. To access these columns,
the mapping interface can be used with the column name as the mapping
key.

Note that a database tuple acts as a tuple with respect to sub-scripted
assignment. TypeError exceptions will be raised for several situations,
and AttributeError may be raised for some methods that are intended
to mutate the data (list's 'sort' method) as these methods have not
been implemented.

Method Summary
  __init__(self, desc, data)
DatabaseTuple constructor.
  __cmp__(self, other)
  __getattr__(self, name)
Simulate attribute-access via column names...
  __getitem__(self, key)
Simulate indexed (tuple/list) and mapping-style access...
  __getslice__(self, i, j)
Simulate list/tuple slicing access...
  __len__(self)
  __repr__(self)
  __setattr__(self, name, value)
Simulate attribute-access via column names...
  __setitem__(self, key, value)
Simulate indexed (tuple/list) and mapping-style access...
  __setslice__(self, i, j, list)
Simulate list/tuple slicing access...
  __str__(self)
  _count_(self, item)
Simulate list's methods...
  _getvalue_(self, name)
Internal method for named-based value retrieval...
  _has_key_(self, key)
Simulate mapping's methods...
  _index_(self, item)
Simulate list's methods...
  _items_(self)
Simulate mapping's methods...
  _keys_(self)
Simulate mapping's methods...
  asList(self)
Return the "list" as a real mapping...
  asMapping(self)
Return the "tuple" as a real mapping...
  asTuple(self)
Return the "tuple" as a real tuple...

Method Details

__init__(self, desc, data)
(Constructor)

DatabaseTuple constructor.

A DatabaseTuple is initialized with a TupleDescriptor and a tuple or
list specifying the data elements.

__getattr__(self, name)
(Qualification operator)

Simulate attribute-access via column names

__getitem__(self, key)
(Indexing operator)

Simulate indexed (tuple/list) and mapping-style access

__getslice__(self, i, j)
(Slicling operator)

Simulate list/tuple slicing access

__setattr__(self, name, value)

Simulate attribute-access via column names

__setitem__(self, key, value)
(Index assignment operator)

Simulate indexed (tuple/list) and mapping-style access

__setslice__(self, i, j, list)
(Slice assignment operator)

Simulate list/tuple slicing access

_count_(self, item)

Simulate list's methods

_getvalue_(self, name)

Internal method for named-based value retrieval

_has_key_(self, key)

Simulate mapping's methods

_index_(self, item)

Simulate list's methods

_items_(self)

Simulate mapping's methods

_keys_(self)

Simulate mapping's methods

asList(self)

Return the "list" as a real mapping

asMapping(self)

Return the "tuple" as a real mapping

asTuple(self)

Return the "tuple" as a real tuple

Generated by Epydoc 2.0 on Mon Nov 10 15:08:20 2003 http://epydoc.sf.net