From 18121572afc08b5235308fb32d8bb8064ea736ee Mon Sep 17 00:00:00 2001 From: gregnoel Date: Tue, 30 Mar 2010 13:40:36 +0000 Subject: [PATCH] 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. git-svn-id: http://scons.tigris.org/svn/scons/trunk@4738 fdb21ef1-2011-0410-befe-b5e4ea1792b1 --- 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 0089e247..2191532c 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 -- 2.26.2