Issue 15649: subprocess.Popen.communicate: accept str for input parameter if universal_newlines is False (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/59854

classification

Title: subprocess.Popen.communicate: accept str for input parameter if universal_newlines is False
Type: enhancement Stage: needs patch
Components: Library (Lib) Versions: Python 3.4

process

Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Arfrever, Ramchandra Apte, asvetlov, chris.jerdonek, martin.panter, r.david.murray, serhiy.storchaka
Priority: normal Keywords:

Created on 2012-08-14 15:47 by asvetlov, last changed 2022-04-11 14:57 by admin.

Messages (6)
msg168207 - (view) Author: Andrew Svetlov (asvetlov) * (Python committer) Date: 2012-08-14 15:47
Currently Popen.communicate accept str is universal_newlines==True and bytes if universal_newlines==False. I like to accept both str and bytes if universal_newlines is False and raise explicit exception for bytes if universal_newlines is True. Looks like universal_newlines for bytes doesn't make sense, also we prefer to use str everywhere. Bytes should be used if it is really byte-stream or if unicode cannot be passed by some limitations of underlying OS etc. There are couple dark corners: 1. What to do if stdin doesn't have `encoding` attribute? Convert to bytes using filesystemencoding? Raise explicit exception? Adding `encode` parameter for .communicate doesn't looks elegant. 2. How .communicate works on Windows? I see completely different implementation of this method for win32.
msg168211 - (view) Author: Chris Jerdonek (chris.jerdonek) * (Python committer) Date: 2012-08-14 16:35
> What to do if stdin doesn't have `encoding` attribute? Convert to bytes using filesystemencoding? If choosing an encoding, it probably makes sense to default to the same as for when universal_newlines=True, namely locale.getpreferredencoding(False). > Adding `encode` parameter for .communicate doesn't looks elegant. Also see issue 6135 (to allow setting encoding).
msg168264 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2012-08-15 07:19
Uhum.. Universal Newlines is being deprecated.
msg168265 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-08-15 07:36
No it isn't. There's some issue about a 'U' parameter somewhere that is being deprecated, but that has nothing to do with this issue.
msg179426 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-09 09:29
See also .
msg268339 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2016-06-12 07:35
See also Issue 27273, proposing to use text string input as an indicator to turn on universal_newlines=True in the higher-level functions. I’m not excited by either proposal, but I find the other one a bit more palatable. IMO allowing text string input to communicate(), but returning byte string outputs would be a bad idea. It would have been better to call the universal_newlines=... flag “text_mode”.
History
Date User Action Args
2022-04-11 14:57:34 admin set github: 59854
2016-06-12 07:35:03 martin.panter set nosy: + martin.pantermessages: +
2013-01-09 09:29:45 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2012-08-18 13:41:16 Arfrever set nosy: + Arfrever
2012-08-15 07:36:56 r.david.murray set messages: +
2012-08-15 07:19:22 Ramchandra Apte set nosy: + Ramchandra Aptemessages: +
2012-08-15 02:10:45 eric.araujo set nosy: + r.david.murray
2012-08-14 16:35:39 chris.jerdonek set nosy: + chris.jerdonekmessages: +
2012-08-14 15:49:26 asvetlov set components: + Library (Lib)
2012-08-14 15:47:00 asvetlov create