summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Zimmermann <zimmermann.code@gmail.com>2014-01-08 13:25:16 +0000
committerStefan Zimmermann <zimmermann.code@gmail.com>2014-01-08 13:25:16 +0000
commit0605d2e54160580d65ed2e4f6f587e10876d32a8 (patch)
tree5f61654ad672dbaaef043c67f2d5b74254e2abca
parent78ce49b5b52d41ddccf41986faba5f1d2ddc8804 (diff)
downloadscons-0605d2e54160580d65ed2e4f6f587e10876d32a8.tar.gz
Some more six.PY2/PY3 usage.
-rw-r--r--bin/install_scons.py6
-rw-r--r--review.py14
-rwxr-xr-xruntest.py6
-rw-r--r--src/engine/SCons/Util.py11
4 files changed, 20 insertions, 17 deletions
diff --git a/bin/install_scons.py b/bin/install_scons.py
index 7a39e963..afd0789c 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 c01472eb..9f1ba820 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 2470a618..63802928 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 7ea27891..052b3fc9 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):