Out-of-the-box itools.datatypes provides support for the following types:
An integer number is serialized using ASCII characters. This means a call to Integer.decode(x) is equivalent to int(x), and Integer.encode(x) does the same than str(x).
Text strings are serialized using the UTF-8 encoding (by default).
A byte string does not needs to be serialized or deserialized, the output is always equal to the input.
Boolean values are encoded with the “0” character for the false value and with the “1” character for the true value.
Dates are encoded following the ISO 8601 standard1: YYYY-MM-DD.
Date and time is encoded with the pattern:
YYYY-MM-DDThh:mm:ss.
The URI decoder will build and return one of the URI reference objects defined in the itools.uri package, usually it will be an instance of the class itools.uri.generic.Reference.
Usually filenames include extensions to indicate the file type, and sometimes other information like the language. The filename decoder will parse a filename and return a tuple where the first element is the filename, the second element is the file type, and the last element is the language. For example:
>>> from itools.datatypes import FileName
>>> FileName.decode('index.html.en')
('index', 'html', 'en')
>>> FileName.decode('index.html')
('index', 'html', None)
>>> FileName.decode('index')
('index', None, None)
An XML qualified name has two parts, the prefix and the local name, so our decoder will return a tuple with these two elements:
>>> from itools.datatypes import QName
>>> QName.decode('dc:title')
('dc', 'title')
>>> QName.decode('href')
(None, 'href')
The encoder expects a two element tuple:
>>> QName.encode(('dc', 'title'))
'dc:title'
>>> QName.encode((None, 'href'))
'href'
Footnotes