Bases: object
RFC5322 Parser - see https://tools.ietf.org/html/rfc5322
Build logical lines from a RFC5322-like string
Returns: | A list of strings |
---|
>>> body = '''RT/1.2.3 200 Ok
...
... # a
... b
... spam: 1
...
... ham: 2,
... 3
... --
... # c
... spam: 4
... ham:
... --
... a -- b
... '''
>>> RTParser.build(body)
[['# a b', 'spam: 1', 'ham: 2, 3'], ['# c', 'spam: 4', 'ham:'], ['a -- b']]
Returns: | A list of 2-tuples parsing ‘k: v’ and skipping comments |
---|
>>> RTParser.decode(['# c1: c2', 'spam: 1', 'ham: 2, 3', 'eggs:'])
[('spam', '1'), ('ham', '2, 3'), ('eggs', '')]
>>> RTParser.decode(['<!DOCTYPE HTML PUBLIC >', '<html><head>',])
[]
Returns: | A list of 2-tuples parsing ‘# k: v’ |
---|
>>> RTParser.decode_comment(['# c1: c2', 'spam: 1', 'ham: 2, 3', 'eggs:'])
[('c1', 'c2')]
>>>
Returns: | A list of RFC5322-like section |
---|
>>> decode = RTParser.decode
>>> body = '''
...
... # c1
... spam: 1
... ham: 2,
... 3
... eggs:'''
>>> RTParser.parse(body, decode)
[[('spam', '1'), ('ham', '2, 3'), ('eggs', '')]]
>>> RTParser.parse('# spam 1 does not exist.', decode)
Traceback (most recent call last):
...
RTNotFoundError: spam 1 does not exist
>>> RTParser.parse('# Spam 1 created.', decode)
[[('id', 'spam/1')]]
>>> RTParser.parse('No matching results.', decode)
[]
>>> decode = RTParser.decode_comment
>>> RTParser.parse('# spam: 1\n# ham: 2', decode)
[[('spam', '1'), ('ham', '2')]]