Fix server not working on some windows systems with non-English locales

This commit is contained in:
Kovid Goyal 2017-05-11 18:37:44 +05:30
parent 2089449769
commit 8743efbed1
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 13 additions and 4 deletions

View File

@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
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)

View File

@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3'
__copyright__ = '2015, Kovid Goyal <kovid at kovidgoyal.net>'
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')