mirror of
https://github.com/python/cpython.git
synced 2025-07-18 08:45:20 +00:00
gh-87901: Remove the encoding argument from os.popen (GH-92836)
(cherry picked from commit 96f65835f8
)
Co-authored-by: Inada Naoki <songofacandy@gmail.com>
This commit is contained in:
parent
849963598f
commit
aa55985aa8
3 changed files with 13 additions and 7 deletions
|
@ -3916,13 +3916,13 @@ written in Python, such as a mail server's external command delivery program.
|
||||||
.. availability:: Unix.
|
.. availability:: Unix.
|
||||||
|
|
||||||
|
|
||||||
.. function:: popen(cmd, mode='r', buffering=-1, encoding=None)
|
.. function:: popen(cmd, mode='r', buffering=-1)
|
||||||
|
|
||||||
Open a pipe to or from command *cmd*.
|
Open a pipe to or from command *cmd*.
|
||||||
The return value is an open file object
|
The return value is an open file object
|
||||||
connected to the pipe, which can be read or written depending on whether *mode*
|
connected to the pipe, which can be read or written depending on whether *mode*
|
||||||
is ``'r'`` (default) or ``'w'``.
|
is ``'r'`` (default) or ``'w'``.
|
||||||
The *buffering* and *encoding* arguments have the same meaning as
|
The *buffering* argument have the same meaning as
|
||||||
the corresponding argument to the built-in :func:`open` function. The
|
the corresponding argument to the built-in :func:`open` function. The
|
||||||
returned file object reads or writes text strings rather than bytes.
|
returned file object reads or writes text strings rather than bytes.
|
||||||
|
|
||||||
|
@ -3945,8 +3945,13 @@ written in Python, such as a mail server's external command delivery program.
|
||||||
documentation for more powerful ways to manage and communicate with
|
documentation for more powerful ways to manage and communicate with
|
||||||
subprocesses.
|
subprocesses.
|
||||||
|
|
||||||
.. versionchanged:: 3.11
|
.. note::
|
||||||
Added the *encoding* parameter.
|
The :ref:`Python UTF-8 Mode <utf8-mode>` affects encodings used
|
||||||
|
for *cmd* and pipe contents.
|
||||||
|
|
||||||
|
:func:`popen` is a simple wrapper around :class:`subprocess.Popen`.
|
||||||
|
Use :class:`subprocess.Popen` or :func:`subprocess.run` to
|
||||||
|
control options like encodings.
|
||||||
|
|
||||||
|
|
||||||
.. function:: posix_spawn(path, argv, env, *, file_actions=None, \
|
.. function:: posix_spawn(path, argv, env, *, file_actions=None, \
|
||||||
|
|
|
@ -974,15 +974,14 @@ otherwise return -SIG, where SIG is the signal that killed it. """
|
||||||
# command in a shell can't be supported.
|
# command in a shell can't be supported.
|
||||||
if sys.platform != 'vxworks':
|
if sys.platform != 'vxworks':
|
||||||
# Supply os.popen()
|
# Supply os.popen()
|
||||||
def popen(cmd, mode="r", buffering=-1, encoding=None):
|
def popen(cmd, mode="r", buffering=-1):
|
||||||
if not isinstance(cmd, str):
|
if not isinstance(cmd, str):
|
||||||
raise TypeError("invalid cmd type (%s, expected string)" % type(cmd))
|
raise TypeError("invalid cmd type (%s, expected string)" % type(cmd))
|
||||||
if mode not in ("r", "w"):
|
if mode not in ("r", "w"):
|
||||||
raise ValueError("invalid mode %r" % mode)
|
raise ValueError("invalid mode %r" % mode)
|
||||||
if buffering == 0 or buffering is None:
|
if buffering == 0 or buffering is None:
|
||||||
raise ValueError("popen() does not support unbuffered streams")
|
raise ValueError("popen() does not support unbuffered streams")
|
||||||
import subprocess, io
|
import subprocess
|
||||||
encoding = io.text_encoding(encoding)
|
|
||||||
if mode == "r":
|
if mode == "r":
|
||||||
proc = subprocess.Popen(cmd,
|
proc = subprocess.Popen(cmd,
|
||||||
shell=True, text=True,
|
shell=True, text=True,
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Removed the ``encoding`` argument from :func:`os.popen` that was added in
|
||||||
|
3.11b1.
|
Loading…
Add table
Add a link
Reference in a new issue