tests: urlopen() compatibility for python3
Signed-off-by: Masashi Honma <masashi.honma@gmail.com>
This commit is contained in:
parent
b7da11fd95
commit
308ecbc16e
1 changed files with 20 additions and 5 deletions
|
@ -12,6 +12,7 @@ import hashlib
|
||||||
import hmac
|
import hmac
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
import sys
|
||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
|
@ -2768,6 +2769,9 @@ def ssdp_get_location(uuid):
|
||||||
return location
|
return location
|
||||||
|
|
||||||
def upnp_get_urls(location):
|
def upnp_get_urls(location):
|
||||||
|
if sys.version_info[0] > 2:
|
||||||
|
conn = urlopen(location)
|
||||||
|
else:
|
||||||
conn = urlopen(location, proxies={})
|
conn = urlopen(location, proxies={})
|
||||||
tree = ET.parse(conn)
|
tree = ET.parse(conn)
|
||||||
root = tree.getroot()
|
root = tree.getroot()
|
||||||
|
@ -2822,9 +2826,20 @@ def test_ap_wps_upnp(dev, apdev):
|
||||||
location = ssdp_get_location(ap_uuid)
|
location = ssdp_get_location(ap_uuid)
|
||||||
urls = upnp_get_urls(location)
|
urls = upnp_get_urls(location)
|
||||||
|
|
||||||
|
if sys.version_info[0] > 2:
|
||||||
|
conn = urlopen(urls['scpd_url'])
|
||||||
|
else:
|
||||||
conn = urlopen(urls['scpd_url'], proxies={})
|
conn = urlopen(urls['scpd_url'], proxies={})
|
||||||
scpd = conn.read()
|
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={})
|
conn = urlopen(urljoin(location, "unknown.html"), proxies={})
|
||||||
if conn.getcode() != 404:
|
if conn.getcode() != 404:
|
||||||
raise Exception("Unexpected HTTP response to GET unknown URL")
|
raise Exception("Unexpected HTTP response to GET unknown URL")
|
||||||
|
|
Loading…
Reference in a new issue