From 853d48b48fc8123c403c5fb947732adb830b752d Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Fri, 11 Mar 2022 22:55:25 +0500 Subject: server.py: minor refactoring --- server.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/server.py b/server.py index 0ebe5d5..914765d 100755 --- a/server.py +++ b/server.py @@ -40,6 +40,14 @@ class RequestHandler(http.server.SimpleHTTPRequestHandler): return +def make_server(port): + addr = ('', port) + server = http.server.HTTPServer + if sys.version_info >= (3, 7): + server = http.server.ThreadingHTTPServer + return server(addr, RequestHandler) + + def parse_args(args=None): if args is None: args = sys.argv[1:] @@ -54,12 +62,9 @@ def main(args=None): # It's a failsafe; this script is only allowed to serve the directory it # resides in. os.chdir(script_dir()) + args = parse_args(args) - addr = ('', args.port) - server = http.server.HTTPServer - if sys.version_info >= (3, 7): - server = http.server.ThreadingHTTPServer - httpd = server(addr, RequestHandler) + httpd = make_server(args.port) try: httpd.serve_forever() except KeyboardInterrupt: -- cgit v1.2.3