46
46
# TODO: jam 20060922 This code should raise real errors rather than
47
47
# using 'assert' to process user input, or raising ValueError
48
48
# rather than a more specific error.
49
50
for line in unicode_iter:
50
if line is None or line == '':
51
if line is None or line == u'':
51
52
break # end of file
53
54
break # end of stanza
55
if line[0] == '\t': # continues previous value
56
if line[0] == u'\t': # continues previous value
57
58
raise ValueError('invalid continuation line %r' % real_l)
58
accum_value += '\n' + line[1:-1]
59
accum_value.append(u'\n' + line[1:-1])
59
60
else: # new tag:value line
60
61
if tag is not None:
61
stanza.add(tag, accum_value)
62
stanza.add(tag, u''.join(accum_value))
63
colon_index = line.index(': ')
64
colon_index = line.index(u': ')
65
66
raise ValueError('tag/value separator not found in line %r'
67
68
tag = str(line[:colon_index])
68
69
if not _valid_tag(tag):
69
70
raise ValueError("invalid rio tag %r" % (tag,))
70
accum_value = line[colon_index+2:-1]
71
accum_value = [line[colon_index+2:-1]]
72
73
if tag is not None: # add last tag-value
73
stanza.add(tag, accum_value)
74
stanza.add(tag, u''.join(accum_value))
75
76
else: # didn't see any content