summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2007-10-08 02:46:15 (GMT)
committerGuido van Rossum <guido@python.org>2007-10-08 02:46:15 (GMT)
commitbae07c9baf3e53164de6f85a18ce747a76b9ffde (patch)
treee0bf84063848730026bea64461fe3920dbe8ecb8 /Lib/subprocess.py
parent85c1ba5d742779eec3148377ce6d8d359d318263 (diff)
downloadcpython-bae07c9baf3e53164de6f85a18ce747a76b9ffde.zip
cpython-bae07c9baf3e53164de6f85a18ce747a76b9ffde.tar.gz
cpython-bae07c9baf3e53164de6f85a18ce747a76b9ffde.tar.bz2
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).
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 362d59a..a34eb29 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()