def setUpClass(cls):
"""
Set up an HTTP server to serve the XML files. Set the correct port in
the IGD.xml URLBase element.
"""
# Have to chdir here because the py2 SimpleHTTPServer doesn't allow us
# to change its working directory like the py3 one does.
os.chdir(path.join(path.dirname(path.realpath(__file__)), 'xml'))
cls.httpd = sockserver.TCPServer(('127.0.0.1', 0), httpserver.SimpleHTTPRequestHandler)
cls.httpd_thread = threading.Thread(target=cls.httpd.serve_forever)
cls.httpd_thread.daemon = True
cls.httpd_thread.start()
cls.httpd_port = cls.httpd.server_address[1]
with open('upnp/IGD.xml', 'w') as out_f:
with open('upnp/IGD.xml.templ') as in_f:
out_f.write(in_f.read().format(port=cls.httpd_port))
评论列表
文章目录