diff options
author | Guido van Rossum <guido@python.org> | 2007-11-06 21:34:58 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-11-06 21:34:58 +0000 |
commit | 98297ee7815939b124156e438b22bd652d67b5db (patch) | |
tree | a9d239ebd87c73af2571ab48003984c4e18e27e5 /Lib/subprocess.py | |
parent | a19f80c6df2df5e8a5d0cff37131097835ef971e (diff) | |
download | cpython-98297ee7815939b124156e438b22bd652d67b5db.tar.gz cpython-98297ee7815939b124156e438b22bd652d67b5db.zip |
Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137
branch. The most obvious changes:
- str8 renamed to bytes (PyString at the C level);
- bytes renamed to buffer (PyBytes at the C level);
- PyString and PyUnicode are no longer compatible.
I.e. we now have an immutable bytes type and a mutable bytes type.
The behavior of PyString was modified quite a bit, to make it more
bytes-like. Some changes are still on the to-do list.
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r-- | Lib/subprocess.py | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 6eb93857a2a..d134c3a45e1 100644 --- a/Lib/subprocess.py +++ b/Lib/subprocess.py @@ -552,10 +552,9 @@ class Popen(object): self.stderr = io.TextIOWrapper(self.stderr) - def _translate_newlines(self, data): - data = data.replace(b"\r\n", b"\n") - data = data.replace(b"\r", b"\n") - return str(data) + def _translate_newlines(self, data, encoding): + data = data.replace(b"\r\n", b"\n").replace(b"\r", b"\n") + return data.decode(encoding) def __del__(self, sys=sys): @@ -825,16 +824,6 @@ class Popen(object): if stderr is not None: stderr = stderr[0] - # Translate newlines, if requested. We cannot let the file - # object do the translation: It is based on stdio, which is - # impossible to combine with select (unless forcing no - # buffering). - if self.universal_newlines: - if stdout is not None: - stdout = self._translate_newlines(stdout) - if stderr is not None: - stderr = self._translate_newlines(stderr) - self.wait() return (stdout, stderr) @@ -960,7 +949,8 @@ class Popen(object): os.close(p2cread) if c2pwrite is not None and c2pwrite not in (p2cread, 1): os.close(c2pwrite) - if errwrite is not None and errwrite not in (p2cread, c2pwrite, 2): + if (errwrite is not None and + errwrite not in (p2cread, c2pwrite, 2)): os.close(errwrite) # Close all other fds, if asked for @@ -1046,8 +1036,7 @@ class Popen(object): 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) + input = bytes(input) read_set = [] write_set = [] stdout = None # Return @@ -1072,6 +1061,9 @@ class Popen(object): while read_set or write_set: rlist, wlist, xlist = select.select(read_set, write_set, []) + # XXX Rewrite these to use non-blocking I/O on the + # file objects; they are no longer using C stdio! + if self.stdin in wlist: # When select has indicated that the file is writable, # we can write up to PIPE_BUF bytes without risk @@ -1099,19 +1091,19 @@ class Popen(object): # All data exchanged. Translate lists into strings. if stdout is not None: - stdout = b''.join(stdout) + stdout = b"".join(stdout) if stderr is not None: - stderr = b''.join(stderr) + stderr = b"".join(stderr) - # Translate newlines, if requested. We cannot let the file - # object do the translation: It is based on stdio, which is - # impossible to combine with select (unless forcing no - # buffering). + # Translate newlines, if requested. + # This also turns bytes into strings. if self.universal_newlines: if stdout is not None: - stdout = self._translate_newlines(stdout) + stdout = self._translate_newlines(stdout, + self.stdout.encoding) if stderr is not None: - stderr = self._translate_newlines(stderr) + stderr = self._translate_newlines(stderr, + self.stderr.encoding) self.wait() return (stdout, stderr) |