From 0ad9b7727d172fc772a5499da37efcc9385ed7b0 Mon Sep 17 00:00:00 2001 From: Benjamin Peterson Date: Thu, 26 Mar 2009 19:09:21 +0000 Subject: [PATCH] add support for PyPy --- Lib/platform.py | 15 +++++++++++++++ Lib/test/test_platform.py | 5 +++++ 2 files changed, 20 insertions(+) diff --git a/Lib/platform.py b/Lib/platform.py index 7863821cceb..7a6f339147e 100755 --- a/Lib/platform.py +++ b/Lib/platform.py @@ -1270,6 +1270,11 @@ _ironpython_sys_version_parser = re.compile( '(?: \(([\d\.]+)\))?' ' on (.NET [\d\.]+)') +_pypy_sys_version_parser = re.compile( + r'([\w.+]+)\s*' + '\(#?([^,]+),\s*([\w ]+),\s*([\w :]+)\)\s*' + '\[PyPy [^\]]+\]?') + _sys_version_cache = {} def _sys_version(sys_version=None): @@ -1325,6 +1330,16 @@ def _sys_version(sys_version=None): version, buildno, builddate, buildtime, _ = match.groups() compiler = sys.platform + elif "PyPy" in sys_version: + # PyPy + name = "PyPy" + match = _pypy_sys_version_parser.match(sys_version) + if match is None: + raise ValueError("failed to parse PyPy sys.version: %s" % + repr(sys_version)) + version, buildno, builddate, buildtime = match.groups() + compiler = "" + else: # CPython match = _sys_version_parser.match(sys_version) diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py index f10aa069837..0ca761c98f5 100644 --- a/Lib/test/test_platform.py +++ b/Lib/test/test_platform.py @@ -93,6 +93,11 @@ class PlatformTest(unittest.TestCase): : ("Jython", "2.5.0", "trunk", "6107", ('trunk:6107', 'Mar 26 2009'), "java1.5.0_16"), + ("2.5.2 (63378, Mar 26 2009, 18:03:29)\n[PyPy 1.0.0]", + ('PyPy', 'trunk', '63378'), self.save_platform) + : + ("PyPy", "2.5.2", "trunk", "63378", ('63378', 'Mar 26 2009'), + "") } for (version_tag, subversion, sys_platform), info in \ sys_versions.iteritems():