Пример #1
0
def _parse_reference(lines):
    '''Parse single REFERENCE field.
    '''
    res = {}
    # magic number 11: the non keyworded lines in REFERENCE
    # are at least indented with 11 spaces.
    feature_indent = ' ' * 11
    section_splitter = _yield_section(
        lambda x: not x.startswith(feature_indent),
        skip_blanks=True, strip=False)
    for section in section_splitter(lines):
        label, data = _parse_section_default(
            section, join_delimiter=' ', return_label=True)
        res[label] = data
    return res
 def test_parse_section_default(self):
     lines = [
         ['FOO  blah blah',
          '     blah'],
         ['FOO=blah',
          '    blah'],
         ['FOO']]
     kwargs = [{'join_delimiter': '=', 'return_label': False},
               {'label_delimiter': '=', 'join_delimiter': '',
                'return_label': True},
               {'label_delimiter': '=', 'join_delimiter': '=',
                'return_label': True}]
     expects = ['blah blah=blah',
                ('FOO', 'blahblah'),
                ('FOO', '')]
     for i, j, k in zip(lines, kwargs, expects):
         self.assertEqual(k, _parse_section_default(i, **j))