From 26003a0bd3168f8c2ee3d92a26d35ca977f8e25b Mon Sep 17 00:00:00 2001 From: Stefan Zimmermann Date: Wed, 8 Jan 2014 13:25:16 +0000 Subject: Some more six.PY2/PY3 usage. --- bin/install_scons.py | 6 ++++-- review.py | 14 ++++++++------ runtest.py | 6 ++++-- src/engine/SCons/Util.py | 11 ++++------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/bin/install_scons.py b/bin/install_scons.py index 7a39e96..afd0789 100644 --- a/bin/install_scons.py +++ b/bin/install_scons.py @@ -19,14 +19,16 @@ # hierarchy. from __future__ import print_function +from six import PY3 + import getopt import os import shutil import sys import tarfile -try: +if PY3: from urllib.request import urlretrieve -except ImportError: # Python < 3 +else: from urllib import urlretrieve from Command import CommandRunner, Usage diff --git a/review.py b/review.py index c01472e..9f1ba82 100644 --- a/review.py +++ b/review.py @@ -15,6 +15,8 @@ # limitations under the License. from __future__ import print_function +from six import PY3 + """Tool for uploading diffs from a version control system to the codereview app. Usage summary: upload.py [options] [-- diff_options] [path...] @@ -32,14 +34,14 @@ against by using the '--rev' option. # This code is derived from appcfg.py in the App Engine SDK (open source), # and from ASPN recipe #146306. -try: +if PY3: from configparser import ConfigParser -except ImportError: # Python < 3 +else: from ConfigParser import ConfigParser -try: +if PY3: from http.cookiejar import ( CookieJar, MozillaCookieJar, LoadError as CookieLoadError) -except ImportError: # Python < 3 +else: from cookielib import ( CookieJar, MozillaCookieJar, LoadError as CookieLoadError) import fnmatch @@ -52,7 +54,7 @@ import re import socket import subprocess import sys -try: +if PY3: from urllib.request import ( Request, OpenerDirector, ProxyHandler, UnknownHandler, HTTPHandler, HTTPSHandler, @@ -61,7 +63,7 @@ try: from urllib.error import HTTPError from urllib.parse import ( urlencode, urlparse, urlunparse, splituser as urlsplituser) -except ImportError: # Python < 3 +else: from urllib2 import ( Request, OpenerDirector, ProxyHandler, UnknownHandler, HTTPHandler, HTTPSHandler, diff --git a/runtest.py b/runtest.py index 2470a61..6380292 100755 --- a/runtest.py +++ b/runtest.py @@ -85,6 +85,8 @@ # rather than reinventing that wheel.) from __future__ import print_function +from six import PY3 + import getopt import glob import os @@ -95,9 +97,9 @@ import time try: import threading - try: + if PY3: from queue import Queue - except ImportError: # Python < 3 + else: from Queue import Queue threading_ok = True except ImportError: diff --git a/src/engine/SCons/Util.py b/src/engine/SCons/Util.py index 7ea2789..052b3fc 100644 --- a/src/engine/SCons/Util.py +++ b/src/engine/SCons/Util.py @@ -33,24 +33,21 @@ import copy import re import types -try: +if PY3: from collections import UserDict, UserList, UserString -except ImportError: # Python < 3 +else: from UserDict import UserDict from UserList import UserList from UserString import UserString # Don't "from types import ..." these because we need to get at the # types module later to look for UnicodeType. -try: - InstanceType = types.InstanceType -except AttributeError: # Python 3 - InstanceType = None +InstanceType = types.InstanceType if PY2 else None MethodType = types.MethodType FunctionType = types.FunctionType try: unicode except NameError: UnicodeType = None -else: UnicodeType = str +else: UnicodeType = unicode def dictify(keys, values, result={}): for k, v in zip(keys, values): -- cgit v0.12