Skip to content

Commit 2bcd548

Browse files
committed
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.
1 parent 51af9ca commit 2bcd548

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

backend/example-backend.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
#!/usr/bin/python
1+
#!/usr/bin/env python
22
#
33
# This is a simple web server (listening to port 5911) that takes the
44
# X-UA-Device header into consideration when producing content.
55
#
66
# Author: Lasse Karstensen <[email protected]>, February 2012.
7+
#
8+
from __future__ import print_function
79
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
810
from socket import AF_INET6
911
from pprint import pformat
@@ -59,13 +61,10 @@ def do_GET(self):
5961
self.wfile.write("<p>This page was generated %s.</p>" % (datetime.datetime.now().isoformat()))
6062
self.wfile.write(TAIL_CONTENT)
6163

62-
def main():
64+
if __name__ == "__main__":
6365
server_address = ('', 5911)
6466
HTTPServer.allow_reuse_address = True
6567
HTTPServer.address_family = AF_INET6
6668
httpd = HTTPServer(server_address, requesthandler)
67-
print "Listening on %s:%s." % server_address
69+
print("Listening on %s:%s." % server_address)
6870
httpd.serve_forever()
69-
70-
if __name__ == "__main__":
71-
main()

tests/vtc-from-controlset.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""
33
Parse the list of manually classified User-Agent strings and
44
prepare a varnishtest test case that verifies the correct classification.
@@ -25,9 +25,9 @@
2525
client c1 -run
2626
"""
2727

28-
def main():
28+
if __name__ == "__main__":
2929
inputfile = argv[1]
30-
print HEADER
30+
print(HEADER)
3131
for line in open(inputfile):
3232
line = line.strip()
3333
if line.startswith("#") or len(line) == 0:
@@ -36,10 +36,8 @@ def main():
3636

3737
classid, uastring = line.split("\t", 1)
3838

39-
print "\ttxreq -hdr \"User-Agent: %s\"" % uastring
40-
print "\trxresp"
41-
print "\texpect resp.http.X-UA-Device == \"%s\"\n" % classid
42-
print TAILER
39+
print("\ttxreq -hdr \"User-Agent: %s\"" % uastring)
40+
print("\trxresp")
41+
print("\texpect resp.http.X-UA-Device == \"%s\"\n" % classid)
42+
print(TAILER)
4343

44-
if __name__ == "__main__":
45-
main()

tests/vtc-from-snippets.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python
1+
#!/usr/bin/env python3
22
"""
33
Pick out the examples from the installation documentation and
44
build a VTC test case around it.
@@ -60,9 +60,9 @@ def parse(inputfile):
6060
assert section is not None
6161
assert line.startswith(".. endsnippet-%s" % section)
6262
except AssertionError:
63-
print section, line
64-
print buf
65-
print req
63+
print(section, line)
64+
print(buf)
65+
print(req)
6666
raise
6767

6868
yield section, "".join(buf), " ".join(req)
@@ -82,6 +82,6 @@ def parse(inputfile):
8282
rstfile = argv[1]
8383
for name, testsnippet, req in parse(rstfile):
8484
with open("snippet-%s.vtc" % name, "w+") as fp:
85-
print >>fp, header(name)
86-
print >>fp, testsnippet
87-
print >>fp, tailer(req)
85+
print(header(name), file=fp)
86+
print(testsnippet, file=fp)
87+
print(tailer(req), file=fp)

0 commit comments

Comments
 (0)