~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/globbing.py

  • Committer: Patch Queue Manager
  • Date: 2016-02-01 19:56:05 UTC
  • mfrom: (6615.1.1 trunk)
  • Revision ID: pqm@pqm.ubuntu.com-20160201195605-o7rl92wf6uyum3fk
(vila) Open trunk again as 2.8b1 (Vincent Ladeuil)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2011 Canonical Ltd
2
2
 
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
expressions.
21
21
"""
22
22
 
 
23
from __future__ import absolute_import
 
24
 
23
25
import re
24
26
 
25
 
from bzrlib import errors
 
27
from bzrlib import (
 
28
    errors,
 
29
    lazy_regex,
 
30
    )
26
31
from bzrlib.trace import (
27
32
    mutter,
28
33
    warning,
38
43
    must not contain capturing groups.
39
44
    """
40
45
 
41
 
    _expand = re.compile(ur'\\&')
 
46
    _expand = lazy_regex.lazy_compile(ur'\\&')
42
47
 
43
48
    def __init__(self, source=None):
44
49
        self._pat = None
74
79
 
75
80
    def __call__(self, text):
76
81
        if not self._pat:
77
 
            self._pat = re.compile(
 
82
            self._pat = lazy_regex.lazy_compile(
78
83
                    u'|'.join([u'(%s)' % p for p in self._pats]),
79
84
                    re.UNICODE)
80
85
        return self._pat.sub(self._do_sub, text)
217
222
 
218
223
    def _add_patterns(self, patterns, translator, prefix=''):
219
224
        while patterns:
220
 
            grouped_rules = ['(%s)' % translator(pat) for pat in patterns[:99]]
 
225
            grouped_rules = [
 
226
                '(%s)' % translator(pat) for pat in patterns[:99]]
221
227
            joined_rule = '%s(?:%s)$' % (prefix, '|'.join(grouped_rules))
222
 
            self._regex_patterns.append((re.compile(joined_rule, re.UNICODE),
 
228
            # Explicitly use lazy_compile here, because we count on its
 
229
            # nicer error reporting.
 
230
            self._regex_patterns.append((
 
231
                lazy_regex.lazy_compile(joined_rule, re.UNICODE),
223
232
                patterns[:99]))
224
233
            patterns = patterns[99:]
225
234
 
275
284
        translator = Globster.pattern_info[Globster.identify(pattern)]["translator"]
276
285
        tpattern = '(%s)' % translator(pattern)
277
286
        try:
278
 
            re_obj = re.compile(tpattern, re.UNICODE)
 
287
            re_obj = lazy_regex.lazy_compile(tpattern, re.UNICODE)
279
288
            re_obj.search("") # force compile
280
289
        except errors.InvalidPattern, e:
281
290
            result = False
334
343
                Globster.pattern_info[t]["prefix"])
335
344
 
336
345
 
337
 
_slashes = re.compile(r'[\\/]+')
 
346
_slashes = lazy_regex.lazy_compile(r'[\\/]+')
338
347
def normalize_pattern(pattern):
339
348
    """Converts backslashes in path patterns to forward slashes.
340
349