~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/rio.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-04-09 16:49:22 UTC
  • mfrom: (1534.10.27 bzr.ttransform)
  • Revision ID: pqm@pqm.ubuntu.com-20060409164922-071803e906c8b96d
New conflict-handling system

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]