tests: urlopen() compatibility for python3

Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
This commit is contained in:
Masashi Honma 2019-02-04 02:13:31 +02:00 committed by Jouni Malinen
parent b7da11fd95
commit 308ecbc16e

View file

@ -12,6 +12,7 @@ import hashlib
import hmac
import os
import time
import sys
import stat
import subprocess
import logging
@ -2768,6 +2769,9 @@ def ssdp_get_location(uuid):
return location
def upnp_get_urls(location):
if sys.version_info[0] > 2:
conn = urlopen(location)
else:
conn = urlopen(location, proxies={})
tree = ET.parse(conn)
root = tree.getroot()
@ -2822,9 +2826,20 @@ def test_ap_wps_upnp(dev, apdev):
location = ssdp_get_location(ap_uuid)
urls = upnp_get_urls(location)
if sys.version_info[0] > 2:
conn = urlopen(urls['scpd_url'])
else:
conn = urlopen(urls['scpd_url'], proxies={})
scpd = conn.read()
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")