summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2004-03-25 14:58:19 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2004-03-25 14:58:19 (GMT)
commit1c0f1f97fb9021a2084298e04aa920d5f478f0c6 (patch)
tree675d72d827999aea2e8ee9aef40bada55aaeeb91 /Lib
parent85309512ec4f461a3025fab3bd11408950752f5d (diff)
downloadcpython-1c0f1f97fb9021a2084298e04aa920d5f478f0c6.zip
cpython-1c0f1f97fb9021a2084298e04aa920d5f478f0c6.tar.gz
cpython-1c0f1f97fb9021a2084298e04aa920d5f478f0c6.tar.bz2
Defer compilation of regular expressions until first use.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/util.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/distutils/util.py b/Lib/distutils/util.py
index 8c3c8df..12775d6 100644
--- a/Lib/distutils/util.py
+++ b/Lib/distutils/util.py
@@ -209,9 +209,12 @@ def grok_environment_error (exc, prefix="error: "):
# Needed by 'split_quoted()'
-_wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace)
-_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
-_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
+_wordchars_re = _squote_re = _dquote_re = None
+def _init_regex():
+ global _wordchars_re, _squote_re, _dquote_re
+ _wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace)
+ _squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
+ _dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
def split_quoted (s):
"""Split a string up according to Unix shell-like rules for quotes and
@@ -227,6 +230,7 @@ def split_quoted (s):
# This is a nice algorithm for splitting up a single string, since it
# doesn't require character-by-character examination. It was a little
# bit of a brain-bender to get it working right, though...
+ if _wordchars_re is None: _init_regex()
s = string.strip(s)
words = []