# HG changeset patch # Parent 0b15b5371c0712a78002035eb27249ed04cd7b57 Issue #21313: Tolerate truncated buildinfo in sys.version diff -r 0b15b5371c07 Lib/platform.py --- a/Lib/platform.py Wed May 25 18:17:25 2011 +0200 +++ b/Lib/platform.py Fri May 13 05:48:05 2016 +0000 @@ -1315,7 +1315,7 @@ _sys_version_parser = re.compile( r'([\w.+]+)\s*' - '\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*' + '\(#?([^,]+)(?:,\s*([\w ]*)(?:,\s*([\w :]*))?)?\)\s*' '\[([^\]]+)\]?') _ironpython_sys_version_parser = re.compile( @@ -1395,6 +1395,10 @@ 'failed to parse Jython sys.version: %s' % repr(sys_version)) version, buildno, builddate, buildtime, _ = match.groups() + if builddate is None: + builddate = '' + if buildtime is None: + buildtime = '' compiler = sys.platform elif "PyPy" in sys_version: @@ -1417,7 +1421,12 @@ version, buildno, builddate, buildtime, compiler = \ match.groups() name = 'CPython' - builddate = builddate + ' ' + buildtime + if builddate is None: + builddate = '' + if buildtime: + builddate = builddate + ' ' + buildtime + elif buildtime is None: + buildtime = '' if hasattr(sys, 'subversion'): # sys.subversion was added in Python 2.5 diff -r 0b15b5371c07 Lib/test/test_platform.py --- a/Lib/test/test_platform.py Wed May 25 18:17:25 2011 +0200 +++ b/Lib/test/test_platform.py Fri May 13 05:48:05 2016 +0000 @@ -67,6 +67,22 @@ ('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 diff -r 0b15b5371c07 Misc/NEWS --- a/Misc/NEWS Wed May 25 18:17:25 2011 +0200 +++ b/Misc/NEWS Fri May 13 05:48:05 2016 +0000 @@ -77,6 +77,9 @@ Library ------- +- Issue #21313: Fix the "platform" module to tolerate when sys.version + contains truncated build information. + - Issue #12045: Avoid duplicate execution of command in ctypes.util._get_soname(). Patch by Sijin Joseph.