Skip to content

Commit 1981df5

Browse files
committed
Merge branch 'main' into Xmader/feat/js-debugger
2 parents 148e71f + ae133ef commit 1981df5

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

python/pythonmonkey/require.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,9 @@
4545

4646
# Force to use UTF-8 encoding
4747
# 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')
5151

5252
# Add some python functions to the global python object for code in this file to use.
5353
globalThis = pm.eval("globalThis;", evalOpts)
@@ -59,10 +59,10 @@
5959
globalThis.python.pythonMonkey.isCompilableUnit = pm.isCompilableUnit
6060
globalThis.python.pythonMonkey.nodeModules = node_modules
6161
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)
6666
globalThis.python.eval = eval
6767
globalThis.python.exec = exec
6868
globalThis.python.getenv = os.getenv

0 commit comments

Comments
 (0)