Override standard display hook to use non-locale encoding
(value)
| 612 | # existing test code was removed at Rev 1.27 (r34098). |
| 613 | |
| 614 | def displayhook(value): |
| 615 | """Override standard display hook to use non-locale encoding""" |
| 616 | if value is None: |
| 617 | return |
| 618 | # Set '_' to None to avoid recursion |
| 619 | builtins._ = None |
| 620 | text = repr(value) |
| 621 | try: |
| 622 | sys.stdout.write(text) |
| 623 | except UnicodeEncodeError: |
| 624 | # let's use ascii while utf8-bmp codec doesn't present |
| 625 | encoding = 'ascii' |
| 626 | bytes = text.encode(encoding, 'backslashreplace') |
| 627 | text = bytes.decode(encoding, 'strict') |
| 628 | sys.stdout.write(text) |
| 629 | sys.stdout.write("\n") |
| 630 | builtins._ = value |
| 631 | |
| 632 | |
| 633 | if __name__ == '__main__': |