From 1c54f078cfd4a00cd2d231adeea1ac3a8636e259 Mon Sep 17 00:00:00 2001 From: Greg Noel Date: Tue, 30 Mar 2010 13:40:36 +0000 Subject: Only one SCons file uses urllib, and only one routine from that module, so use a simple hack to load that routine, no matter wheter it's Python 2.x or Python 3.x. Tested with Python 2.5, 2.6, and 3.0. --- bin/scons-test.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/bin/scons-test.py b/bin/scons-test.py index 0089e24..2191532 100644 --- a/bin/scons-test.py +++ b/bin/scons-test.py @@ -22,9 +22,18 @@ import os.path import sys import tempfile import time -import urllib import zipfile +try: + # try Python 3.x style + from urllib.request import urlretrieve +except ImportError: + # nope, must be 2.x; this hack is equivalent + import imp + # protect import from fixer + urlretrieve = imp.load_module('urllib', + *imp.find_module('urllib')).urlretrieve + helpstr = """\ Usage: scons-test.py [-f zipfile] [-o outdir] [-v] [--xml] [runtest arguments] Options: @@ -69,7 +78,7 @@ if not os.path.exists(tempdir): # Fetch the input file if it happens to be across a network somewhere. # Ohmigod, does Python make this simple... -inputfile, headers = urllib.urlretrieve(inputfile) +inputfile, headers = urlretrieve(inputfile) # Unzip the header file in the output directory. We use our own code # (lifted from scons-unzip.py) to make the output subdirectory name -- cgit v0.12