From 79548c3bf90b5a5ea2de3f6e1ca7c61169eb484c Mon Sep 17 00:00:00 2001 From: Kevin Yap Date: Mon, 15 Dec 2014 11:05:02 -0800 Subject: [PATCH] Minor changes to server.py - Log original path name rather than last path name - Use for-else construct to avoid use of flag variable - Make log messages consistent --- pelican/server.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/pelican/server.py b/pelican/server.py index cfe3d2b0..0a8dc1b6 100644 --- a/pelican/server.py +++ b/pelican/server.py @@ -19,21 +19,25 @@ SUFFIXES = ['', '.html', '/index.html'] class ComplexHTTPRequestHandler(srvmod.SimpleHTTPRequestHandler): def do_GET(self): - # we are trying to detect the file by having a fallback mechanism - found = False + # Try to detect file by applying various suffixes for suffix in SUFFIXES: - if not hasattr(self,'original_path'): + if not hasattr(self, 'original_path'): self.original_path = self.path + self.path = self.original_path + suffix path = self.translate_path(self.path) + if os.path.exists(path): srvmod.SimpleHTTPRequestHandler.do_GET(self) - logging.info("Found: %s" % self.path) - found = True + logging.info("Found `%s`." % self.path) break - logging.info("Tried to find file %s, but it doesn't exist. ", self.path) - if not found: - logging.warning("Unable to find file %s or variations.", self.path) + + logging.info("Tried to find `%s`, but it doesn't exist.", + self.path) + else: + # Fallback if there were no matches + logging.warning("Unable to find `%s` or variations.", + self.original_path) Handler = ComplexHTTPRequestHandler @@ -41,13 +45,13 @@ socketserver.TCPServer.allow_reuse_address = True try: httpd = socketserver.TCPServer((SERVER, PORT), Handler) except OSError as e: - logging.error("Could not listen on port %s, server %s", PORT, SERVER) + logging.error("Could not listen on port %s, server %s.", PORT, SERVER) sys.exit(getattr(e, 'exitcode', 1)) -logging.info("Serving at port %s, server %s", PORT, SERVER) +logging.info("Serving at port %s, server %s.", PORT, SERVER) try: httpd.serve_forever() except KeyboardInterrupt as e: - logging.info("Shutting down server") + logging.info("Shutting down server.") httpd.socket.close()