New submission from Alex:

Regardless of the value of `encoding`, StreamReaders returned for the 
`asyncio.subprocess.Process`'s `stdout` and `stderr` would be in binary mode.

    import sys
    import asyncio
    import subprocess

    async def main():
        sp = await asyncio.create_subprocess_exec('ls', '-la',
                                                  stdin=None,
                                                  stdout=subprocess.PIPE,
                                                  encoding='utf8')
        await sp.wait()
        data = await sp.stdout.read()
        print(data)
        print(isinstance(data, bytes))

    loop = asyncio.get_event_loop()
    loop.run_until_complete(main())

There are two naive solutions:

- `create_subprocess_*` could explicitly raise when provided any `encoding` and 
`errors` (like it now does with `universal_newlines`).

- or implement encoding conversions for StreamReaders (and StreamWriters), and 
forward those.

Of course it would be better to have conversions, but I don't know how those 
will have to deal with decoding partially available data - e.g. returning in 
the middle of surrogate pair, or having only half a codepoint for UTF16. There 
should likely cache partial data to process at the next read, but this would 
require rewriting codecs to support partial decode... seems like it's not that 
easy :(

----------
messages: 299537
nosy: toriningen
priority: normal
severity: normal
status: open
title: asyncio.create_subprocess_* do not honor `encoding`

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue31087>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to