[ovs-dev] [PATCHv2 2/2] test-l7.py: Tidy up and python3-ify.
Joe Stringer
joe at ovn.org
Thu Dec 22 18:58:26 UTC 2016
Haul test-l7.py into the 202nd decade by supporting python3.
TFTPY still doesn't support python3, so work around this by handling
import syntax errors so that even if tftpy is installed in a python3
environment, test-l7.py will not throw an exception while attempting to
load it.
Signed-off-by: Joe Stringer <joe at ovn.org>
---
v2: First post.
---
tests/test-l7.py | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
diff --git a/tests/test-l7.py b/tests/test-l7.py
index e5f473b56740..d7854a1df31b 100755
--- a/tests/test-l7.py
+++ b/tests/test-l7.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# Copyright (c) 2015, 2016 Nicira, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -15,9 +16,13 @@
import argparse
import socket
-from BaseHTTPServer import HTTPServer
-from SimpleHTTPServer import SimpleHTTPRequestHandler
-from SocketServer import TCPServer
+try: # Python 2.7
+ from BaseHTTPServer import HTTPServer
+ from SimpleHTTPServer import SimpleHTTPRequestHandler
+ from SocketServer import TCPServer
+except:
+ from http.server import HTTPServer, SimpleHTTPRequestHandler
+ from socketserver import TCPServer
class TCPServerV6(HTTPServer):
@@ -62,7 +67,7 @@ def get_tftpd():
def serve_forever(self):
self.listen(self.ip, self.port)
server = [OVSTFTPServer, None, TftpShared.DEF_TFTP_PORT]
- except ImportError:
+ except (ImportError, SyntaxError):
server = None
pass
return server
@@ -78,9 +83,9 @@ def main():
protocols = [srv for srv in SERVERS if SERVERS[srv] is not None]
parser = argparse.ArgumentParser(
- description='Run basic application servers.')
+ description='Run basic application servers.')
parser.add_argument('proto', default='http', nargs='?',
- help='protocol to serve (%s)' % protocols)
+ help='protocol to serve (%s)' % protocols)
args = parser.parse_args()
if args.proto not in protocols:
--
2.10.2
More information about the dev
mailing list