]> granicus.if.org Git - python/commitdiff
#2683: Popen.communicate() argument must be bytes.
authorGeorg Brandl <georg@python.org>
Tue, 1 Jul 2008 19:28:43 +0000 (19:28 +0000)
committerGeorg Brandl <georg@python.org>
Tue, 1 Jul 2008 19:28:43 +0000 (19:28 +0000)
Lib/subprocess.py
Lib/test/test_subprocess.py
Misc/NEWS

index d9c76d8ad58b5c8160f62767d73e5cdc7cc3e687..8df10344cbc9acaf7aee396e97e5bb769582a417 100644 (file)
@@ -883,8 +883,6 @@ class Popen(object):
 
             if self.stdin:
                 if input is not None:
-                    if isinstance(input, str):
-                        input = input.encode()
                     self.stdin.write(input)
                 self.stdin.close()
 
@@ -1129,10 +1127,6 @@ class Popen(object):
 
 
         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 = []
             write_set = []
             stdout = None # Return
index 71ae0db291fb16a4e0cdfcfbabb87177b244395e..fe916c2a8511a8bf87a6ffa0a2534256dd4b5eac 100644 (file)
@@ -302,7 +302,7 @@ class ProcessTestCase(unittest.TestCase):
                              stdin=subprocess.PIPE,
                              stdout=subprocess.PIPE,
                              stderr=subprocess.PIPE)
-        (stdout, stderr) = p.communicate("banana")
+        (stdout, stderr) = p.communicate(b"banana")
         self.assertEqual(stdout, b"banana")
         self.assertEqual(remove_stderr_debug_decorations(stderr),
                          b"pineapple")
@@ -420,7 +420,7 @@ class ProcessTestCase(unittest.TestCase):
                                  stdin=subprocess.PIPE,
                                  stdout=subprocess.PIPE,
                                  stderr=subprocess.PIPE)
-            data = p.communicate("lime")[0]
+            data = p.communicate(b"lime")[0]
             self.assertEqual(data, b"lime")
 
 
index 9914858c17f0f470b820c80ea4e6a1d1aa4749cb..87f7c6bf77e13c61f42ed43a468f25e3c6847153 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,6 +17,9 @@ Core and Builtins
 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
   code of every single module of the standard library, including invalid files
   used in the test suite.