/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: John Arbash Meinel
  • Date: 2006-10-09 14:06:24 UTC
  • mto: This revision was merged to the branch mainline in revision 2069.
  • Revision ID: john@arbash-meinel.com-20061009140624-0ebc61ab6809f5f4
Install lazy compile during startup

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006 Canonical Ltd
 
1
# Copyright (C) 2006 by 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
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Lazily compiled regex objects.
18
18
 
23
23
import re
24
24
 
25
25
 
 
26
_real_re_compile = re.compile
 
27
 
 
28
 
26
29
class LazyRegex(object):
27
 
    """A proxy around a real regex, which won't be compiled until accessed."""
 
30
    """A proxy around a real regex, which won't compiled until accessed."""
28
31
 
29
32
 
30
33
    # These are the parameters on a real _sre.SRE_Pattern object, which we
91
94
 
92
95
def reset_compile():
93
96
    """Restore the original function to re.compile().
94
 
 
 
97
    
95
98
    It is safe to call reset_compile() multiple times, it will always
96
99
    restore re.compile() to the value that existed at import time.
97
100
    Though the first call will reset back to the original (it doesn't
98
101
    track nesting level)
99
102
    """
100
103
    re.compile = _real_re_compile
101
 
 
102
 
 
103
 
_real_re_compile = re.compile
104
 
if _real_re_compile is lazy_compile:
105
 
    raise AssertionError(
106
 
        "re.compile has already been overridden as lazy_compile, but this would" \
107
 
        " cause infinite recursion")