Message ID | 20161222185826.25237-2-joe@ovn.org |
---|---|
State | Accepted |
Headers | show |
On Thu, Dec 22, 2016 at 10:58:26AM -0800, Joe Stringer wrote: > 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@ovn.org> > --- > v2: First post. Seems reasonable but I'm a poor Python reviewer. Acked-by: Ben Pfaff <blp@ovn.org>
On 22 December 2016 at 15:57, Ben Pfaff <blp@ovn.org> wrote: > On Thu, Dec 22, 2016 at 10:58:26AM -0800, Joe Stringer wrote: >> 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@ovn.org> >> --- >> v2: First post. > > Seems reasonable but I'm a poor Python reviewer. > > Acked-by: Ben Pfaff <blp@ovn.org> Thanks, applied to master.
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:
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@ovn.org> --- v2: First post. --- tests/test-l7.py | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-)