Serializing and deserializing dictionaries of parameters.
The serialized “mapfiles” should be clear, flat-text strings, and allow easy merging of independent/conflicting changes.
Generate a YAML mapfile content string.
See also
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"
Parse a YAML mapfile string.
See also
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