/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.py

  • Committer: Breezy landing bot
  • Author(s): Colin Watson
  • Date: 2020-11-16 21:47:08 UTC
  • mfrom: (7521.1.1 remove-lp-workaround)
  • Revision ID: breezy.the.bot@gmail.com-20201116214708-jos209mgxi41oy15
Remove breezy.git workaround for bazaar.launchpad.net.

Merged from https://code.launchpad.net/~cjwatson/brz/remove-lp-workaround/+merge/393710

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Python implementation of _read_stanza_*."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
import re
22
20
 
23
 
from bzrlib.rio import (
 
21
from .rio import (
24
22
    Stanza,
25
23
    )
26
24
 
27
25
_tag_re = re.compile(r'^[-a-zA-Z0-9_]+$')
 
26
 
 
27
 
28
28
def _valid_tag(tag):
29
 
    if type(tag) != str:
 
29
    if not isinstance(tag, str):
30
30
        raise TypeError(tag)
31
31
    return bool(_tag_re.match(tag))
32
32
 
34
34
def _read_stanza_utf8(line_iter):
35
35
    def iter_unicode_lines():
36
36
        for line in line_iter:
37
 
            if type(line) != str:
 
37
            if not isinstance(line, bytes):
38
38
                raise TypeError(line)
39
 
            yield line.decode('utf-8')
 
39
            yield line.decode('utf-8', 'surrogateescape')
40
40
    return _read_stanza_unicode(iter_unicode_lines())
41
41
 
42
42
 
55
55
        if line == u'\n':
56
56
            break       # end of stanza
57
57
        real_l = line
58
 
        if line[0] == u'\t': # continues previous value
 
58
        if line[0] == u'\t':  # continues previous value
59
59
            if tag is None:
60
60
                raise ValueError('invalid continuation line %r' % real_l)
61
61
            accum_value.append(u'\n' + line[1:-1])
62
 
        else: # new tag:value line
 
62
        else:  # new tag:value line
63
63
            if tag is not None:
64
64
                stanza.add(tag, u''.join(accum_value))
65
65
            try:
70
70
            tag = str(line[:colon_index])
71
71
            if not _valid_tag(tag):
72
72
                raise ValueError("invalid rio tag %r" % (tag,))
73
 
            accum_value = [line[colon_index+2:-1]]
 
73
            accum_value = [line[colon_index + 2:-1]]
74
74
 
75
 
    if tag is not None: # add last tag-value
 
75
    if tag is not None:  # add last tag-value
76
76
        stanza.add(tag, u''.join(accum_value))
77
77
        return stanza
78
78
    else:     # didn't see any content