/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/rio.py

  • Committer: Breezy landing bot
  • Author(s): Martin
  • Date: 2017-06-10 02:49:30 UTC
  • mfrom: (6677.1.4 py3_bootstrap)
  • Revision ID: breezy.the.bot@gmail.com-20170610024930-enw8wdbjy9s4dtnm
Progress on Python 3 to get TestCaseWithTransport working

Merged from https://code.launchpad.net/~gz/brz/py3_bootstrap/+merge/325439

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
 
37
37
from . import osutils
38
38
from .iterablefile import IterableFile
 
39
from .sixish import (
 
40
    text_type,
 
41
    )
39
42
 
40
43
# XXX: some redundancy is allowing to write stanzas in isolation as well as
41
44
# through a writer object.
74
77
    """Produce a rio IterableFile from an iterable of stanzas"""
75
78
    def str_iter():
76
79
        if header is not None:
77
 
            yield header + '\n'
 
80
            yield header + b'\n'
78
81
        first_stanza = True
79
82
        for s in stanzas:
80
83
            if first_stanza is not True:
81
 
                yield '\n'
 
84
                yield b'\n'
82
85
            for line in s.to_lines():
83
86
                yield line
84
87
            first_stanza = False
121
124
        """Append a name and value to the stanza."""
122
125
        if not valid_tag(tag):
123
126
            raise ValueError("invalid tag %r" % (tag,))
124
 
        if isinstance(value, str):
125
 
            value = unicode(value)
126
 
        elif isinstance(value, unicode):
 
127
        if isinstance(value, bytes):
 
128
            value = value.decode('ascii')
 
129
        elif isinstance(value, text_type):
127
130
            pass
128
 
        ## elif isinstance(value, (int, long)):
129
 
        ##    value = str(value)           # XXX: python2.4 without L-suffix
130
131
        else:
131
132
            raise TypeError("invalid type for rio value: %r of type %s"
132
133
                            % (value, type(value)))
175
176
        result = []
176
177
        for tag, value in self.items:
177
178
            if value == '':
178
 
                result.append(tag + ': \n')
 
179
                result.append(tag.encode('ascii') + b': \n')
179
180
            elif '\n' in value:
180
181
                # don't want splitlines behaviour on empty lines
181
182
                val_lines = value.split('\n')
182
 
                result.append(tag + ': ' + val_lines[0].encode('utf-8') + '\n')
 
183
                result.append(tag + b': ' + val_lines[0].encode('utf-8') + b'\n')
183
184
                for line in val_lines[1:]:
184
 
                    result.append('\t' + line.encode('utf-8') + '\n')
 
185
                    result.append(b'\t' + line.encode('utf-8') + b'\n')
185
186
            else:
186
 
                result.append(tag + ': ' + value.encode('utf-8') + '\n')
 
187
                result.append(tag.encode('ascii') + b': ' + value.encode('utf-8') + b'\n')
187
188
        return result
188
189
 
189
190
    def to_string(self):
190
191
        """Return stanza as a single string"""
191
 
        return ''.join(self.to_lines())
 
192
        return b''.join(self.to_lines())
192
193
 
193
194
    def to_unicode(self):
194
195
        """Return stanza as a single Unicode string.