]> granicus.if.org Git - python/commitdiff
Issue #6478: _strptime's regexp cache now is reset after changing timezone
authorSerhiy Storchaka <storchaka@gmail.com>
Thu, 3 Dec 2015 20:26:36 +0000 (22:26 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Thu, 3 Dec 2015 20:26:36 +0000 (22:26 +0200)
with time.tzset().

1  2 
Lib/_strptime.py
Lib/test/test_strptime.py
Misc/NEWS

index 374923dd135135bff28087ee6c2df1c2a6a2203c,6d648568b6e148917e0359d13d6b891e4c9ecf80..b8cda769bb3e33ec0895623b1b611f6aa5938b49
@@@ -167,9 -169,11 +169,11 @@@ class LocaleTime(object)
              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()])
++        no_saving = frozenset({"utc", "gmt", self.tzname[0].lower()})
+         if self.daylight:
 -            has_saving = frozenset([self.tzname[1].lower()])
++            has_saving = frozenset({self.tzname[1].lower()})
          else:
              has_saving = frozenset()
          self.timezone = (no_saving, has_saving)
@@@ -307,13 -311,16 +311,15 @@@ def _strptime(data_string, format="%a %
  
      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:
index 346e2c63f8c7dd5878ddbaf15cceb3d5aef21163,c1dd19547899c9c00fe59eace285b408136f2646..1bf1748779db3f8630e38b5b532dd1217298cf8d
@@@ -577,6 -576,46 +576,33 @@@ class CacheTests(unittest.TestCase)
          finally:
              locale.setlocale(locale.LC_TIME, locale_info)
  
+     @support.run_with_tz('STD-1DST')
+     def test_TimeRE_recreation_timezone(self):
+         # The TimeRE instance should be recreated upon changing the timezone.
+         oldtzname = time.tzname
+         tm = _strptime._strptime_time(time.tzname[0], '%Z')
+         self.assertEqual(tm.tm_isdst, 0)
+         tm = _strptime._strptime_time(time.tzname[1], '%Z')
+         self.assertEqual(tm.tm_isdst, 1)
+         # Get id of current cache object.
+         first_time_re = _strptime._TimeRE_cache
+         # Change the timezone and force a recreation of the cache.
+         os.environ['TZ'] = 'EST+05EDT,M3.2.0,M11.1.0'
+         time.tzset()
+         tm = _strptime._strptime_time(time.tzname[0], '%Z')
+         self.assertEqual(tm.tm_isdst, 0)
+         tm = _strptime._strptime_time(time.tzname[1], '%Z')
+         self.assertEqual(tm.tm_isdst, 1)
+         # Get the new cache object's id.
+         second_time_re = _strptime._TimeRE_cache
+         # They should not be equal.
+         self.assertIsNot(first_time_re, second_time_re)
+         # Make sure old names no longer accepted.
+         with self.assertRaises(ValueError):
+             _strptime._strptime_time(oldtzname[0], '%Z')
+         with self.assertRaises(ValueError):
+             _strptime._strptime_time(oldtzname[1], '%Z')
  
 -def test_main():
 -    support.run_unittest(
 -        getlang_Tests,
 -        LocaleTime_Tests,
 -        TimeRETests,
 -        StrptimeTests,
 -        Strptime12AMPMTests,
 -        JulianTests,
 -        CalculationTests,
 -        CacheTests
 -    )
 -
 -
  if __name__ == '__main__':
 -    test_main()
 +    unittest.main()
diff --cc Misc/NEWS
index c28618399e0b845e525999bab53f5b6b22549b4e,76296000b451bc7f8a64d4511d6eac184cba15f4..6dae17d196b3f1de51f9ded5b11904f9089a1212
+++ b/Misc/NEWS
@@@ -19,142 -19,128 +19,145 @@@ Core and Builtin
    __bytes__, __trunc__, and __float__ returning instances of subclasses of
    bytes, int, and float to subclasses of bytes, int, and float correspondingly.
  
 -- Issue #25388: Fixed tokenizer crash when processing undecodable source code
 -  with a null byte.
 +Library
 +-------
  
 -- Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
 -  rejects builtin types with not defined __new__.
++- Issue #6478: _strptime's regexp cache now is reset after changing timezone
++  with time.tzset().
 -- Issue #24802: Avoid buffer overreads when int(), float(), compile(), exec()
 -  and eval() are passed bytes-like objects.  These objects are not
 -  necessarily terminated by a null byte, but the functions assumed they were.
 +- Issue #14285: When executing a package with the "python -m package" option,
 +  and package initialization fails, a proper traceback is now reported.  The
 +  "runpy" module now lets exceptions from package initialization pass back to
 +  the caller, rather than raising ImportError.
  
 -- Issue #24402: Fix input() to prompt to the redirected stdout when
 -  sys.stdout.fileno() fails.
 +- Issue #25177: Fixed problem with the mean of very small and very large
 +  numbers. As a side effect, statistics.mean and statistics.variance should
 +  be significantly faster.
  
 -- Issue #24806: Prevent builtin types that are not allowed to be subclassed from
 -  being subclassed through multiple inheritance.
 +- Issue #25718: Fixed copying object with state with boolean value is false.
  
 -- Issue #24848: Fixed a number of bugs in UTF-7 decoding of misformed data.
 +- Issue #10131: Fixed deep copying of minidom documents.  Based on patch
 +  by Marian Ganisin.
  
 -- Issue #25280: Import trace messages emitted in verbose (-v) mode are no
 -  longer formatted twice.
 +- Issue #25725: Fixed a reference leak in pickle.loads() when unpickling
 +  invalid data including tuple instructions.
  
 -- Issue #25003: os.urandom() doesn't use getentropy() on Solaris because
 -  getentropy() is blocking, whereas os.urandom() should not block. getentropy()
 -  is supported since Solaris 11.3.
 +- Issue #25663: In the Readline completer, avoid listing duplicate global
 +  names, and search the global namespace before searching builtins.
  
 -- Issue #25182: The stdprinter (used as sys.stderr before the io module is
 -  imported at startup) now uses the backslashreplace error handler.
 +- Issue #25688: Fixed file leak in ElementTree.iterparse() raising an error.
  
 -- Issue #24891: Fix a race condition at Python startup if the file descriptor
 -  of stdin (0), stdout (1) or stderr (2) is closed while Python is creating
 -  sys.stdin, sys.stdout and sys.stderr objects. These attributes are now set
 -  to None if the creation of the object failed, instead of raising an OSError
 -  exception. Initial patch written by Marco Paolini.
 +- Issue #23914: Fixed SystemError raised by unpickler on broken pickle data.
  
 -- Issue #21167: NAN operations are now handled correctly when python is
 -  compiled with ICC even if -fp-model strict is not specified.
 +- Issue #25691: Fixed crash on deleting ElementTree.Element attributes.
  
 -- Issue #4395: Better testing and documentation of binary operators.
 -  Patch by Martin Panter.
 +- Issue #25624: ZipFile now always writes a ZIP_STORED header for directory
 +  entries.  Patch by Dingyuan Wang.
  
 -- Issue #24467: Fixed possible buffer over-read in bytearray. The bytearray
 -  object now always allocates place for trailing null byte and it's buffer now
 -  is always null-terminated.
 +Tests
 +-----
  
 -- Issue #24115: Update uses of PyObject_IsTrue(), PyObject_Not(),
 -  PyObject_IsInstance(), PyObject_RichCompareBool() and _PyDict_Contains()
 -  to check for and handle errors correctly.
 +- Issue #25616: Tests for OrderedDict are extracted from test_collections
 +  into separate file test_ordered_dict.
  
 -- Issue #24257: Fixed system error in the comparison of faked
 -  types.SimpleNamespace.
  
 -- Issue #22939: Fixed integer overflow in iterator object.  Patch by
 -  Clement Rouault.
 +What's New in Python 3.5.1 final?
 +=================================
  
 -- Issue #23985: Fix a possible buffer overrun when deleting a slice from
 -  the front of a bytearray and then appending some other bytes data.
 +Release date: 2015-12-06
  
 -- Issue #24102: Fixed exception type checking in standard error handlers.
 +Core and Builtins
 +-----------------
  
 -- Issue #23757: PySequence_Tuple() incorrectly called the concrete list API
 -  when the data was a list subclass.
 +Library
 +-------
  
 -- Issue #24407: Fix crash when dict is mutated while being updated.
 +Windows
 +-------
  
 -- Issue #24096: Make warnings.warn_explicit more robust against mutation of the
 -  warnings.filters list.
 +- Issue #25715: Python 3.5.1 installer shows wrong upgrade path and incorrect
 +  logic for launcher detection.
  
 -- Issue #23996: Avoid a crash when a delegated generator raises an
 -  unnormalized StopIteration exception.  Patch by Stefan Behnel.
 +What's New in Python 3.5.1 release candidate 1?
 +===============================================
  
 -- Issue #24022: Fix tokenizer crash when processing undecodable source code.
 +Release date: 2015-11-22
  
 -- Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
 -  while it is holding a lock to a buffered I/O object, and the main thread
 -  tries to use the same I/O object (typically stdout or stderr).  A fatal
 -  error is emitted instead.
 +Core and Builtins
 +-----------------
  
 -- Issue #22977: Fixed formatting Windows error messages on Wine.
 -  Patch by Martin Panter.
 +- Issue #25630: Fix a possible segfault during argument parsing in functions
 +  that accept filesystem paths.
  
 -- Issue #23803: Fixed str.partition() and str.rpartition() when a separator
 -  is wider then partitioned string.
 +- Issue #23564: Fixed a partially broken sanity check in the _posixsubprocess
 +  internals regarding how fds_to_pass were passed to the child.  The bug had
 +  no actual impact as subprocess.py already avoided it.
  
 -- Issue #23192: Fixed generator lambdas.  Patch by Bruno Cauet.
 +- Issue #25388: Fixed tokenizer crash when processing undecodable source code
 +  with a null byte.
  
 -- Issue #23629: Fix the default __sizeof__ implementation for variable-sized
 -  objects.
 +- Issue #25462: The hash of the key now is calculated only once in most
 +  operations in C implementation of OrderedDict.
  
 -- Issue #24044: Fix possible null pointer dereference in list.sort in out of
 -  memory conditions.
 +- Issue #22995: Default implementation of __reduce__ and __reduce_ex__ now
 +  rejects builtin types with not defined __new__.
  
 -- Issue #21354: PyCFunction_New function is exposed by python DLL again.
 +- Issue #25555: Fix parser and AST: fill lineno and col_offset of "arg" node
 +  when compiling AST from Python objects.
  
 -Library
 --------
 +- Issue #24802: Avoid buffer overreads when int(), float(), compile(), exec()
 +  and eval() are passed bytes-like objects.  These objects are not
 +  necessarily terminated by a null byte, but the functions assumed they were.
  
 -- Issue #6478: _strptime's regexp cache now is reset after changing timezone
 -  with time.tzset().
 +- Issue #24726: Fixed a crash and leaking NULL in repr() of OrderedDict that
 +  was mutated by direct calls of dict methods.
  
 -- Issue #25177: Fixed problem with the mean of very small and very large
 -  numbers. As a side effect, statistics.mean and statistics.variance should
 -  be significantly faster.
 +- Issue #25449: Iterating OrderedDict with keys with unstable hash now raises
 +  KeyError in C implementations as well as in Python implementation.
  
 -- Issue #25718: Fixed copying object with state with boolean value is false.
 +- Issue #25395: Fixed crash when highly nested OrderedDict structures were
 +  garbage collected.
  
 -- Issue #10131: Fixed deep copying of minidom documents.  Based on patch
 -  by Marian Ganisin.
 +- Issue #25274: sys.setrecursionlimit() now raises a RecursionError if the new
 +  recursion limit is too low depending at the current recursion depth. Modify
 +  also the "lower-water mark" formula to make it monotonic. This mark is used
 +  to decide when the overflowed flag of the thread state is reset.
  
 -- Issue #25725: Fixed a reference leak in pickle.loads() when unpickling
 -  invalid data including tuple instructions.
 +- Issue #24402: Fix input() to prompt to the redirected stdout when
 +  sys.stdout.fileno() fails.
  
 -- Issue #25663: In the Readline completer, avoid listing duplicate global
 -  names, and search the global namespace before searching builtins.
 +- Issue #24806: Prevent builtin types that are not allowed to be subclassed from
 +  being subclassed through multiple inheritance.
  
 -- Issue #25688: Fixed file leak in ElementTree.iterparse() raising an error.
 +- Issue #24848: Fixed a number of bugs in UTF-7 decoding of misformed data.
  
 -- Issue #23914: Fixed SystemError raised by unpickler on broken pickle data.
 +- Issue #25280: Import trace messages emitted in verbose (-v) mode are no
 +  longer formatted twice.
  
 -- Issue #25691: Fixed crash on deleting ElementTree.Element attributes.
 +- Issue #25003: On Solaris 11.3 or newer, os.urandom() now uses the
 +  getrandom() function instead of the getentropy() function. The getentropy()
 +  function is blocking to generate very good quality entropy, os.urandom()
 +  doesn't need such high-quality entropy.
  
 -- Issue #25624: ZipFile now always writes a ZIP_STORED header for directory
 -  entries.  Patch by Dingyuan Wang.
 +- Issue #25182: The stdprinter (used as sys.stderr before the io module is
 +  imported at startup) now uses the backslashreplace error handler.
 +
 +- Issue #25131: Make the line number and column offset of set/dict literals and
 +  comprehensions correspond to the opening brace.
 +
 +- Issue #25150: Hide the private _Py_atomic_xxx symbols from the public
 +  Python.h header to fix a compilation error with OpenMP. PyThreadState_GET()
 +  becomes an alias to PyThreadState_Get() to avoid ABI incompatibilies.
 +
 +Library
 +-------
 +
 +- Issue #25626: Change three zlib functions to accept sizes that fit in
 +  Py_ssize_t, but internally cap those sizes to UINT_MAX.  This resolves a
 +  regression in 3.5 where GzipFile.read() failed to read chunks larger than 2
 +  or 4 GiB.  The change affects the zlib.Decompress.decompress() max_length
 +  parameter, the zlib.decompress() bufsize parameter, and the
 +  zlib.Decompress.flush() length parameter.
  
  - Issue #25583: Avoid incorrect errors raised by os.makedirs(exist_ok=True)
    when the OS gives priority to errors such as EACCES over EEXIST.