提交 699e55af 编写于 作者: C Cleber Rosa

Python 3: adapt avocado.utils.asset and avocado.utils.download

By mapping to urlparse* and urllib* libraries from appropriate
locations.
Signed-off-by: NCleber Rosa <crosa@redhat.com>
上级 a17711ee
......@@ -25,7 +25,11 @@ import stat
import sys
import time
import tempfile
import urlparse
try:
import urlparse
except ImportError:
import urllib.parse as urlparse
from . import crypto
from . import path as utils_path
......
......@@ -21,7 +21,11 @@ import logging
import os
import socket
import shutil
import urllib2
try:
from urllib2 import urlopen
except ImportError:
from urllib.request import urlopen
from . import aurl
from . import output
......@@ -44,7 +48,7 @@ def url_open(url, data=None, timeout=5):
old_timeout = socket.getdefaulttimeout()
socket.setdefaulttimeout(timeout)
try:
return urllib2.urlopen(url, data=data)
return urlopen(url, data=data)
finally:
socket.setdefaulttimeout(old_timeout)
......@@ -87,7 +91,7 @@ def url_download_interactive(url, output_file, title='', chunk_size=102400):
"""
output_dir = os.path.dirname(output_file)
output_file = open(output_file, 'w+b')
input_file = urllib2.urlopen(url)
input_file = urlopen(url)
try:
file_size = int(input_file.headers['Content-Length'])
......
import json
import unittest
import urllib2
try:
from urllib2 import URLError
except ImportError:
from urllib.error import URLError
from avocado.utils import download
......@@ -22,7 +26,7 @@ class TestThirdPartyBugs(unittest.TestCase):
'change the avocado.conf option '
'"reject_unknown_hosts" defaults to True.' %
'https://github.com/paramiko/paramiko/issues/243')
except urllib2.URLError as details:
except URLError as details:
raise unittest.SkipTest(details)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册