File tree Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Expand file tree Collapse file tree 1 file changed +6
-3
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ async def run_server():
20
20
21
21
import sys
22
22
from contextlib import asynccontextmanager
23
+ from io import TextIOWrapper
23
24
24
25
import anyio
25
26
import anyio .lowlevel
@@ -38,11 +39,13 @@ async def stdio_server(
38
39
from the current process' stdin and writing to stdout.
39
40
"""
40
41
# Purposely not using context managers for these, as we don't want to close
41
- # standard process handles.
42
+ # standard process handles. Encoding of stdin/stdout as text streams on
43
+ # python is platform-dependent (Windows is particularly problematic), so we
44
+ # re-wrap the underlying binary stream to ensure UTF-8.
42
45
if not stdin :
43
- stdin = anyio .wrap_file (sys .stdin )
46
+ stdin = anyio .wrap_file (TextIOWrapper ( sys .stdin . buffer , encoding = "utf-8" ) )
44
47
if not stdout :
45
- stdout = anyio .wrap_file (sys .stdout )
48
+ stdout = anyio .wrap_file (TextIOWrapper ( sys .stdout . buffer , encoding = "utf-8" ) )
46
49
47
50
read_stream : MemoryObjectReceiveStream [types .JSONRPCMessage | Exception ]
48
51
read_stream_writer : MemoryObjectSendStream [types .JSONRPCMessage | Exception ]
You can’t perform that action at this time.
0 commit comments