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
# X-UA-Device header into consideration when producing content.
#
# Author: Lasse Karstensen <lkarsten@varnish-software.com>, February 2012.
#
from __future__ import print_function
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from socket import AF_INET6
from pprint import pformat
......@@ -59,13 +61,10 @@ class requesthandler(BaseHTTPRequestHandler):
self.wfile.write("<p>This page was generated %s.</p>" % (datetime.datetime.now().isoformat()))
self.wfile.write(TAIL_CONTENT)
def main():
if __name__ == "__main__":
server_address = ('', 5911)
HTTPServer.allow_reuse_address = True
HTTPServer.address_family = AF_INET6
httpd = HTTPServer(server_address, requesthandler)
print "Listening on %s:%s." % server_address
print("Listening on %s:%s." % server_address)
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
prepare a varnishtest test case that verifies the correct classification.
......@@ -25,9 +25,9 @@ TAILER="""}
client c1 -run
"""
def main():
if __name__ == "__main__":
inputfile = argv[1]
print HEADER
print(HEADER)
for line in open(inputfile):
line = line.strip()
if line.startswith("#") or len(line) == 0:
......@@ -36,10 +36,8 @@ def main():
classid, uastring = line.split("\t", 1)
print "\ttxreq -hdr \"User-Agent: %s\"" % uastring
print "\trxresp"
print "\texpect resp.http.X-UA-Device == \"%s\"\n" % classid
print TAILER
print("\ttxreq -hdr \"User-Agent: %s\"" % uastring)
print("\trxresp")
print("\texpect resp.http.X-UA-Device == \"%s\"\n" % classid)
print(TAILER)
if __name__ == "__main__":
main()
#!/usr/bin/env python
#!/usr/bin/env python3
"""
Pick out the examples from the installation documentation and
build a VTC test case around it.
......@@ -60,9 +60,9 @@ def parse(inputfile):
assert section is not None
assert line.startswith(".. endsnippet-%s" % section)
except AssertionError:
print section, line
print buf
print req
print(section, line)
print(buf)
print(req)
raise
yield section, "".join(buf), " ".join(req)
......@@ -82,6 +82,6 @@ if __name__ == "__main__":
rstfile = argv[1]
for name, testsnippet, req in parse(rstfile):
with open("snippet-%s.vtc" % name, "w+") as fp:
print >>fp, header(name)
print >>fp, testsnippet
print >>fp, tailer(req)
print(header(name), file=fp)
print(testsnippet, file=fp)
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