diff --git a/src/calibre/srv/http_response.py b/src/calibre/srv/http_response.py index deade8c635..c048c3656f 100644 --- a/src/calibre/srv/http_response.py +++ b/src/calibre/srv/http_response.py @@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2015, Kovid Goyal ' -import os, httplib, hashlib, uuid, struct, repr as reprlib, time +import os, httplib, hashlib, uuid, struct, repr as reprlib from collections import namedtuple from io import BytesIO, DEFAULT_BUFFER_SIZE from itertools import chain, repeat, izip_longest @@ -22,7 +22,7 @@ from calibre.srv.http_request import HTTPRequest, read_headers from calibre.srv.sendfile import file_metadata, sendfile_to_socket_async, CannotSendfile, SendfileInterrupted from calibre.srv.utils import ( MultiDict, http_date, HTTP1, HTTP11, socket_errors_socket_closed, - sort_q_values, get_translator_for_lang, Cookie) + sort_q_values, get_translator_for_lang, Cookie, fast_now_strftime) from calibre.utils.speedups import ReadOnlyFileBuffer from calibre.utils.monotonic import monotonic @@ -526,7 +526,7 @@ class HTTPConnection(HTTPRequest): return line = '%s port-%s %s %s "%s" %s %s' % ( self.remote_addr, self.remote_port, username or '-', - time.strftime('%d/%b/%Y:%H:%M:%S %z'), + fast_now_strftime('%d/%b/%Y:%H:%M:%S %z'), 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 dc061467be..9b5582bd6a 100644 --- a/src/calibre/srv/utils.py +++ b/src/calibre/srv/utils.py @@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2015, Kovid Goyal ' -import errno, socket, select, os +import errno, socket, select, os, time from Cookie import SimpleCookie from contextlib import closing from urlparse import parse_qs @@ -508,3 +508,12 @@ def get_use_roman(): from calibre.gui2 import config _use_roman = config['use_roman_numerals_for_series_number'] return _use_roman + + +if iswindows: + def fast_now_strftime(fmt): + fmt = fmt.encode('mbcs') + return time.strftime(fmt).decode('mbcs', 'replace') +else: + def fast_now_strftime(fmt): + return time.strftime(fmt).decode('utf-8', 'replace')