/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/lazy_regex.py

  • Committer: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006, 2008-2011, 2017 Canonical Ltd
 
1
# Copyright (C) 2006 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
28
28
 
29
29
import re
30
30
 
31
 
from . import errors
32
 
 
33
 
 
34
 
class InvalidPattern(errors.BzrError):
35
 
 
36
 
    _fmt = ('Invalid pattern(s) found. %(msg)s')
37
 
 
38
 
    def __init__(self, msg):
39
 
        self.msg = msg
 
31
from bzrlib import errors
40
32
 
41
33
 
42
34
class LazyRegex(object):
76
68
        """Thunk over to the original re.compile"""
77
69
        try:
78
70
            return _real_re_compile(*args, **kwargs)
79
 
        except re.error as e:
 
71
        except re.error, e:
80
72
            # raise InvalidPattern instead of re.error as this gives a
81
73
            # cleaner message to the user.
82
 
            raise InvalidPattern('"' + args[0] + '" ' +str(e))
 
74
            raise errors.InvalidPattern('"' + args[0] + '" ' +str(e))
83
75
 
84
76
    def __getstate__(self):
85
77
        """Return the state to use when pickling."""
139
131
    raise AssertionError(
140
132
        "re.compile has already been overridden as lazy_compile, but this would" \
141
133
        " cause infinite recursion")
142
 
 
143
 
 
144
 
# Some libraries calls re.finditer which fails it if receives a LazyRegex.
145
 
if getattr(re, 'finditer', False):
146
 
    def finditer_public(pattern, string, flags=0):
147
 
        if isinstance(pattern, LazyRegex):
148
 
            return pattern.finditer(string)
149
 
        else:
150
 
            return _real_re_compile(pattern, flags).finditer(string)
151
 
    re.finditer = finditer_public