libbe.storage.util.mapfile

Serializing and deserializing dictionaries of parameters.

The serialized “mapfiles” should be clear, flat-text strings, and allow easy merging of independent/conflicting changes.

exception libbe.storage.util.mapfile.IllegalKey(key)
exception libbe.storage.util.mapfile.IllegalValue(value)
exception libbe.storage.util.mapfile.InvalidMapfileContents(contents)
libbe.storage.util.mapfile.generate(map)

Generate a YAML mapfile content string.

See also

parse
inverse

Examples

>>> generate({'q':'p'})
'q: p\n\n'
>>> generate({'q':u'Fran\u00e7ais'})
'q: Fran\xc3\xa7ais\n\n'
>>> generate({'q':u'hello'})
'q: hello\n\n'
>>> generate({'q=':'p'})
Traceback (most recent call last):
IllegalKey: Illegal key "q="
>>> generate({'q:':'p'})
Traceback (most recent call last):
IllegalKey: Illegal key "q:"
>>> generate({'q\n':'p'})
Traceback (most recent call last):
IllegalKey: Illegal key "q\n"
>>> generate({'':'p'})
Traceback (most recent call last):
IllegalKey: Illegal key ""
>>> generate({'>q':'p'})
Traceback (most recent call last):
IllegalKey: Illegal key ">q"
>>> generate({'q':'p\n'})
Traceback (most recent call last):
IllegalValue: Illegal value "p\n"
libbe.storage.util.mapfile.parse(contents)

Parse a YAML mapfile string.

See also

generate
inverse

Examples

>>> parse('q: p\n\n')['q']
'p'
>>> parse('q: \'p\'\n\n')['q']
'p'
>>> contents = generate({'a':'b', 'c':'d', 'e':'f'})
>>> dict = parse(contents)
>>> dict['a']
'b'
>>> dict['c']
'd'
>>> dict['e']
'f'
>>> contents = generate({'q':u'Fran\u00e7ais'})
>>> dict = parse(contents)
>>> dict['q']
u'Fran\xe7ais'
>>> dict = parse('a!')
Traceback (most recent call last):
  ...
InvalidMapfileContents: Invalid YAML contents

Previous topic

libbe.storage.util.config

Next topic

libbe.storage.util.properties

This Page