From 60f8965ab4238723276e5a3307feaacdec021d9b Mon Sep 17 00:00:00 2001 From: Michael Lazar Date: Sun, 22 Sep 2019 21:59:20 -0400 Subject: [PATCH] Display timezones in local time --- CHANGELOG.md | 15 +++++++++------ jetforce.py | 9 ++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 56dc852..fef284e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,14 +2,17 @@ ### Unreleased +- The server will now return a redirect if a directory is requested but the URL + does not end in a trailing slash. This reduces duplicate selectors and makes + it easier for clients to resolve relative links. +- Added a ``-V`` / ``--version`` argument to display the version and exit. - The server now returns a ``50 PERMENANT FAILURE`` response when a client requests a URL that does not exist on the server. This change is motivated by - mailing list discussions that a ``51 NOT FOUND`` status may not be - appropriate if the scheme/host component of the URL does not match the server. -- Added ``-V`` / ``--version`` argument to display the version and exit. -- Force URLs to always end in trailing slashes when serving a directory. This - reduces duplicate selectors and makes resolving relative links more reliable. - + the suggestion that a ``51 NOT FOUND`` status might not always be appropriate + if the scheme/host component of the URL does not match. +- Timestamps in log messages are now displayed to the server's local timezone. + The UTC offset is included in the timestamp as "+HHMM" to prevent ambiguity. + ### v0.0.7 (2019-08-30) - Added support for a primitive version of CGI scripting. diff --git a/jetforce.py b/jetforce.py index d44b714..34ad3f4 100755 --- a/jetforce.py +++ b/jetforce.py @@ -14,6 +14,7 @@ import ssl import subprocess import sys import tempfile +import time import typing import urllib.parse @@ -339,12 +340,14 @@ class GeminiRequestHandler: removed or slimmed-down. """ + TIMESTAMP_FORMAT = "%d/%b/%Y:%H:%M:%S %z" + def __init__(self, server: GeminiServer, app: typing.Callable) -> None: self.server = server self.app = app self.reader: typing.Optional[asyncio.StreamReader] = None self.writer: typing.Optional[asyncio.StreamWriter] = None - self.received_timestamp: typing.Optional[datetime.datetime] = None + self.received_timestamp: typing.Optional[time.struct_time] = None self.remote_addr: typing.Optional[str] = None self.client_cert: typing.Optional[dict] = None self.url: typing.Optional[urllib.parse.ParseResult] = None @@ -367,7 +370,7 @@ class GeminiRequestHandler: self.writer = writer self.remote_addr = writer.get_extra_info("peername")[0] self.client_cert = writer.get_extra_info("peercert") - self.received_timestamp = datetime.datetime.utcnow() + self.received_timestamp = time.localtime() try: await self.parse_header() @@ -481,7 +484,7 @@ class GeminiRequestHandler: """ self.server.log_message( f"{self.remote_addr} " - f"[{self.received_timestamp:%d/%b/%Y:%H:%M:%S +0000}] " + f"[{time.strftime(self.TIMESTAMP_FORMAT, self.received_timestamp)}] " f'"{self.url}" ' f"{self.status} " f'"{self.meta}" '