mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
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
This commit is contained in:
parent
6616ed8816
commit
79548c3bf9
1 changed files with 15 additions and 11 deletions
|
|
@ -19,21 +19,25 @@ SUFFIXES = ['', '.html', '/index.html']
|
||||||
|
|
||||||
class ComplexHTTPRequestHandler(srvmod.SimpleHTTPRequestHandler):
|
class ComplexHTTPRequestHandler(srvmod.SimpleHTTPRequestHandler):
|
||||||
def do_GET(self):
|
def do_GET(self):
|
||||||
# we are trying to detect the file by having a fallback mechanism
|
# Try to detect file by applying various suffixes
|
||||||
found = False
|
|
||||||
for suffix in SUFFIXES:
|
for suffix in SUFFIXES:
|
||||||
if not hasattr(self,'original_path'):
|
if not hasattr(self, 'original_path'):
|
||||||
self.original_path = self.path
|
self.original_path = self.path
|
||||||
|
|
||||||
self.path = self.original_path + suffix
|
self.path = self.original_path + suffix
|
||||||
path = self.translate_path(self.path)
|
path = self.translate_path(self.path)
|
||||||
|
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
srvmod.SimpleHTTPRequestHandler.do_GET(self)
|
srvmod.SimpleHTTPRequestHandler.do_GET(self)
|
||||||
logging.info("Found: %s" % self.path)
|
logging.info("Found `%s`." % self.path)
|
||||||
found = True
|
|
||||||
break
|
break
|
||||||
logging.info("Tried to find file %s, but it doesn't exist. ", self.path)
|
|
||||||
if not found:
|
logging.info("Tried to find `%s`, but it doesn't exist.",
|
||||||
logging.warning("Unable to find file %s or variations.", self.path)
|
self.path)
|
||||||
|
else:
|
||||||
|
# Fallback if there were no matches
|
||||||
|
logging.warning("Unable to find `%s` or variations.",
|
||||||
|
self.original_path)
|
||||||
|
|
||||||
Handler = ComplexHTTPRequestHandler
|
Handler = ComplexHTTPRequestHandler
|
||||||
|
|
||||||
|
|
@ -41,13 +45,13 @@ socketserver.TCPServer.allow_reuse_address = True
|
||||||
try:
|
try:
|
||||||
httpd = socketserver.TCPServer((SERVER, PORT), Handler)
|
httpd = socketserver.TCPServer((SERVER, PORT), Handler)
|
||||||
except OSError as e:
|
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))
|
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:
|
try:
|
||||||
httpd.serve_forever()
|
httpd.serve_forever()
|
||||||
except KeyboardInterrupt as e:
|
except KeyboardInterrupt as e:
|
||||||
logging.info("Shutting down server")
|
logging.info("Shutting down server.")
|
||||||
httpd.socket.close()
|
httpd.socket.close()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue