~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/rio.py

  • Committer: abentley
  • Date: 2006-04-20 23:47:53 UTC
  • mfrom: (1681 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1683.
  • Revision ID: abentley@lappy-20060420234753-6a6874b76f09f86d
Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
 
21
21
import re
22
22
 
 
23
from bzrlib.iterablefile import IterableFile
 
24
 
23
25
# XXX: some redundancy is allowing to write stanzas in isolation as well as
24
26
# through a writer object.  
25
27
 
52
54
            else:
53
55
                yield s
54
56
 
 
57
 
 
58
def rio_file(stanzas, header=None):
 
59
    """Produce a rio IterableFile from an iterable of stanzas"""
 
60
    def str_iter():
 
61
        if header is not None:
 
62
            yield header + '\n'
 
63
        first_stanza = True
 
64
        for s in stanzas:
 
65
            if first_stanza is not True:
 
66
                yield '\n'
 
67
            for line in s.to_lines():
 
68
                yield line
 
69
            first_stanza = False
 
70
    return IterableFile(str_iter())
 
71
 
 
72
 
55
73
def read_stanzas(from_file):
56
74
    while True:
57
75
        s = read_stanza(from_file)
135
153
            return []
136
154
        result = []
137
155
        for tag, value in self.items:
138
 
            assert isinstance(tag, str)
 
156
            assert isinstance(tag, str), type(tag)
139
157
            assert isinstance(value, unicode)
140
158
            if value == '':
141
159
                result.append(tag + ': \n')
228
246
                colon_index = line.index(': ')
229
247
            except ValueError:
230
248
                raise ValueError('tag/value separator not found in line %r' % real_l)
231
 
            tag = line[:colon_index]
 
249
            tag = str(line[:colon_index])
232
250
            assert valid_tag(tag), \
233
251
                    "invalid rio tag %r" % tag
234
252
            accum_value = line[colon_index+2:-1]