]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Defer compilation of regular expressions until first use.
authorMartin v. Löwis <martin@v.loewis.de>
Thu, 25 Mar 2004 14:58:19 +0000 (14:58 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Thu, 25 Mar 2004 14:58:19 +0000 (14:58 +0000)
Lib/distutils/util.py

index 8c3c8df97902b7e80897ce86e6234702b1537eae..12775d6fc4fdb93592116e2272e5a6cae0fb8a3b 100644 (file)
@@ -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 = []