Commit 2bcd5482 authored by Lasse Karstensen's avatar Lasse Karstensen

Convert (most) scripts to Python 3.

Missing: the development web server. I don't think that sees much use,
we can convert it to http.server when/if someone ever needs it on a box
without python2.
parent 51af9ca8
#!/usr/bin/python #!/usr/bin/env python
# #
# This is a simple web server (listening to port 5911) that takes the # This is a simple web server (listening to port 5911) that takes the
# X-UA-Device header into consideration when producing content. # X-UA-Device header into consideration when producing content.
# #
# Author: Lasse Karstensen <lkarsten@varnish-software.com>, February 2012. # Author: Lasse Karstensen <lkarsten@varnish-software.com>, February 2012.
#
from __future__ import print_function
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from socket import AF_INET6 from socket import AF_INET6
from pprint import pformat from pprint import pformat
...@@ -59,13 +61,10 @@ class requesthandler(BaseHTTPRequestHandler): ...@@ -59,13 +61,10 @@ class requesthandler(BaseHTTPRequestHandler):
self.wfile.write("<p>This page was generated %s.</p>" % (datetime.datetime.now().isoformat())) self.wfile.write("<p>This page was generated %s.</p>" % (datetime.datetime.now().isoformat()))
self.wfile.write(TAIL_CONTENT) self.wfile.write(TAIL_CONTENT)
def main(): if __name__ == "__main__":
server_address = ('', 5911) server_address = ('', 5911)
HTTPServer.allow_reuse_address = True HTTPServer.allow_reuse_address = True
HTTPServer.address_family = AF_INET6 HTTPServer.address_family = AF_INET6
httpd = HTTPServer(server_address, requesthandler) httpd = HTTPServer(server_address, requesthandler)
print "Listening on %s:%s." % server_address print("Listening on %s:%s." % server_address)
httpd.serve_forever() httpd.serve_forever()
if __name__ == "__main__":
main()
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Parse the list of manually classified User-Agent strings and Parse the list of manually classified User-Agent strings and
prepare a varnishtest test case that verifies the correct classification. prepare a varnishtest test case that verifies the correct classification.
...@@ -25,9 +25,9 @@ TAILER="""} ...@@ -25,9 +25,9 @@ TAILER="""}
client c1 -run client c1 -run
""" """
def main(): if __name__ == "__main__":
inputfile = argv[1] inputfile = argv[1]
print HEADER print(HEADER)
for line in open(inputfile): for line in open(inputfile):
line = line.strip() line = line.strip()
if line.startswith("#") or len(line) == 0: if line.startswith("#") or len(line) == 0:
...@@ -36,10 +36,8 @@ def main(): ...@@ -36,10 +36,8 @@ def main():
classid, uastring = line.split("\t", 1) classid, uastring = line.split("\t", 1)
print "\ttxreq -hdr \"User-Agent: %s\"" % uastring print("\ttxreq -hdr \"User-Agent: %s\"" % uastring)
print "\trxresp" print("\trxresp")
print "\texpect resp.http.X-UA-Device == \"%s\"\n" % classid print("\texpect resp.http.X-UA-Device == \"%s\"\n" % classid)
print TAILER print(TAILER)
if __name__ == "__main__":
main()
#!/usr/bin/env python #!/usr/bin/env python3
""" """
Pick out the examples from the installation documentation and Pick out the examples from the installation documentation and
build a VTC test case around it. build a VTC test case around it.
...@@ -60,9 +60,9 @@ def parse(inputfile): ...@@ -60,9 +60,9 @@ def parse(inputfile):
assert section is not None assert section is not None
assert line.startswith(".. endsnippet-%s" % section) assert line.startswith(".. endsnippet-%s" % section)
except AssertionError: except AssertionError:
print section, line print(section, line)
print buf print(buf)
print req print(req)
raise raise
yield section, "".join(buf), " ".join(req) yield section, "".join(buf), " ".join(req)
...@@ -82,6 +82,6 @@ if __name__ == "__main__": ...@@ -82,6 +82,6 @@ if __name__ == "__main__":
rstfile = argv[1] rstfile = argv[1]
for name, testsnippet, req in parse(rstfile): for name, testsnippet, req in parse(rstfile):
with open("snippet-%s.vtc" % name, "w+") as fp: with open("snippet-%s.vtc" % name, "w+") as fp:
print >>fp, header(name) print(header(name), file=fp)
print >>fp, testsnippet print(testsnippet, file=fp)
print >>fp, tailer(req) print(tailer(req), file=fp)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment