Commit 4c545ea7 authored by Martin Panter's avatar Martin Panter

Issue #21313: Tolerate truncated buildinfo in sys.version

parent cdea4032
...@@ -1146,9 +1146,11 @@ def processor(): ...@@ -1146,9 +1146,11 @@ def processor():
### Various APIs for extracting information from sys.version ### Various APIs for extracting information from sys.version
_sys_version_parser = re.compile( _sys_version_parser = re.compile(
r'([\w.+]+)\s*' r'([\w.+]+)\s*' # "version<space>"
'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*' r'\(#?([^,]+)' # "(#buildno"
'\[([^\]]+)\]?', re.ASCII) r'(?:,\s*([\w ]*)' # ", builddate"
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"
_ironpython_sys_version_parser = re.compile( _ironpython_sys_version_parser = re.compile(
r'IronPython\s*' r'IronPython\s*'
...@@ -1227,6 +1229,8 @@ def _sys_version(sys_version=None): ...@@ -1227,6 +1229,8 @@ def _sys_version(sys_version=None):
'failed to parse Jython sys.version: %s' % 'failed to parse Jython sys.version: %s' %
repr(sys_version)) repr(sys_version))
version, buildno, builddate, buildtime, _ = match.groups() version, buildno, builddate, buildtime, _ = match.groups()
if builddate is None:
builddate = ''
compiler = sys.platform compiler = sys.platform
elif "PyPy" in sys_version: elif "PyPy" in sys_version:
...@@ -1249,7 +1253,10 @@ def _sys_version(sys_version=None): ...@@ -1249,7 +1253,10 @@ def _sys_version(sys_version=None):
version, buildno, builddate, buildtime, compiler = \ version, buildno, builddate, buildtime, compiler = \
match.groups() match.groups()
name = 'CPython' name = 'CPython'
builddate = builddate + ' ' + buildtime if builddate is None:
builddate = ''
elif buildtime:
builddate = builddate + ' ' + buildtime
if hasattr(sys, '_mercurial'): if hasattr(sys, '_mercurial'):
_, branch, revision = sys._mercurial _, branch, revision = sys._mercurial
......
...@@ -76,6 +76,22 @@ class PlatformTest(unittest.TestCase): ...@@ -76,6 +76,22 @@ class PlatformTest(unittest.TestCase):
('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')), ('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 (1.0.61005.1977) on .NET 2.0.50727.42',
('IronPython', '1.0.0', '', '', '', '', '.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 # branch and revision are not "parsed", but fetched
# from sys._mercurial. Ignore them # from sys._mercurial. Ignore them
......
...@@ -131,6 +131,9 @@ Core and Builtins ...@@ -131,6 +131,9 @@ Core and Builtins
Library Library
------- -------
- Issue #21313: Fix the "platform" module to tolerate when sys.version
contains truncated build information.
- Issue #26839: On Linux, :func:`os.urandom` now calls ``getrandom()`` with - Issue #26839: On Linux, :func:`os.urandom` now calls ``getrandom()`` with
``GRND_NONBLOCK`` to fall back on reading ``/dev/urandom`` if the urandom ``GRND_NONBLOCK`` to fall back on reading ``/dev/urandom`` if the urandom
entropy pool is not initialized yet. Patch written by Colm Buckley. entropy pool is not initialized yet. Patch written by Colm Buckley.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment