This patch is made by using 2to3 command with some modifications. $ find . -name *.py | xargs 2to3 -f imports -w -n Signed-off-by: Masashi Honma <masashi.honma@xxxxxxxxx> --- tests/hwsim/p2p_utils.py | 9 +- tests/hwsim/test_ap_eap.py | 5 +- tests/hwsim/test_ap_wps.py | 148 ++++++++++++++------------- tests/hwsim/test_p2p_wifi_display.py | 5 +- 4 files changed, 92 insertions(+), 75 deletions(-) diff --git a/tests/hwsim/p2p_utils.py b/tests/hwsim/p2p_utils.py index 1a4646dc7..6c8a3cc4b 100644 --- a/tests/hwsim/p2p_utils.py +++ b/tests/hwsim/p2p_utils.py @@ -8,7 +8,10 @@ import logging logger = logging.getLogger() import threading import time -import Queue +try: + from Queue import Queue +except ImportError: + from queue import Queue import hwsim_utils @@ -238,7 +241,7 @@ def go_neg_pin(i_dev, r_dev, i_intent=None, r_intent=None, i_method='enter', r_m pin = r_dev.wps_read_pin() logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.dump_monitor() - res = Queue.Queue() + res = queue.Queue() t = threading.Thread(target=go_neg_init, args=(i_dev, r_dev, pin, i_method, i_intent, res)) t.start() logger.debug("Wait for GO Negotiation Request on r_dev") @@ -318,7 +321,7 @@ def go_neg_pbc(i_dev, r_dev, i_intent=None, r_intent=None, i_freq=None, r_freq=N i_dev.p2p_find(social=True) logger.info("Start GO negotiation " + i_dev.ifname + " -> " + r_dev.ifname) r_dev.dump_monitor() - res = Queue.Queue() + res = queue.Queue() t = threading.Thread(target=go_neg_init_pbc, args=(i_dev, r_dev, i_intent, res, i_freq, provdisc)) t.start() logger.debug("Wait for GO Negotiation Request on r_dev") diff --git a/tests/hwsim/test_ap_eap.py b/tests/hwsim/test_ap_eap.py index c190cf484..f40be0c55 100644 --- a/tests/hwsim/test_ap_eap.py +++ b/tests/hwsim/test_ap_eap.py @@ -14,7 +14,10 @@ logger = logging.getLogger() import os import signal import socket -import SocketServer +try: + import SocketServer +except ImportError: + import socketserver as SocketServer import struct import tempfile diff --git a/tests/hwsim/test_ap_wps.py b/tests/hwsim/test_ap_wps.py index fe069d396..b41a53be9 100644 --- a/tests/hwsim/test_ap_wps.py +++ b/tests/hwsim/test_ap_wps.py @@ -19,12 +19,20 @@ logger = logging.getLogger() import re import socket import struct -import httplib -import urlparse +try: + from http.client import HTTPConnection + from urllib.parse import urlparse, urljoin + from urllib.error import HTTPError + from io import StringIO + from socketserver import StreamRequestHandler, TCPServer +except ImportError: + from httplib import HTTPConnection + from urlparse import urlparse, urljoin + from urllib2 import build_opener, ProxyHandler, HTTPError + from StringIO import StringIO + from SocketServer import StreamRequestHandler, TCPServer import urllib import xml.etree.ElementTree as ET -import StringIO -import SocketServer import hwsim_utils import hostapd @@ -2351,13 +2359,13 @@ def test_ap_wps_pbc_timeout(dev, apdev, params): location = ssdp_get_location(ap_uuid) urls = upnp_get_urls(location) - eventurl = urlparse.urlparse(urls['event_sub_url']) - ctrlurl = urlparse.urlparse(urls['control_url']) + eventurl = urllib.parse.urlparse(urls['event_sub_url']) + ctrlurl = urllib.parse.urlparse(urls['control_url']) - url = urlparse.urlparse(location) - conn = httplib.HTTPConnection(url.netloc) + url = urllib.parse.urlparse(location) + conn = http.client.HTTPConnection(url.netloc) - class WPSERHTTPServer(SocketServer.StreamRequestHandler): + class WPSERHTTPServer(socketserver.StreamRequestHandler): def handle(self): data = self.rfile.readline().strip() logger.debug(data) @@ -2764,9 +2772,9 @@ def upnp_get_urls(location): urn = '{urn:schemas-upnp-org:device-1-0}' service = root.find("./" + urn + "device/" + urn + "serviceList/" + urn + "service") res = {} - res['scpd_url'] = urlparse.urljoin(location, service.find(urn + 'SCPDURL').text) - res['control_url'] = urlparse.urljoin(location, service.find(urn + 'controlURL').text) - res['event_sub_url'] = urlparse.urljoin(location, service.find(urn + 'eventSubURL').text) + res['scpd_url'] = urllib.parse.urljoin(location, service.find(urn + 'SCPDURL').text) + res['control_url'] = urllib.parse.urljoin(location, service.find(urn + 'controlURL').text) + res['event_sub_url'] = urllib.parse.urljoin(location, service.find(urn + 'eventSubURL').text) return res def upnp_soap_action(conn, path, action, include_soap_action=True, @@ -2791,7 +2799,7 @@ def upnp_soap_action(conn, path, action, include_soap_action=True, msg = ET.SubElement(act, "NewWLANEventMAC") msg.text = neweventmac tree = ET.ElementTree(root) - soap = StringIO.StringIO() + soap = io.StringIO() tree.write(soap, xml_declaration=True, encoding='utf-8') headers = { "Content-type": 'text/xml; charset="utf-8"' } @@ -2813,13 +2821,13 @@ def test_ap_wps_upnp(dev, apdev): conn = urllib.urlopen(urls['scpd_url'], proxies={}) scpd = conn.read() - conn = urllib.urlopen(urlparse.urljoin(location, "unknown.html"), + conn = urllib.urlopen(urllib.parse.urljoin(location, "unknown.html"), proxies={}) if conn.getcode() != 404: raise Exception("Unexpected HTTP response to GET unknown URL") - url = urlparse.urlparse(location) - conn = httplib.HTTPConnection(url.netloc) + url = urllib.parse.urlparse(location) + conn = http.client.HTTPConnection(url.netloc) #conn.set_debuglevel(1) headers = { "Content-type": 'text/xml; charset="utf-8"', "SOAPAction": '"urn:schemas-wifialliance-org:service:WFAWLANConfig:1#GetDeviceInfo"' } @@ -2835,7 +2843,7 @@ def test_ap_wps_upnp(dev, apdev): headers = { "Content-type": 'text/xml; charset="utf-8"', "SOAPAction": '"urn:some-unknown-action#GetDeviceInfo"' } - ctrlurl = urlparse.urlparse(urls['control_url']) + ctrlurl = urllib.parse.urlparse(urls['control_url']) conn.request("POST", ctrlurl.path, "\r\n\r\n", headers) resp = conn.getresponse() if resp.status != 401: @@ -2892,10 +2900,10 @@ def test_ap_wps_upnp_subscribe(dev, apdev): location = ssdp_get_location(ap_uuid) urls = upnp_get_urls(location) - eventurl = urlparse.urlparse(urls['event_sub_url']) + eventurl = urllib.parse.urlparse(urls['event_sub_url']) - url = urlparse.urlparse(location) - conn = httplib.HTTPConnection(url.netloc) + url = urllib.parse.urlparse(location) + conn = http.client.HTTPConnection(url.netloc) #conn.set_debuglevel(1) headers = { "callback": '<http://127.0.0.1:12345/event>', "timeout": "Second-1234" } @@ -3241,9 +3249,9 @@ def test_ap_wps_upnp_subscribe_events(dev, apdev): location = ssdp_get_location(ap_uuid) urls = upnp_get_urls(location) - eventurl = urlparse.urlparse(urls['event_sub_url']) + eventurl = urllib.parse.urlparse(urls['event_sub_url']) - class WPSERHTTPServer(SocketServer.StreamRequestHandler): + class WPSERHTTPServer(socketserver.StreamRequestHandler): def handle(self): data = self.rfile.readline().strip() logger.debug(data) @@ -3252,8 +3260,8 @@ def test_ap_wps_upnp_subscribe_events(dev, apdev): server = MyTCPServer(("127.0.0.1", 12345), WPSERHTTPServer) server.timeout = 1 - url = urlparse.urlparse(location) - conn = httplib.HTTPConnection(url.netloc) + url = urllib.parse.urlparse(location) + conn = http.client.HTTPConnection(url.netloc) headers = { "callback": '<http://127.0.0.1:12345/event>', "NT": "upnp:event", @@ -3308,8 +3316,8 @@ def test_ap_wps_upnp_http_proto(dev, apdev): location = ssdp_get_location(ap_uuid) - url = urlparse.urlparse(location) - conn = httplib.HTTPConnection(url.netloc, timeout=0.2) + url = urllib.parse.urlparse(location) + conn = http.client.HTTPConnection(url.netloc, timeout=0.2) #conn.set_debuglevel(1) conn.request("HEAD", "hello") @@ -3407,8 +3415,8 @@ def test_ap_wps_upnp_http_proto_chunked(dev, apdev): location = ssdp_get_location(ap_uuid) - url = urlparse.urlparse(location) - conn = httplib.HTTPConnection(url.netloc) + url = urllib.parse.urlparse(location) + conn = http.client.HTTPConnection(url.netloc) #conn.set_debuglevel(1) headers = { "Transfer-Encoding": 'chunked' } @@ -4079,7 +4087,7 @@ def gen_wps_event(sid='uuid:7eb3342a-8a5f-47fe-a585-0785bfec6d8a'): 'Date: Sat, 15 Aug 2015 18:55:08 GMT\r\n\r\n' return hdr + payload -class WPSAPHTTPServer(SocketServer.StreamRequestHandler): +class WPSAPHTTPServer(StreamRequestHandler): def handle(self): data = self.rfile.readline().strip() logger.info("HTTP server received: " + data) @@ -4113,10 +4121,10 @@ class WPSAPHTTPServer(SocketServer.StreamRequestHandler): def handle_others(self, data): logger.info("Ignore HTTP request: " + data) -class MyTCPServer(SocketServer.TCPServer): +class MyTCPServer(TCPServer): def __init__(self, addr, handler): self.allow_reuse_address = True - SocketServer.TCPServer.__init__(self, addr, handler) + socketserver.TCPServer.__init__(self, addr, handler) def wps_er_start(dev, http_server, max_age=1, wait_m_search=False, location_url=None): @@ -4184,7 +4192,7 @@ def run_wps_er_proto_test(dev, handler, no_event_url=False, location_url=None): dev.request("WPS_ER_STOP") def send_wlanevent(url, uuid, data, no_response=False): - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) payload = '''<?xml version="1.0" encoding="utf-8"?> <e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"> <e:property><STAStatus>1</STAStatus></e:property> @@ -4239,8 +4247,8 @@ def _test_ap_wps_er_http_proto(dev, apdev): sock.close() logger.info("Valid Probe Request notification") - url = urlparse.urlparse(wps_event_url) - conn = httplib.HTTPConnection(url.netloc) + url = urllib.parse.urlparse(wps_event_url) + conn = http.client.HTTPConnection(url.netloc) payload = '''<?xml version="1.0" encoding="utf-8"?> <e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"> <e:property><STAStatus>1</STAStatus></e:property> @@ -4270,32 +4278,32 @@ RGV2aWNlIEEQSQAGADcqAAEg raise Exception("No Enrollee UUID match") logger.info("Incorrect event URL AP id") - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) conn.request("NOTIFY", url.path + '123', payload, headers) resp = conn.getresponse() if resp.status != 404: raise Exception("Unexpected HTTP response: %d" % resp.status) logger.info("Missing AP id") - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) conn.request("NOTIFY", '/event/' + url.path.split('/')[2], payload, headers) time.sleep(0.1) logger.info("Incorrect event URL event id") - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) conn.request("NOTIFY", '/event/123456789/123', payload, headers) time.sleep(0.1) logger.info("Incorrect event URL prefix") - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) conn.request("NOTIFY", '/foobar/123456789/123', payload, headers) resp = conn.getresponse() if resp.status != 404: raise Exception("Unexpected HTTP response: %d" % resp.status) logger.info("Unsupported request") - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) conn.request("FOOBAR", '/foobar/123456789/123', payload, headers) resp = conn.getresponse() if resp.status != 501: @@ -4303,7 +4311,7 @@ RGV2aWNlIEEQSQAGADcqAAEg logger.info("Unsupported request and OOM") with alloc_fail(dev[0], 1, "wps_er_http_req"): - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) conn.request("FOOBAR", '/foobar/123456789/123', payload, headers) time.sleep(0.5) @@ -4543,7 +4551,7 @@ RGV2aWNlIEEQSQAGADcqAAEg pass sock.close() - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) payload = '<foo' headers = { "Content-type": 'text/xml; charset="utf-8"', "Server": "Unspecified, UPnP/1.0, Unspecified", @@ -4557,7 +4565,7 @@ RGV2aWNlIEEQSQAGADcqAAEg if resp.status != 200: raise Exception("Unexpected HTTP response: %d" % resp.status) - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) payload = '<WLANEvent foo></WLANEvent>' headers = { "Content-type": 'text/xml; charset="utf-8"', "Server": "Unspecified, UPnP/1.0, Unspecified", @@ -4590,7 +4598,7 @@ RGV2aWNlIEEQSQAGADcqAAEg send_wlanevent(url, uuid, m1, no_response=True) with alloc_fail(dev[0], 1, "wps_er_http_resp_not_found"): - url2 = urlparse.urlparse(wps_event_url.replace('/event/', '/notfound/')) + url2 = urllib.parse.urlparse(wps_event_url.replace('/event/', '/notfound/')) send_wlanevent(url2, uuid, m1, no_response=True) logger.info("EAP message: M1") @@ -4822,7 +4830,7 @@ def _test_ap_wps_http_timeout(dev, apdev): add_ssdp_ap(apdev[0], ap_uuid) location = ssdp_get_location(ap_uuid) - url = urlparse.urlparse(location) + url = urllib.parse.urlparse(location) addr = (url.hostname, url.port) logger.debug("Open HTTP connection to hostapd, but do not complete request") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM, @@ -4830,7 +4838,7 @@ def _test_ap_wps_http_timeout(dev, apdev): sock.connect(addr) sock.send("G") - class DummyServer(SocketServer.StreamRequestHandler): + class DummyServer(socketserver.StreamRequestHandler): def handle(self): logger.debug("DummyServer - start 31 sec wait") time.sleep(31) @@ -5927,12 +5935,12 @@ def test_ap_wps_set_selected_registrar_proto(dev, apdev): location = ssdp_get_location(ap_uuid) urls = upnp_get_urls(location) - eventurl = urlparse.urlparse(urls['event_sub_url']) - ctrlurl = urlparse.urlparse(urls['control_url']) - url = urlparse.urlparse(location) - conn = httplib.HTTPConnection(url.netloc) + eventurl = urllib.parse.urlparse(urls['event_sub_url']) + ctrlurl = urllib.parse.urlparse(urls['control_url']) + url = urllib.parse.urlparse(location) + conn = http.client.HTTPConnection(url.netloc) - class WPSERHTTPServer(SocketServer.StreamRequestHandler): + class WPSERHTTPServer(socketserver.StreamRequestHandler): def handle(self): data = self.rfile.readline().strip() logger.debug(data) @@ -9269,12 +9277,12 @@ def test_ap_wps_upnp_web_oom(dev, apdev, params): hapd = add_ssdp_ap(apdev[0], ap_uuid) location = ssdp_get_location(ap_uuid) - url = urlparse.urlparse(location) + url = urllib.parse.urlparse(location) urls = upnp_get_urls(location) - eventurl = urlparse.urlparse(urls['event_sub_url']) - ctrlurl = urlparse.urlparse(urls['control_url']) + eventurl = urllib.parse.urlparse(urls['event_sub_url']) + ctrlurl = urllib.parse.urlparse(urls['control_url']) - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) with alloc_fail(hapd, 1, "web_connection_parse_get"): conn.request("GET", "/wps_device.xml") try: @@ -9282,7 +9290,7 @@ def test_ap_wps_upnp_web_oom(dev, apdev, params): except: pass - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) conn.request("GET", "/unknown") resp = conn.getresponse() if resp.status != 404: @@ -9296,56 +9304,56 @@ def test_ap_wps_upnp_web_oom(dev, apdev, params): except: pass - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) conn.request("GET", "/wps_device.xml") resp = conn.getresponse() if resp.status != 200: raise Exception("GET /wps_device.xml failed") - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") if resp.status != 200: raise Exception("GetDeviceInfo failed") with alloc_fail(hapd, 1, "web_process_get_device_info"): - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") if resp.status != 500: raise Exception("Internal error not reported from GetDeviceInfo OOM") with alloc_fail(hapd, 1, "wps_build_m1;web_process_get_device_info"): - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") if resp.status != 500: raise Exception("Internal error not reported from GetDeviceInfo OOM") with alloc_fail(hapd, 1, "wpabuf_alloc;web_connection_send_reply"): - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) try: resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") except: pass - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) resp = upnp_soap_action(conn, ctrlurl.path, "GetDeviceInfo") if resp.status != 200: raise Exception("GetDeviceInfo failed") # No NewWLANEventType in PutWLANResponse NewMessage - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", newmsg="foo") if resp.status != 600: raise Exception("Unexpected HTTP response: %d" % resp.status) # No NewWLANEventMAC in PutWLANResponse NewMessage - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", newmsg="foo", neweventtype="1") if resp.status != 600: raise Exception("Unexpected HTTP response: %d" % resp.status) # Invalid NewWLANEventMAC in PutWLANResponse NewMessage - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", newmsg="foo", neweventtype="1", neweventmac="foo") @@ -9354,7 +9362,7 @@ def test_ap_wps_upnp_web_oom(dev, apdev, params): # Workaround for NewWLANEventMAC in PutWLANResponse NewMessage # Ignored unexpected PutWLANResponse WLANEventType 1 - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", newmsg="foo", neweventtype="1", neweventmac="00.11.22.33.44.55") @@ -9362,7 +9370,7 @@ def test_ap_wps_upnp_web_oom(dev, apdev, params): raise Exception("Unexpected HTTP response: %d" % resp.status) # PutWLANResponse NewMessage with invalid EAP message - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) resp = upnp_soap_action(conn, ctrlurl.path, "PutWLANResponse", newmsg="foo", neweventtype="2", neweventmac="00:11:22:33:44:55") @@ -9370,7 +9378,7 @@ def test_ap_wps_upnp_web_oom(dev, apdev, params): raise Exception("Unexpected HTTP response: %d" % resp.status) with alloc_fail(hapd, 1, "web_connection_parse_subscribe"): - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) headers = { "callback": '<http://127.0.0.1:12345/event>', "NT": "upnp:event", "timeout": "Second-1234" } @@ -9381,7 +9389,7 @@ def test_ap_wps_upnp_web_oom(dev, apdev, params): pass with alloc_fail(hapd, 1, "dup_binstr;web_connection_parse_subscribe"): - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) headers = { "callback": '<http://127.0.0.1:12345/event>', "NT": "upnp:event", "timeout": "Second-1234" } @@ -9391,7 +9399,7 @@ def test_ap_wps_upnp_web_oom(dev, apdev, params): raise Exception("Unexpected HTTP response: %d" % resp.status) with alloc_fail(hapd, 1, "wpabuf_alloc;web_connection_parse_unsubscribe"): - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) headers = { "callback": '<http://127.0.0.1:12345/event>', "NT": "upnp:event", "timeout": "Second-1234" } @@ -9402,7 +9410,7 @@ def test_ap_wps_upnp_web_oom(dev, apdev, params): pass with alloc_fail(hapd, 1, "web_connection_unimplemented"): - conn = httplib.HTTPConnection(url.netloc) + conn = http.client.HTTPConnection(url.netloc) conn.request("HEAD", "/wps_device.xml") try: resp = conn.getresponse() diff --git a/tests/hwsim/test_p2p_wifi_display.py b/tests/hwsim/test_p2p_wifi_display.py index b032c4f42..d5179d8e7 100644 --- a/tests/hwsim/test_p2p_wifi_display.py +++ b/tests/hwsim/test_p2p_wifi_display.py @@ -9,7 +9,10 @@ import logging logger = logging.getLogger() import time import threading -import Queue +try: + from Queue import Queue +except ImportError: + from queue import Queue import hwsim_utils import utils -- 2.17.1 _______________________________________________ Hostap mailing list Hostap@xxxxxxxxxxxxxxxxxxx http://lists.infradead.org/mailman/listinfo/hostap