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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-22 00:56:52 UTC
  • mfrom: (6621.2.26 py3_pokes)
  • Revision ID: jelmer@jelmer.uk-20170522005652-yjahcr9hwmjkno7n
Merge Python3 porting work ('py3 pokes')

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
from __future__ import absolute_import
18
18
 
 
19
import re
19
20
import sys
20
21
 
21
 
from breezy.lazy_import import lazy_import
 
22
from ...lazy_import import lazy_import
22
23
lazy_import(globals(), """
23
24
from fnmatch import fnmatch
24
 
import re
25
 
from cStringIO import StringIO
26
25
 
27
26
from breezy._termcolor import color_string, re_color_string, FG
28
27
 
36
35
    diff,
37
36
    errors,
38
37
    lazy_regex,
 
38
    revision as _mod_revision,
 
39
    )
 
40
""")
 
41
from breezy import (
39
42
    osutils,
40
 
    revision as _mod_revision,
41
43
    trace,
42
44
    )
43
 
""")
 
45
from breezy.sixish import (
 
46
    BytesIO,
 
47
    )
44
48
 
45
49
_user_encoding = osutils.get_user_encoding()
46
50
 
122
126
        # use python's re.compile as we need to catch re.error in case of bad pattern
123
127
        lazy_regex.reset_compile()
124
128
        patternc = re.compile(pattern, flags)
125
 
    except re.error, e:
 
129
    except re.error as e:
126
130
        raise errors.BzrError("Invalid pattern: '%s'" % pattern)
127
131
    return patternc
128
132
 
277
281
            else:
278
282
                ancestor_id = new_rev.parent_ids[0]
279
283
            old_tree = repo.revision_tree(ancestor_id)
280
 
            s = StringIO()
 
284
            s = BytesIO()
281
285
            diff.show_diff_trees(old_tree, new_tree, s,
282
286
                old_label='', new_label='')
283
287
            display_revno = True
674
678
            writeline()
675
679
    elif opts.fixed_string:
676
680
        # Fast path for no match, search through the entire file at once rather
677
 
        # than a line at a time. However, we don't want this without Python 2.5
678
 
        # as the quick string search algorithm wasn't implemented till then:
679
 
        # <http://effbot.org/zone/stringlib.htm>
680
 
        if sys.version_info > (2, 5):
681
 
            i = file_text.find(pattern)
682
 
            if i == -1:
683
 
                return
684
 
            b = file_text.rfind("\n", 0, i) + 1
685
 
            if opts.line_number:
686
 
                start = file_text.count("\n", 0, b) + 1
687
 
            file_text = file_text[b:]
688
 
        else:
689
 
            start = 1
 
681
        # than a line at a time. <http://effbot.org/zone/stringlib.htm>
 
682
        i = file_text.find(pattern)
 
683
        if i == -1:
 
684
            return
 
685
        b = file_text.rfind("\n", 0, i) + 1
 
686
        if opts.line_number:
 
687
            start = file_text.count("\n", 0, b) + 1
 
688
        file_text = file_text[b:]
690
689
        if opts.line_number:
691
690
            for index, line in enumerate(file_text.splitlines()):
692
691
                if pattern in line: