From a9fc6f451b45ba5da0e66fbc261b8f0c0aeec761 Mon Sep 17 00:00:00 2001 From: s3lph Date: Sat, 14 Jul 2018 22:55:14 +0200 Subject: [PATCH] Cleaner datetime API usage. --- matemat/webserver/httpd.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/matemat/webserver/httpd.py b/matemat/webserver/httpd.py index aa282e1..e962a8c 100644 --- a/matemat/webserver/httpd.py +++ b/matemat/webserver/httpd.py @@ -10,7 +10,6 @@ from http.server import HTTPServer, BaseHTTPRequestHandler from http.cookies import SimpleCookie from uuid import uuid4 from datetime import datetime, timedelta -from time import localtime import jinja2 @@ -349,10 +348,10 @@ class HttpHandler(BaseHTTPRequestHandler): # Parse the If-Modified-Since header to check whether the browser can reuse cached content datestr: str = self.headers.get('If-Modified-Since', 'Thu, 01 Jan 1970 00:00:00 GMT') maxage: datetime = datetime.strptime(datestr, '%a, %d %b %Y %H:%M:%S %Z') - # File modification time in LOCAL time + # Get file modification time filestat: int = int(os.path.getmtime(filepath)) - # Create timezone-unaware datetime object and subtract UTC offset - fileage: datetime = datetime.fromtimestamp(filestat) - timedelta(seconds=localtime().tm_gmtoff) + # Create UTC datetime object from mtime + fileage: datetime = datetime.utcfromtimestamp(filestat) # If the file has not been replaced by a newer version than requested by the client, send a 304 response if fileage <= maxage: