diff options
author | Martin Panter <vadmium+py@gmail.com> | 2016-06-08 06:12:22 (GMT) |
---|---|---|
committer | Martin Panter <vadmium+py@gmail.com> | 2016-06-08 06:12:22 (GMT) |
commit | c36364491fb5bedc736957ce123f30d8a7b7023c (patch) | |
tree | ddd0d2380fb175da5e67a05e0d5ff654b165cffa | |
parent | 05837eceec640f8e5ae15e67a1f890d89667f792 (diff) | |
download | cpython-c36364491fb5bedc736957ce123f30d8a7b7023c.zip cpython-c36364491fb5bedc736957ce123f30d8a7b7023c.tar.gz cpython-c36364491fb5bedc736957ce123f30d8a7b7023c.tar.bz2 |
Issue #21313: Tolerate truncated buildinfo in sys.version
-rwxr-xr-x | Lib/platform.py | 15 | ||||
-rw-r--r-- | Lib/test/test_platform.py | 16 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 30 insertions, 4 deletions
diff --git a/Lib/platform.py b/Lib/platform.py index 3cf2303..63455ce 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -1314,9 +1314,11 @@ def processor(): ### Various APIs for extracting information from sys.version _sys_version_parser = re.compile( - r'([\w.+]+)\s*' - '\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*' - '\[([^\]]+)\]?') + r'([\w.+]+)\s*' # "version<space>" + r'\(#?([^,]+)' # "(#buildno" + r'(?:,\s*([\w ]*)' # ", builddate" + r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>" + r'\[([^\]]+)\]?') # "[compiler]" _ironpython_sys_version_parser = re.compile( r'IronPython\s*' @@ -1395,6 +1397,8 @@ def _sys_version(sys_version=None): 'failed to parse Jython sys.version: %s' % repr(sys_version)) version, buildno, builddate, buildtime, _ = match.groups() + if builddate is None: + builddate = '' compiler = sys.platform elif "PyPy" in sys_version: @@ -1417,7 +1421,10 @@ def _sys_version(sys_version=None): version, buildno, builddate, buildtime, compiler = \ match.groups() name = 'CPython' - builddate = builddate + ' ' + buildtime + if builddate is None: + builddate = '' + elif buildtime: + builddate = builddate + ' ' + buildtime if hasattr(sys, 'subversion'): # sys.subversion was added in Python 2.5 diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index 331995f..f754550 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -67,6 +67,22 @@ class PlatformTest(unittest.TestCase): ('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')), ('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42', ('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')), + ('2.4.3 (truncation, date, t) \n[GCC]', + ('CPython', '2.4.3', '', '', 'truncation', 'date t', 'GCC')), + ('2.4.3 (truncation, date, ) \n[GCC]', + ('CPython', '2.4.3', '', '', 'truncation', 'date', 'GCC')), + ('2.4.3 (truncation, date,) \n[GCC]', + ('CPython', '2.4.3', '', '', 'truncation', 'date', 'GCC')), + ('2.4.3 (truncation, date) \n[GCC]', + ('CPython', '2.4.3', '', '', 'truncation', 'date', 'GCC')), + ('2.4.3 (truncation, d) \n[GCC]', + ('CPython', '2.4.3', '', '', 'truncation', 'd', 'GCC')), + ('2.4.3 (truncation, ) \n[GCC]', + ('CPython', '2.4.3', '', '', 'truncation', '', 'GCC')), + ('2.4.3 (truncation,) \n[GCC]', + ('CPython', '2.4.3', '', '', 'truncation', '', 'GCC')), + ('2.4.3 (truncation) \n[GCC]', + ('CPython', '2.4.3', '', '', 'truncation', '', 'GCC')), ): # branch and revision are not "parsed", but fetched # from sys.subversion. Ignore them @@ -92,6 +92,9 @@ Core and Builtins Library ------- +- Issue #21313: Fix the "platform" module to tolerate when sys.version + contains truncated build information. + - Issue #27211: Fix possible memory corruption in io.IOBase.readline(). - Issue #27114: Fix SSLContext._load_windows_store_certs fails with |