From 174ef8a73e384379f8f818d049bf5a1e0c1f349a Mon Sep 17 00:00:00 2001 From: Andreas Sandberg Date: Sat, 26 Jan 2019 09:54:00 +0000 Subject: [PATCH] python: Add fallbacks for packages that have been renamed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Python 3 has restructured some packages. Specifically, __builtin__ has been renamed to builtins and urlparse has been included in urllib. Change-Id: I81f8f3942471db1043006a36abbad6e5a49e0a43 Signed-off-by: Andreas Sandberg Reviewed-on: https://gem5-review.googlesource.com/c/15994 Reviewed-by: Juha Jäykkä --- src/python/m5/stats/__init__.py | 12 ++++++++++-- src/python/m5/util/code_formatter.py | 10 +++++++--- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/python/m5/stats/__init__.py b/src/python/m5/stats/__init__.py index acb62f13e..019c7ebb8 100644 --- a/src/python/m5/stats/__init__.py +++ b/src/python/m5/stats/__init__.py @@ -71,7 +71,11 @@ def _url_factory(func): @wraps(func) def wrapper(url): - from urlparse import parse_qs + try: + from urllib.parse import parse_qs + except ImportError: + # Python 2 fallback + from urlparse import parse_qs from ast import literal_eval qs = parse_qs(url.query, keep_blank_values=True) @@ -135,7 +139,11 @@ def addStatVisitor(url): """ - from urlparse import urlsplit + try: + from urllib.parse import urlsplit + except ImportError: + # Python 2 fallback + from urlparse import urlsplit parsed = urlsplit(url) diff --git a/src/python/m5/util/code_formatter.py b/src/python/m5/util/code_formatter.py index c845c9021..21bbcd7a8 100644 --- a/src/python/m5/util/code_formatter.py +++ b/src/python/m5/util/code_formatter.py @@ -26,7 +26,11 @@ from __future__ import print_function -import __builtin__ +try: + import builtins +except ImportError: + # Python 2 fallback + import __builtin__ as builtins import inspect import os import re @@ -66,8 +70,8 @@ class lookup(object): if self.formatter.globals and item in self.frame.f_globals: return self.frame.f_globals[item] - if item in __builtin__.__dict__: - return __builtin__.__dict__[item] + if item in builtins.__dict__: + return builtins.__dict__[item] try: item = int(item) -- 2.30.2