14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
"""Pyrex implementation of _read_stanza_*."""
21
from bzrlib.rio import Stanza
23
_tag_re = re.compile(r'^[-a-zA-Z0-9_]+$')
25
return bool(_tag_re.match(tag))
28
def _read_stanza_utf8(line_iter):
33
# TODO: jam 20060922 This code should raise real errors rather than
34
# using 'assert' to process user input, or raising ValueError
35
# rather than a more specific error.
36
for line in line_iter:
37
if line is None or line == '':
42
if line[0] == '\t': # continues previous value
44
raise ValueError('invalid continuation line %r' % real_l)
45
accum_value.append('\n' + line[1:-1])
46
else: # new tag:value line
48
stanza.add(tag, ''.join(accum_value).decode('utf-8'))
50
colon_index = line.index(': ')
52
raise ValueError('tag/value separator not found in line %r'
54
tag = line[:colon_index]
55
if not _valid_tag(tag):
56
raise ValueError("invalid rio tag %r" % (tag,))
57
accum_value = line[colon_index+2:-1]
58
if tag is not None: # add last tag-value
59
stanza.add(tag, ''.join(accum_value).decode('utf-8'))
61
else: # didn't see any content
65
def _read_stanza_unicode(unicode_iter):
70
# TODO: jam 20060922 This code should raise real errors rather than
71
# using 'assert' to process user input, or raising ValueError
72
# rather than a more specific error.
73
for line in unicode_iter:
74
if line is None or line == '':
79
if line[0] == '\t': # continues previous value
81
raise ValueError('invalid continuation line %r' % real_l)
82
accum_value += '\n' + line[1:-1]
83
else: # new tag:value line
85
stanza.add(tag, accum_value)
87
colon_index = line.index(': ')
89
raise ValueError('tag/value separator not found in line %r'
91
tag = str(line[:colon_index])
92
if not _valid_tag(tag):
93
raise ValueError("invalid rio tag %r" % (tag,))
94
accum_value = line[colon_index+2:-1]
96
if tag is not None: # add last tag-value
97
stanza.add(tag, accum_value)
99
else: # didn't see any content