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

  • Committer: Robert Collins
  • Date: 2010-05-06 23:41:35 UTC
  • mto: This revision was merged to the branch mainline in revision 5223.
  • Revision ID: robertc@robertcollins.net-20100506234135-yivbzczw1sejxnxc
Lock methods on ``Tree``, ``Branch`` and ``Repository`` are now
expected to return an object which can be used to unlock them. This reduces
duplicate code when using cleanups. The previous 'tokens's returned by
``Branch.lock_write`` and ``Repository.lock_write`` are now attributes
on the result of the lock_write. ``repository.RepositoryWriteLockResult``
and ``branch.BranchWriteLockResult`` document this. (Robert Collins)

``log._get_info_for_log_files`` now takes an add_cleanup callable.
(Robert Collins)

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