Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e50553

Browse files
committed
Issue #21313: Tolerate truncated buildinfo in sys.version
1 parent 1bf197e commit 4e50553

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

Lib/platform.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,9 +1146,11 @@ def processor():
11461146
### Various APIs for extracting information from sys.version
11471147

11481148
_sys_version_parser = re.compile(
1149-
r'([\w.+]+)\s*'
1150-
'\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*'
1151-
'\[([^\]]+)\]?', re.ASCII)
1149+
r'([\w.+]+)\s*' # "version<space>"
1150+
r'\(#?([^,]+)' # "(#buildno"
1151+
r'(?:,\s*([\w ]*)' # ", builddate"
1152+
r'(?:,\s*([\w :]*))?)?\)\s*' # ", buildtime)<space>"
1153+
r'\[([^\]]+)\]?', re.ASCII) # "[compiler]"
11521154

11531155
_ironpython_sys_version_parser = re.compile(
11541156
r'IronPython\s*'
@@ -1227,6 +1229,8 @@ def _sys_version(sys_version=None):
12271229
'failed to parse Jython sys.version: %s' %
12281230
repr(sys_version))
12291231
version, buildno, builddate, buildtime, _ = match.groups()
1232+
if builddate is None:
1233+
builddate = ''
12301234
compiler = sys.platform
12311235

12321236
elif "PyPy" in sys_version:
@@ -1249,7 +1253,10 @@ def _sys_version(sys_version=None):
12491253
version, buildno, builddate, buildtime, compiler = \
12501254
match.groups()
12511255
name = 'CPython'
1252-
builddate = builddate + ' ' + buildtime
1256+
if builddate is None:
1257+
builddate = ''
1258+
elif buildtime:
1259+
builddate = builddate + ' ' + buildtime
12531260

12541261
if hasattr(sys, '_mercurial'):
12551262
_, branch, revision = sys._mercurial

Lib/test/test_platform.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ def test_sys_version(self):
7676
('IronPython', '1.0.60816', '', '', '', '', '.NET 2.0.50727.42')),
7777
('IronPython 1.0 (1.0.61005.1977) on .NET 2.0.50727.42',
7878
('IronPython', '1.0.0', '', '', '', '', '.NET 2.0.50727.42')),
79+
('2.4.3 (truncation, date, t) \n[GCC]',
80+
('CPython', '2.4.3', '', '', 'truncation', 'date t', 'GCC')),
81+
('2.4.3 (truncation, date, ) \n[GCC]',
82+
('CPython', '2.4.3', '', '', 'truncation', 'date', 'GCC')),
83+
('2.4.3 (truncation, date,) \n[GCC]',
84+
('CPython', '2.4.3', '', '', 'truncation', 'date', 'GCC')),
85+
('2.4.3 (truncation, date) \n[GCC]',
86+
('CPython', '2.4.3', '', '', 'truncation', 'date', 'GCC')),
87+
('2.4.3 (truncation, d) \n[GCC]',
88+
('CPython', '2.4.3', '', '', 'truncation', 'd', 'GCC')),
89+
('2.4.3 (truncation, ) \n[GCC]',
90+
('CPython', '2.4.3', '', '', 'truncation', '', 'GCC')),
91+
('2.4.3 (truncation,) \n[GCC]',
92+
('CPython', '2.4.3', '', '', 'truncation', '', 'GCC')),
93+
('2.4.3 (truncation) \n[GCC]',
94+
('CPython', '2.4.3', '', '', 'truncation', '', 'GCC')),
7995
):
8096
# branch and revision are not "parsed", but fetched
8197
# from sys._mercurial. Ignore them

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ Core and Builtins
131131
Library
132132
-------
133133

134+
- Issue #21313: Fix the "platform" module to tolerate when sys.version
135+
contains truncated build information.
136+
134137
- Issue #26839: On Linux, :func:`os.urandom` now calls ``getrandom()`` with
135138
``GRND_NONBLOCK`` to fall back on reading ``/dev/urandom`` if the urandom
136139
entropy pool is not initialized yet. Patch written by Colm Buckley.

0 commit comments

Comments
 (0)