summaryrefslogtreecommitdiff
path: root/Lib/_strptime.py
diff options
context:
space:
mode:
authorBrett Cannon <bcannon@gmail.com>2007-04-01 18:47:27 +0000
committerBrett Cannon <bcannon@gmail.com>2007-04-01 18:47:27 +0000
commitc69066501bc2da4aa325833c76e6cf12b87aafa6 (patch)
treebb31b9ac1298aa9671f58e64336fc2f8fdbb8f9b /Lib/_strptime.py
parent8f35f44af3aacf1802253dc33e26e64306e55756 (diff)
downloadcpython-git-c69066501bc2da4aa325833c76e6cf12b87aafa6.tar.gz
time.strptime's caching of its locale object was being recreated when the
locale changed but not used during the function call it was recreated during. The test in this checkin is untested (OS X does not have the proper locale support for me to test), although the fix for the bug this deals with was tested by the OP (#1290505). Once the buildbots verify the test at least doesn't fail it becomes a backport candidate.
Diffstat (limited to 'Lib/_strptime.py')
-rw-r--r--Lib/_strptime.py9
1 files changed, 4 insertions, 5 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index 5ea59ed7be..9e7823abdd 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -295,17 +295,16 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
"""Return a time struct based on the input string and the format string."""
global _TimeRE_cache, _regex_cache
with _cache_lock:
- time_re = _TimeRE_cache
- locale_time = time_re.locale_time
- if _getlang() != locale_time.lang:
+ if _getlang() != _TimeRE_cache.locale_time.lang:
_TimeRE_cache = TimeRE()
- _regex_cache = {}
+ _regex_cache.clear()
if len(_regex_cache) > _CACHE_MAX_SIZE:
_regex_cache.clear()
+ locale_time = _TimeRE_cache.locale_time
format_regex = _regex_cache.get(format)
if not format_regex:
try:
- format_regex = time_re.compile(format)
+ format_regex = _TimeRE_cache.compile(format)
# KeyError raised when a bad format is found; can be specified as
# \\, in which case it was a stray % but with a space after it
except KeyError, err: