fixes initialization bug if sys.stdout.encoding is None (closes gh-2177).

pull/2180/head
sebres 2018-07-11 13:21:53 +02:00
parent cc321b78da
commit 94ffd00328
1 changed files with 1 additions and 2 deletions

View File

@ -32,11 +32,10 @@ from threading import Lock
from .server.mytime import MyTime
PREFER_ENC = locale.getpreferredencoding()
# correct preferred encoding if lang not set in environment:
if PREFER_ENC.startswith('ANSI_'): # pragma: no cover
if sys.stdout and not sys.stdout.encoding.startswith('ANSI_'):
if sys.stdout and sys.stdout.encoding is not None and not sys.stdout.encoding.startswith('ANSI_'):
PREFER_ENC = sys.stdout.encoding
elif all((os.getenv(v) in (None, "") for v in ('LANGUAGE', 'LC_ALL', 'LC_CTYPE', 'LANG'))):
PREFER_ENC = 'UTF-8';