From: Serhiy Storchaka Date: Thu, 30 Oct 2014 22:56:45 +0000 (+0200) Subject: Issue #22410: Module level functions in the re module now cache compiled X-Git-Tag: v3.5.0a1~562 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=7cc0a1f7cb6af03ada42174404bed86bdbb4e16c;p=thirdparty%2FPython%2Fcpython.git Issue #22410: Module level functions in the re module now cache compiled locale-dependent regular expressions taking into account the locale. --- 7cc0a1f7cb6af03ada42174404bed86bdbb4e16c diff --cc Lib/re.py index 8f5b3995a6a5,46cea2bd691f..e731a69bca31 --- a/Lib/re.py +++ b/Lib/re.py @@@ -122,15 -122,13 +122,16 @@@ This module also defines an exception ' import sys import sre_compile import sre_parse + import _locale # public symbols -__all__ = [ "match", "fullmatch", "search", "sub", "subn", "split", "findall", - "compile", "purge", "template", "escape", "A", "I", "L", "M", "S", "X", - "U", "ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE", - "UNICODE", "error" ] +__all__ = [ + "match", "fullmatch", "search", "sub", "subn", "split", + "findall", "finditer", "compile", "purge", "template", "escape", + "error", "A", "I", "L", "M", "S", "X", "U", + "ASCII", "IGNORECASE", "LOCALE", "MULTILINE", "DOTALL", "VERBOSE", + "UNICODE", +] __version__ = "2.2.1" @@@ -273,10 -273,14 +274,12 @@@ _pattern_type = type(sre_compile.compil _MAXCACHE = 512 def _compile(pattern, flags): # internal: compile pattern - bypass_cache = flags & DEBUG - if not bypass_cache: - try: - p, loc = _cache[type(pattern), pattern, flags] - if loc is None or loc == _locale.setlocale(_locale.LC_CTYPE): - return p - except KeyError: - pass + try: - return _cache[type(pattern), pattern, flags] ++ p, loc = _cache[type(pattern), pattern, flags] ++ if loc is None or loc == _locale.setlocale(_locale.LC_CTYPE): ++ return p + except KeyError: + pass if isinstance(pattern, _pattern_type): if flags: raise ValueError( @@@ -285,10 -289,14 +288,14 @@@ if not sre_compile.isstring(pattern): raise TypeError("first argument must be string or compiled pattern") p = sre_compile.compile(pattern, flags) - if not bypass_cache: + if not (flags & DEBUG): if len(_cache) >= _MAXCACHE: _cache.clear() - _cache[type(pattern), pattern, flags] = p + if p.flags & LOCALE: + loc = _locale.setlocale(_locale.LC_CTYPE) + else: + loc = None + _cache[type(pattern), pattern, flags] = p, loc return p def _compile_repl(repl, pattern): diff --cc Misc/NEWS index 76fdd8ddc7e8,52bbcf1702af..dd2aeb6f4d82 --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -180,9 -33,9 +180,12 @@@ Core and Builtin Library ------- + - Issue #22410: Module level functions in the re module now cache compiled + locale-dependent regular expressions taking into account the locale. + +- Issue #22759: Query methods on pathlib.Path() (exists(), is_dir(), etc.) + now return False when the underlying stat call raises NotADirectoryError. + - Issue #8876: distutils now falls back to copying files when hard linking doesn't work. This allows use with special filesystems such as VirtualBox shared folders.