From 805f49b985252d9149d4024bfaefab83394819cc Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 16 Feb 2015 22:53:12 -0500 Subject: [PATCH] =?UTF-8?q?fix=20crash=20when=20displaying=20certain=20cha?= =?UTF-8?q?racters=20on=20windows=20=E0=B2=A0=5F=E0=B2=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tools/__init__.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tools/__init__.py b/tools/__init__.py index 02f264f..a6fcb75 100644 --- a/tools/__init__.py +++ b/tools/__init__.py @@ -2,6 +2,10 @@ import botconfig import datetime import time +# replace characters that can't be encoded with '?' +# since windows likes to use weird encodings by default +utf8stdout = open(1, 'w', errors="replace", closefd=False) # stdout + def get_timestamp(): """Returns a timestamp with timezone + offset from UTC.""" if botconfig.USE_UTC: @@ -30,7 +34,7 @@ def logger(file, write=True, display=True): display = True timestamp = get_timestamp() if display: - print(timestamp + output) + print(timestamp + output, file=utf8stdout) if write and file is not None: with open(file, "a") as f: f.seek(0, 2)