Package Pyblio :: Module Store :: Class Record
[hide private]
[frames] | no frames]

Class Record

source code

object --+    
         |    
      dict --+
             |
            Record

A database record.

It behaves like a dictionnary, which returns a list of attributes for each key. The attributes types depend on the database Schema.

As a convenience, it is possible to use Record.add to build up a Record, instead of setting its fields manually.


Note: this class is shared by all stores

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
get(self, key, default=None)
Get a field, understanding the dotted notation of the add method
source code
 
xmlwrite(self, fd, offset=1)
Export as XML.
source code
 
add(self, field, value, constructor=None)
Adds a new value to a field of this record.
source code
 
deep_equal(self, other) source code

Inherited from dict: __cmp__, __contains__, __delitem__, __eq__, __ge__, __getattribute__, __getitem__, __gt__, __hash__, __iter__, __le__, __len__, __lt__, __ne__, __new__, __repr__, __setitem__, clear, copy, fromkeys, has_key, items, iteritems, iterkeys, itervalues, keys, pop, popitem, setdefault, update, values

Inherited from object: __delattr__, __reduce__, __reduce_ex__, __setattr__, __str__

Instance Variables [hide private]
instance of Key key
the key of the record, unique over the whole database.
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Returns:
new empty dictionary

Overrides: dict.__init__
(inherited documentation)

get(self, key, default=None)

source code 
Get a field, understanding the dotted notation of the add method
Returns:
D[k] if k in D, else d

Overrides: dict.get

xmlwrite(self, fd, offset=1)

source code 

Export as XML.

Writes the content of the record as an XML fragment.
Parameters:
  • fd - file descriptor to write to.

add(self, field, value, constructor=None)

source code 

Adds a new value to a field of this record.

This function allows you to add an item to a record. It converts the specified 'value' by calling 'constructor' on it, and appends the resulting attribute to the record.

If you specify something like 'a.b' in fields, the 'b' qualifier for field 'a' is set, for the last 'a' added. It is possible, if you know that you will only have one 'a', to set 'a.b' before 'a'.

Example:
>>> rec.add ('title', u'My title', Attribute.Text)
>>> rec.add ('title.subtitle', u'My subtitle', Attribute.Text)
>>> rec.add ('author', definition, author_parser)
Parameters:
  • field (a string, possibly containing a '.' in the case of structured attributes) - the field we want to add in the record
  • value - the 'source' value to set in the record. This value has not yet been converted into an Pyblio.Attribute instance.
  • constructor - a function that will turn a 'value' into a proper attribute.

Instance Variable Details [hide private]

key

the key of the record, unique over the whole database. It is generated by the actual storage layer. This key has only an internal meaning. Do not expose it.
Type:
instance of Key