Commit 63546685ad0185f006d503c92fb9f2711d5b0ffa
1 parent
5fe1f070
msodde: Wrap sys.stdout into unicode-encoder only in py2
This is not necessary in python3
Showing
1 changed file
with
4 additions
and
3 deletions
oletools/msodde.py
| @@ -300,8 +300,8 @@ def ensure_stdout_handles_unicode(): | @@ -300,8 +300,8 @@ def ensure_stdout_handles_unicode(): | ||
| 300 | # try to find encoding for sys.stdout | 300 | # try to find encoding for sys.stdout |
| 301 | encoding = None | 301 | encoding = None |
| 302 | try: | 302 | try: |
| 303 | - encoding = sys.stdout.encoding # variable encoding might not exist | ||
| 304 | - except Exception: | 303 | + encoding = sys.stdout.encoding |
| 304 | + except AttributeError: # variable "encoding" might not exist | ||
| 305 | pass | 305 | pass |
| 306 | 306 | ||
| 307 | if encoding not in (None, '', 'ascii'): | 307 | if encoding not in (None, '', 'ascii'): |
| @@ -324,7 +324,8 @@ def ensure_stdout_handles_unicode(): | @@ -324,7 +324,8 @@ def ensure_stdout_handles_unicode(): | ||
| 324 | sys.stdout = wrapper(sys.stdout) | 324 | sys.stdout = wrapper(sys.stdout) |
| 325 | 325 | ||
| 326 | 326 | ||
| 327 | -ensure_stdout_handles_unicode() # e.g. for print(text) in main() | 327 | +if sys.version_info.major < 3: |
| 328 | + ensure_stdout_handles_unicode() # e.g. for print(text) in main() | ||
| 328 | 329 | ||
| 329 | 330 | ||
| 330 | # === ARGUMENT PARSING ======================================================= | 331 | # === ARGUMENT PARSING ======================================================= |