From: Masashi Honma Date: Mon, 4 Feb 2019 00:13:31 +0000 (+0200) Subject: tests: urlopen() compatibility for python3 X-Git-Tag: hostap_2_8~446 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=308ecbc16edecbc80a59b692a4374177ce5a66aa;p=thirdparty%2Fhostap.git tests: urlopen() compatibility for python3 Signed-off-by: Masashi Honma --- diff --git a/tests/hwsim/test_ap_wps.py b/tests/hwsim/test_ap_wps.py index 970a8c203..e66047cbe 100644 --- a/tests/hwsim/test_ap_wps.py +++ b/tests/hwsim/test_ap_wps.py @@ -12,6 +12,7 @@ import hashlib import hmac import os import time +import sys import stat import subprocess import logging @@ -2768,7 +2769,10 @@ def ssdp_get_location(uuid): return location def upnp_get_urls(location): - conn = urlopen(location, proxies={}) + if sys.version_info[0] > 2: + conn = urlopen(location) + else: + conn = urlopen(location, proxies={}) tree = ET.parse(conn) root = tree.getroot() urn = '{urn:schemas-upnp-org:device-1-0}' @@ -2822,12 +2826,23 @@ def test_ap_wps_upnp(dev, apdev): location = ssdp_get_location(ap_uuid) urls = upnp_get_urls(location) - conn = urlopen(urls['scpd_url'], proxies={}) + if sys.version_info[0] > 2: + conn = urlopen(urls['scpd_url']) + else: + conn = urlopen(urls['scpd_url'], proxies={}) scpd = conn.read() - conn = urlopen(urljoin(location, "unknown.html"), proxies={}) - if conn.getcode() != 404: - raise Exception("Unexpected HTTP response to GET unknown URL") + if sys.version_info[0] > 2: + try: + conn = urlopen(urljoin(location, "unknown.html")) + raise Exception("Unexpected HTTP response to GET unknown URL") + except HTTPError as e: + if e.code != 404: + raise Exception("Unexpected HTTP response to GET unknown URL") + else: + conn = urlopen(urljoin(location, "unknown.html"), proxies={}) + if conn.getcode() != 404: + raise Exception("Unexpected HTTP response to GET unknown URL") url = urlparse(location) conn = HTTPConnection(url.netloc)