Commit 1abcbf8e authored by Georg Brandl's avatar Georg Brandl

#2683: Popen.communicate() argument must be bytes.

parent c22ed14d
...@@ -883,8 +883,6 @@ class Popen(object): ...@@ -883,8 +883,6 @@ class Popen(object):
if self.stdin: if self.stdin:
if input is not None: if input is not None:
if isinstance(input, str):
input = input.encode()
self.stdin.write(input) self.stdin.write(input)
self.stdin.close() self.stdin.close()
...@@ -1129,10 +1127,6 @@ class Popen(object): ...@@ -1129,10 +1127,6 @@ class Popen(object):
def _communicate(self, input): def _communicate(self, input):
if self.stdin:
if isinstance(input, str): # Unicode
input = input.encode("utf-8") # XXX What else?
input = bytes(input)
read_set = [] read_set = []
write_set = [] write_set = []
stdout = None # Return stdout = None # Return
......
...@@ -302,7 +302,7 @@ class ProcessTestCase(unittest.TestCase): ...@@ -302,7 +302,7 @@ class ProcessTestCase(unittest.TestCase):
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
(stdout, stderr) = p.communicate("banana") (stdout, stderr) = p.communicate(b"banana")
self.assertEqual(stdout, b"banana") self.assertEqual(stdout, b"banana")
self.assertEqual(remove_stderr_debug_decorations(stderr), self.assertEqual(remove_stderr_debug_decorations(stderr),
b"pineapple") b"pineapple")
...@@ -420,7 +420,7 @@ class ProcessTestCase(unittest.TestCase): ...@@ -420,7 +420,7 @@ class ProcessTestCase(unittest.TestCase):
stdin=subprocess.PIPE, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE) stderr=subprocess.PIPE)
data = p.communicate("lime")[0] data = p.communicate(b"lime")[0]
self.assertEqual(data, b"lime") self.assertEqual(data, b"lime")
......
...@@ -17,6 +17,9 @@ Core and Builtins ...@@ -17,6 +17,9 @@ Core and Builtins
Library Library
------- -------
- Issue #2683: Fix inconsistency in subprocess.Popen.communicate(): the
argument now must be a bytes object in any case.
- Issue #3145: help("modules whatever") failed when trying to load the source - Issue #3145: help("modules whatever") failed when trying to load the source
code of every single module of the standard library, including invalid files code of every single module of the standard library, including invalid files
used in the test suite. used in the test suite.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment