~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/rio.py

  • Committer: Michael Ellerman
  • Date: 2006-02-28 14:45:51 UTC
  • mto: (1558.1.18 Aaron's integration)
  • mto: This revision was merged to the branch mainline in revision 1586.
  • Revision ID: michael@ellerman.id.au-20060228144551-3d9941ecde4a0b0a
Update contrib/pwk for -p1 diffs from bzr

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
 
 
25
23
# XXX: some redundancy is allowing to write stanzas in isolation as well as
26
24
# through a writer object.  
27
25
 
54
52
            else:
55
53
                yield s
56
54
 
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
 
 
73
55
def read_stanzas(from_file):
74
56
    while True:
75
57
        s = read_stanza(from_file)
153
135
            return []
154
136
        result = []
155
137
        for tag, value in self.items:
156
 
            assert isinstance(tag, str), type(tag)
 
138
            assert isinstance(tag, str)
157
139
            assert isinstance(value, unicode)
158
140
            if value == '':
159
141
                result.append(tag + ': \n')
246
228
                colon_index = line.index(': ')
247
229
            except ValueError:
248
230
                raise ValueError('tag/value separator not found in line %r' % real_l)
249
 
            tag = str(line[:colon_index])
 
231
            tag = line[:colon_index]
250
232
            assert valid_tag(tag), \
251
233
                    "invalid rio tag %r" % tag
252
234
            accum_value = line[colon_index+2:-1]