X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=Server.py;h=c0e1f241d655781e5a96f68216fd6d6d0b0fbd7f;hb=b9cb2812533eec9ba35576c0e25152e1dc5e2557;hp=40a68ab71b1bac124de0079c86594eaa77c34833;hpb=a74854dd38cb742b8fdc0d0cda7fff738a95312c;p=plcapi.git diff --git a/Server.py b/Server.py index 40a68ab..c0e1f24 100755 --- a/Server.py +++ b/Server.py @@ -1,25 +1,23 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # # Simple standalone HTTP server for testing PLCAPI # # Mark Huang # Copyright (C) 2006 The Trustees of Princeton University # -# $Id$ -# import os import sys import getopt import traceback -import BaseHTTPServer +import http.server # Append PLC to the system path sys.path.append(os.path.dirname(os.path.realpath(sys.argv[0]))) from PLC.API import PLCAPI -class PLCAPIRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): +class PLCAPIRequestHandler(http.server.BaseHTTPRequestHandler): """ Simple standalone HTTP request handler for testing PLCAPI. """ @@ -42,7 +40,7 @@ class PLCAPIRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): self.wfile.flush() self.connection.shutdown(1) - except Exception, e: + except Exception as e: # Log error sys.stderr.write(traceback.format_exc()) sys.stderr.flush() @@ -60,7 +58,7 @@ class PLCAPIRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): """) -class PLCAPIServer(BaseHTTPServer.HTTPServer): +class PLCAPIServer(http.server.HTTPServer): """ Simple standalone HTTP server for testing PLCAPI. """ @@ -68,7 +66,7 @@ class PLCAPIServer(BaseHTTPServer.HTTPServer): def __init__(self, addr, config): self.api = PLCAPI(config) self.allow_reuse_address = 1 - BaseHTTPServer.HTTPServer.__init__(self, addr, PLCAPIRequestHandler) + http.server.HTTPServer.__init__(self, addr, PLCAPIRequestHandler) # Defaults addr = "0.0.0.0" @@ -76,18 +74,18 @@ port = 8000 config = "/etc/planetlab/plc_config" def usage(): - print "Usage: %s [OPTION]..." % sys.argv[0] - print "Options:" - print " -p PORT, --port=PORT TCP port number to listen on (default: %d)" % port - print " -f FILE, --config=FILE PLC configuration file (default: %s)" % config - print " -h, --help This message" + print("Usage: %s [OPTION]..." % sys.argv[0]) + print("Options:") + print(" -p PORT, --port=PORT TCP port number to listen on (default: %d)" % port) + print(" -f FILE, --config=FILE PLC configuration file (default: %s)" % config) + print(" -h, --help This message") sys.exit(1) # Get options try: (opts, argv) = getopt.getopt(sys.argv[1:], "p:f:h", ["port=", "config=", "help"]) -except getopt.GetoptError, err: - print "Error: " + err.msg +except getopt.GetoptError as err: + print("Error: " + err.msg) usage() for (opt, optval) in opts: