diff --git a/src/calibre/srv/http_response.py b/src/calibre/srv/http_response.py index 6c1e9cf8a0..d8cbf1a4e4 100644 --- a/src/calibre/srv/http_response.py +++ b/src/calibre/srv/http_response.py @@ -8,6 +8,7 @@ import errno import hashlib import os import struct +import time import uuid from collections import namedtuple from functools import wraps @@ -21,7 +22,7 @@ from calibre.srv.errors import HTTPSimpleResponse from calibre.srv.http_request import HTTPRequest, read_headers from calibre.srv.loop import WRITE from calibre.srv.utils import ( - HTTP1, HTTP11, Cookie, MultiDict, fast_now_strftime, get_translator_for_lang, + HTTP1, HTTP11, Cookie, MultiDict, get_translator_for_lang, http_date, socket_errors_socket_closed, sort_q_values ) from calibre.utils.monotonic import monotonic @@ -549,9 +550,13 @@ class HTTPConnection(HTTPRequest): ff = self.forwarded_for if ff: ff = '[%s] ' % ff + try: + ts = time.strftime('%d/%b/%Y:%H:%M:%S %z') + except Exception: + ts = 'strftime() failed' line = '{} port-{} {}{} {} "{}" {} {}'.format( self.remote_addr, self.remote_port, ff or '', username or '-', - fast_now_strftime('%d/%b/%Y:%H:%M:%S %z'), + ts, force_unicode(self.request_line or '', 'utf-8'), status_code, ('-' if response_size is None else response_size)) self.access_log(line) diff --git a/src/calibre/srv/utils.py b/src/calibre/srv/utils.py index cf16cf1ba2..b4c5ee84bb 100644 --- a/src/calibre/srv/utils.py +++ b/src/calibre/srv/utils.py @@ -4,7 +4,7 @@ __license__ = 'GPL v3' __copyright__ = '2015, Kovid Goyal ' -import errno, socket, os, time +import errno, socket, os from email.utils import formatdate from operator import itemgetter @@ -465,7 +465,3 @@ def get_use_roman(): from calibre.gui2 import config _use_roman = config['use_roman_numerals_for_series_number'] return _use_roman - - -def fast_now_strftime(fmt): - return as_unicode(time.strftime(fmt), errors='replace')