/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): Jelmer Vernooij
  • Date: 2020-08-23 01:15:41 UTC
  • mfrom: (7520.1.4 merge-3.1)
  • Revision ID: breezy.the.bot@gmail.com-20200823011541-nv0oh7nzaganx2qy
Merge lp:brz/3.1.

Merged from https://code.launchpad.net/~jelmer/brz/merge-3.1/+merge/389690

Show diffs side-by-side

added added

removed removed

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