Risk: Medium - Hits quite a bit of different areas
Visibility: Low
utils.py
Create a wrapper for urlopen and urlretrieve to enforce a timeout
using the socket module and setsockettimeout.
- All additional files outside of utils.py are using urllib/urllib2 in
one way or another and are being changed to use our wrapper
Signed-off-by: Scott Zawalski <scottz@google.com>
git-svn-id: http://test.kernel.org/svn/autotest/trunk@1590 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/server/utils.py b/server/utils.py
index 3104842..2aef4a6 100644
--- a/server/utils.py
+++ b/server/utils.py
@@ -12,7 +12,7 @@
stutsman@google.com (Ryan Stutsman)
"""
-import atexit, os, re, shutil, textwrap, sys, tempfile, types, urllib
+import atexit, os, re, shutil, textwrap, sys, tempfile, types
from autotest_lib.client.common_lib import utils
@@ -38,6 +38,15 @@
retain_output)
+def urlopen(url, data=None, proxies=None, timeout=300):
+ return utils.urlopen(url, data=data, proxies=proxies, timeout=timeout)
+
+
+def urlretrieve(url, filename=None, reporthook=None, data=None, timeout=300):
+ return utils.urlretrieve(url, filename=filename, reporthook=reporthook,
+ data=data, timeout=timeout)
+
+
def read_keyval(path):
return utils.read_keyval(path)
@@ -129,7 +138,7 @@
# location is a URL
if location.startswith('http') or location.startswith('ftp'):
tmpfile = os.path.join(tmpdir, os.path.basename(location))
- urllib.urlretrieve(location, tmpfile)
+ utils.urlretrieve(location, tmpfile)
return tmpfile
# location is a local path
elif os.path.exists(os.path.abspath(location)):