138
138
result.append(tag + ': \n')
139
139
elif '\n' in value:
140
val_lines = value.splitlines()
140
# don't want splitlines behaviour on empty lines
141
val_lines = value.split('\n')
141
142
result.append(tag + ': ' + val_lines[0] + '\n')
142
143
for line in val_lines[1:]:
143
144
result.append('\t' + line + '\n')
186
187
blank line follows the stanza, it is consumed. It's not an error for
187
188
there to be no blank at end of file. If there is a blank file at the
188
189
start of the input this is really an empty stanza and that is returned.
191
Only the stanza lines and the trailing blank (if any) are consumed
192
195
stanza = Stanza()
193
198
for line in line_iter:
194
199
if line == None or line == '':
195
200
break # end of file
198
202
break # end of stanza
199
203
assert line[-1] == '\n'
203
colon_index = line.index(': ')
205
raise ValueError('tag/value separator not found in line %r' % real_l)
206
tag = line[:colon_index]
207
assert valid_tag(tag), \
208
"invalid rio tag %r" % tag
209
value_start = line[colon_index+2:-1]
210
# TODO: Handle multiline values
212
stanza.add(tag, value)
214
return None # didn't see any content
205
if line[0] == '\t': # continues previous value
207
raise ValueError('invalid continuation line %r' % real_l)
208
accum_value += '\n' + line[1:-1]
209
else: # new tag:value line
211
stanza.add(tag, accum_value)
213
colon_index = line.index(': ')
215
raise ValueError('tag/value separator not found in line %r' % real_l)
216
tag = line[:colon_index]
217
assert valid_tag(tag), \
218
"invalid rio tag %r" % tag
219
accum_value = line[colon_index+2:-1]
220
if tag is not None: # add last tag-value
221
stanza.add(tag, accum_value)
223
else: # didn't see any content