summaryrefslogtreecommitdiffstats
path: root/Lib/_strptime.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-12-03 20:26:36 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-12-03 20:26:36 (GMT)
commitb1f64e7d292fb0b1830185e7243c0341e28e6899 (patch)
treec0f5834c96438b2c8c0d9c5d94f15748241797ab /Lib/_strptime.py
parent657257edb61c7d69a9e73352fdad8f243e1494ab (diff)
parentc7217d7c2210008ba06e9bcb2a14439a451eef71 (diff)
downloadcpython-b1f64e7d292fb0b1830185e7243c0341e28e6899.zip
cpython-b1f64e7d292fb0b1830185e7243c0341e28e6899.tar.gz
cpython-b1f64e7d292fb0b1830185e7243c0341e28e6899.tar.bz2
Issue #6478: _strptime's regexp cache now is reset after changing timezone
with time.tzset().
Diffstat (limited to 'Lib/_strptime.py')
-rw-r--r--Lib/_strptime.py22
1 files changed, 14 insertions, 8 deletions
diff --git a/Lib/_strptime.py b/Lib/_strptime.py
index 374923d..b8cda76 100644
--- a/Lib/_strptime.py
+++ b/Lib/_strptime.py
@@ -77,6 +77,8 @@ class LocaleTime(object):
self.__calc_date_time()
if _getlang() != self.lang:
raise ValueError("locale changed during initialization")
+ if time.tzname != self.tzname or time.daylight != self.daylight:
+ raise ValueError("timezone changed during initialization")
def __pad(self, seq, front):
# Add '' to seq to either the front (is True), else the back.
@@ -161,15 +163,17 @@ class LocaleTime(object):
def __calc_timezone(self):
# Set self.timezone by using time.tzname.
- # Do not worry about possibility of time.tzname[0] == timetzname[1]
- # and time.daylight; handle that in strptime .
+ # Do not worry about possibility of time.tzname[0] == time.tzname[1]
+ # and time.daylight; handle that in strptime.
try:
time.tzset()
except AttributeError:
pass
- no_saving = frozenset({"utc", "gmt", time.tzname[0].lower()})
- if time.daylight:
- has_saving = frozenset({time.tzname[1].lower()})
+ self.tzname = time.tzname
+ self.daylight = time.daylight
+ no_saving = frozenset({"utc", "gmt", self.tzname[0].lower()})
+ if self.daylight:
+ has_saving = frozenset({self.tzname[1].lower()})
else:
has_saving = frozenset()
self.timezone = (no_saving, has_saving)
@@ -307,13 +311,15 @@ def _strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
global _TimeRE_cache, _regex_cache
with _cache_lock:
-
- if _getlang() != _TimeRE_cache.locale_time.lang:
+ locale_time = _TimeRE_cache.locale_time
+ if (_getlang() != locale_time.lang or
+ time.tzname != locale_time.tzname or
+ time.daylight != locale_time.daylight):
_TimeRE_cache = TimeRE()
_regex_cache.clear()
+ locale_time = _TimeRE_cache.locale_time
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: