diff options
author | Stefan Zimmermann <zimmermann.code@gmail.com> | 2014-01-08 13:25:16 (GMT) |
---|---|---|
committer | Stefan Zimmermann <zimmermann.code@gmail.com> | 2014-01-08 13:25:16 (GMT) |
commit | 26003a0bd3168f8c2ee3d92a26d35ca977f8e25b (patch) | |
tree | 5f61654ad672dbaaef043c67f2d5b74254e2abca | |
parent | 59ee07b24ed1278d83aa70605f51b6284aa60a82 (diff) | |
download | SCons-26003a0bd3168f8c2ee3d92a26d35ca977f8e25b.zip SCons-26003a0bd3168f8c2ee3d92a26d35ca977f8e25b.tar.gz SCons-26003a0bd3168f8c2ee3d92a26d35ca977f8e25b.tar.bz2 |
Some more six.PY2/PY3 usage.
-rw-r--r-- | bin/install_scons.py | 6 | ||||
-rw-r--r-- | review.py | 14 | ||||
-rwxr-xr-x | runtest.py | 6 | ||||
-rw-r--r-- | 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 @@ -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, @@ -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): |