Patch #1276356: Implement new resource "urlfetch" for regrtest.
This enables even impatient people to run tests that require remote
files such as test_normalization and test_codecmaps_*.
diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py
index a296caf..bec1a0f 100644
--- a/Lib/test/test_support.py
+++ b/Lib/test/test_support.py
@@ -237,7 +237,21 @@
else:
print 'Missing SyntaxError: "%s"' % statement
+def open_urlresource(url):
+ import urllib, urlparse
+ import os.path
+ filename = urlparse.urlparse(url)[2].split('/')[-1] # '/': it's URL!
+
+ for path in [os.path.curdir, os.path.pardir]:
+ fn = os.path.join(path, filename)
+ if os.path.exists(fn):
+ return open(fn)
+
+ requires('urlfetch')
+ print >> get_original_stdout(), '\tfetching %s ...' % url
+ fn, _ = urllib.urlretrieve(url, filename)
+ return open(fn)
#=======================================================================
# Preliminary PyUNIT integration.