/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: Jelmer Vernooij
  • Date: 2020-04-05 19:11:34 UTC
  • mto: (7490.7.16 work)
  • mto: This revision was merged to the branch mainline in revision 7501.
  • Revision ID: jelmer@jelmer.uk-20200405191134-0aebh8ikiwygxma5
Populate the .gitignore file.

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