Commit 0e3efec2336062ee75d574192d4f06a9a3ae0961
1 parent
ae5ff5e4
io_encoding: warn when modifying encoding
Showing
1 changed file
with
4 additions
and
2 deletions
oletools/common/io_encoding.py
| ... | ... | @@ -128,8 +128,8 @@ def ensure_stdout_handles_unicode(): |
| 128 | 128 | elif os.isatty(output_stream.fileno()): # e.g. C locale |
| 129 | 129 | # Do not output UTF8 since that might be mis-interpreted. |
| 130 | 130 | # Just replace chars that cannot be handled |
| 131 | - if DEBUG: | |
| 132 | - print('sys.stdout is a tty, just replace errors') | |
| 131 | + print('Encoding for stdout is only {}, will replace other chars to ' | |
| 132 | + 'avoid unicode error'.format(encoding), file=sys.stderr) | |
| 133 | 133 | sys.stdout = codecs.getwriter(encoding)(output_stream, errors='replace') |
| 134 | 134 | else: # e.g. redirection, pipe in python2 |
| 135 | 135 | new_encoding = PREFERRED_ENCODING |
| ... | ... | @@ -141,6 +141,8 @@ def ensure_stdout_handles_unicode(): |
| 141 | 141 | if DEBUG: |
| 142 | 142 | print('preferred encoding also unacceptable, fall back to {}' |
| 143 | 143 | .format(new_encoding)) |
| 144 | + print('Encoding for stdout is only {}, will auto-encode text with {} ' | |
| 145 | + 'before output'.format(encoding, new_encoding), file=sys.stderr) | |
| 144 | 146 | sys.stdout = codecs.getwriter(new_encoding)(output_stream) |
| 145 | 147 | |
| 146 | 148 | ... | ... |