4 Datatypes

Information stored in a file or sent through a network appears as a chain of bytes, but it represents high level information. For example we may want to keep some basic data about a master piece book:

    <metadata xmlns:dc="http://purl.org/dc/elements/1.1/">
      <dc:title>100 años de soledad</dc:title>
      <dc:creator>Gabriel Garcia Marquez</dc:creator>
      <dc:date>1999-07-02</dc:date>
      <dc:language>es</dc:language>
    </metadata>

Above we have used the XML language to keep the title, author, date of publication and language of our book; but we may prefer a different file format:

    BEGIN:RECORD
      TITLE:100 años de soledad
      CREATOR:Gabriel Garcia Marquez
      DATE:1999-07-02
      LANGUAGE:es
    END:RECORD

Indepently of the format used, one thing is sure, we would like to load the information with a type:

    '100 años de soledad'    -(text)->  u'100 años de soledad'
    'Gabriel Garcia Marquez' -(text)->  u'Gabriel Garcia Marquez'
    '1999-07-02'             -(date)->  datetime.date(1999, 7, 2)
    'es'                     -(noop)->  'es'

This process is called deserialization. The opposite operation, which we are also interested in, is called serialization: to transform a value to a chain of bytes.

Other operations we may be interested include:

The packages itools.datatypes and itools.schema provide an infrastructure to do all this and more. What is useful not only to serialize and deserialize files, but also for other purposes, like validating user input data.