|
45 | 45 |
|
46 | 46 | # Force to use UTF-8 encoding |
47 | 47 | # Windows may use other encodings / code pages that have many characters missing/unrepresentable |
48 | | -# Error: Python UnicodeEncodeError: 'charmap' codec can't encode characters in position xx-xx: character maps to <undefined> |
49 | | -sys.stdout.reconfigure(encoding='utf-8') |
50 | | -sys.stderr.reconfigure(encoding='utf-8') |
| 48 | +if isinstance(sys.stdin, io.TextIOWrapper): sys.stdin.reconfigure(encoding='utf-8') |
| 49 | +if isinstance(sys.stdout, io.TextIOWrapper): sys.stdout.reconfigure(encoding='utf-8') |
| 50 | +if isinstance(sys.stderr, io.TextIOWrapper): sys.stderr.reconfigure(encoding='utf-8') |
51 | 51 |
|
52 | 52 | # Add some python functions to the global python object for code in this file to use. |
53 | 53 | globalThis = pm.eval("globalThis;", evalOpts) |
|
59 | 59 | globalThis.python.pythonMonkey.isCompilableUnit = pm.isCompilableUnit |
60 | 60 | globalThis.python.pythonMonkey.nodeModules = node_modules |
61 | 61 | globalThis.python.print = print |
62 | | -globalThis.python.stdout.write = sys.stdout.write |
63 | | -globalThis.python.stderr.write = sys.stderr.write |
64 | | -globalThis.python.stdout.read = sys.stdout.read |
65 | | -globalThis.python.stderr.read = sys.stderr.read |
| 62 | +globalThis.python.stdout.write = lambda s: sys.stdout.write(s) |
| 63 | +globalThis.python.stderr.write = lambda s: sys.stderr.write(s) |
| 64 | +globalThis.python.stdout.read = lambda n: sys.stdout.read(n) |
| 65 | +globalThis.python.stderr.read = lambda n: sys.stderr.read(n) |
66 | 66 | globalThis.python.eval = eval |
67 | 67 | globalThis.python.exec = exec |
68 | 68 | globalThis.python.getenv = os.getenv |
|
0 commit comments