From 63546685ad0185f006d503c92fb9f2711d5b0ffa Mon Sep 17 00:00:00 2001 From: Christian Herdtweck Date: Fri, 5 Jan 2018 10:09:58 +0100 Subject: [PATCH] msodde: Wrap sys.stdout into unicode-encoder only in py2 --- oletools/msodde.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/oletools/msodde.py b/oletools/msodde.py index 37a0fa9..ca475be 100644 --- a/oletools/msodde.py +++ b/oletools/msodde.py @@ -300,8 +300,8 @@ def ensure_stdout_handles_unicode(): # try to find encoding for sys.stdout encoding = None try: - encoding = sys.stdout.encoding # variable encoding might not exist - except Exception: + encoding = sys.stdout.encoding + except AttributeError: # variable "encoding" might not exist pass if encoding not in (None, '', 'ascii'): @@ -324,7 +324,8 @@ def ensure_stdout_handles_unicode(): sys.stdout = wrapper(sys.stdout) -ensure_stdout_handles_unicode() # e.g. for print(text) in main() +if sys.version_info.major < 3: + ensure_stdout_handles_unicode() # e.g. for print(text) in main() # === ARGUMENT PARSING ======================================================= -- libgit2 0.21.4