Commit a972bb3980e2fb36bba296fe380b470dbddded2b
1 parent
0cdbb2d3
olemeta: ensure stdout can handle unicode
This replaces an earlier partial custom solution
Showing
1 changed file
with
4 additions
and
4 deletions
oletools/olemeta.py
| @@ -79,6 +79,7 @@ if not _parent_dir in sys.path: | @@ -79,6 +79,7 @@ if not _parent_dir in sys.path: | ||
| 79 | import olefile | 79 | import olefile |
| 80 | from oletools.thirdparty import xglob | 80 | from oletools.thirdparty import xglob |
| 81 | from oletools.thirdparty.tablestream import tablestream | 81 | from oletools.thirdparty.tablestream import tablestream |
| 82 | +from oletools.common import ensure_stdout_handles_unicode | ||
| 82 | 83 | ||
| 83 | 84 | ||
| 84 | #=== MAIN ================================================================= | 85 | #=== MAIN ================================================================= |
| @@ -88,13 +89,12 @@ def process_ole(ole): | @@ -88,13 +89,12 @@ def process_ole(ole): | ||
| 88 | meta = ole.get_metadata() | 89 | meta = ole.get_metadata() |
| 89 | 90 | ||
| 90 | # console output with UTF8 encoding: | 91 | # console output with UTF8 encoding: |
| 91 | - # It looks like we do not need the UTF8 codec anymore, both for Python 2 and 3 | ||
| 92 | - console_utf8 = sys.stdout #codecs.getwriter('utf8')(sys.stdout) | 92 | + ensure_stdout_handles_unicode() |
| 93 | 93 | ||
| 94 | # TODO: move similar code to a function | 94 | # TODO: move similar code to a function |
| 95 | 95 | ||
| 96 | print('Properties from the SummaryInformation stream:') | 96 | print('Properties from the SummaryInformation stream:') |
| 97 | - t = tablestream.TableStream([21, 30], header_row=['Property', 'Value'], outfile=console_utf8) | 97 | + t = tablestream.TableStream([21, 30], header_row=['Property', 'Value']) |
| 98 | for prop in meta.SUMMARY_ATTRIBS: | 98 | for prop in meta.SUMMARY_ATTRIBS: |
| 99 | value = getattr(meta, prop) | 99 | value = getattr(meta, prop) |
| 100 | if value is not None: | 100 | if value is not None: |
| @@ -111,7 +111,7 @@ def process_ole(ole): | @@ -111,7 +111,7 @@ def process_ole(ole): | ||
| 111 | print('') | 111 | print('') |
| 112 | 112 | ||
| 113 | print('Properties from the DocumentSummaryInformation stream:') | 113 | print('Properties from the DocumentSummaryInformation stream:') |
| 114 | - t = tablestream.TableStream([21, 30], header_row=['Property', 'Value'], outfile=console_utf8) | 114 | + t = tablestream.TableStream([21, 30], header_row=['Property', 'Value']) |
| 115 | for prop in meta.DOCSUM_ATTRIBS: | 115 | for prop in meta.DOCSUM_ATTRIBS: |
| 116 | value = getattr(meta, prop) | 116 | value = getattr(meta, prop) |
| 117 | if value is not None: | 117 | if value is not None: |