From bae07c9baf3e53164de6f85a18ce747a76b9ffde Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 8 Oct 2007 02:46:15 +0000 Subject: Breaking ground for PEP 3137 implementation: Get rid of buffer(). Use memoryview() in its place where possible. In a few places, do things a bit different, because memoryview() can't slice (yet). --- Lib/subprocess.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'Lib/subprocess.py') diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 362d59ad15..a34eb29c13 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -1041,8 +1041,11 @@ class Popen(object): def _communicate(self, input): - if isinstance(input, str): # Unicode - input = input.encode("utf-8") # XXX What else? + if self.stdin: + if isinstance(input, str): # Unicode + input = input.encode("utf-8") # XXX What else? + if not isinstance(input, (bytes, str8)): + input = bytes(input) read_set = [] write_set = [] stdout = None # Return @@ -1071,7 +1074,8 @@ class Popen(object): # When select has indicated that the file is writable, # we can write up to PIPE_BUF bytes without risk # blocking. POSIX defines PIPE_BUF >= 512 - bytes_written = os.write(self.stdin.fileno(), buffer(input, input_offset, 512)) + chunk = input[input_offset : input_offset + 512] + bytes_written = os.write(self.stdin.fileno(), chunk) input_offset += bytes_written if input_offset >= len(input): self.stdin.close() -- cgit v1.2.1