Skip to content

Commit ae11419

Browse files
committed
Convert str to bytes when writing to stderr during bootstrap
1 parent 5642851 commit ae11419

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

graalpython/lib-graalpython/_io.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,13 +534,24 @@ def truncate(self, size=-1):
534534
return size
535535

536536

537+
class StdPrinter:
538+
def __init__(self, file_io):
539+
self.file_io = file_io
540+
541+
def write(self, data):
542+
return self.file_io.write(bytes(data, "utf-8"))
543+
544+
def __getattr__(self, attr):
545+
return self.file_io.__getattribute__(attr)
546+
547+
537548
sys.stdin = FileIO(0, mode='r', closefd=False)
538549
sys.stdin.name = "<stdin>"
539550
sys.__stdin__ = sys.stdin
540551
sys.stdout = FileIO(1, mode='w', closefd=False)
541552
sys.stdout.name = "<stdout>"
542553
sys.__stdout__ = sys.stdout
543-
sys.stderr = FileIO(2, mode='w', closefd=False)
554+
sys.stderr = StdPrinter(FileIO(2, mode='w', closefd=False))
544555
sys.stderr.name = "<stderr>"
545556
sys.__stderr__ = sys.stderr
546557

graalpython/lib-graalpython/pyio_patches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def open(*args, **kwargs):
8989
sys.stdout = _pyio.TextIOWrapper(_pyio.BufferedWriter(sys.stdout), encoding=__graalpython__.stdio_encoding, errors=__graalpython__.stdio_error, line_buffering=True)
9090
sys.stdout.mode = "w"
9191
sys.__stdout__ = sys.stdout
92-
sys.stderr = _pyio.TextIOWrapper(_pyio.BufferedWriter(sys.stderr), encoding=__graalpython__.stdio_encoding, errors="backslashreplace", line_buffering=True)
92+
sys.stderr = _pyio.TextIOWrapper(_pyio.BufferedWriter(sys.stderr.file_io), encoding=__graalpython__.stdio_encoding, errors="backslashreplace", line_buffering=True)
9393
sys.stderr.mode = "w"
9494
sys.__stderr__ = sys.stderr
9595

0 commit comments

Comments
 (0)