mirror of https://github.com/python/cpython
gh-118824: Remove deprecated `master_open` and `slave_open` from `pty` (#118826)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
This commit is contained in:
parent
b407ad38fb
commit
f912e5a2f6
|
@ -175,6 +175,14 @@ pathlib
|
||||||
:meth:`~pathlib.PurePath.is_relative_to`. In previous versions, any such
|
:meth:`~pathlib.PurePath.is_relative_to`. In previous versions, any such
|
||||||
arguments are joined onto *other*.
|
arguments are joined onto *other*.
|
||||||
|
|
||||||
|
pty
|
||||||
|
___
|
||||||
|
|
||||||
|
* Remove deprecated :func:`!pty.master_open` and :func:`!pty.slave_open`.
|
||||||
|
They had previously raised a :exc:`DeprecationWarning` since Python 3.12.
|
||||||
|
Use :func:`pty.openpty` instead.
|
||||||
|
(Contributed by Nikita Sobolev in :gh:`118824`.)
|
||||||
|
|
||||||
sqlite3
|
sqlite3
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
|
47
Lib/pty.py
47
Lib/pty.py
|
@ -32,27 +32,18 @@ def openpty():
|
||||||
except (AttributeError, OSError):
|
except (AttributeError, OSError):
|
||||||
pass
|
pass
|
||||||
master_fd, slave_name = _open_terminal()
|
master_fd, slave_name = _open_terminal()
|
||||||
slave_fd = slave_open(slave_name)
|
|
||||||
return master_fd, slave_fd
|
|
||||||
|
|
||||||
def master_open():
|
|
||||||
"""master_open() -> (master_fd, slave_name)
|
|
||||||
Open a pty master and return the fd, and the filename of the slave end.
|
|
||||||
Deprecated, use openpty() instead."""
|
|
||||||
|
|
||||||
import warnings
|
|
||||||
warnings.warn("Use pty.openpty() instead.", DeprecationWarning, stacklevel=2) # Remove API in 3.14
|
|
||||||
|
|
||||||
|
slave_fd = os.open(slave_name, os.O_RDWR)
|
||||||
try:
|
try:
|
||||||
master_fd, slave_fd = os.openpty()
|
from fcntl import ioctl, I_PUSH
|
||||||
except (AttributeError, OSError):
|
except ImportError:
|
||||||
|
return master_fd, slave_fd
|
||||||
|
try:
|
||||||
|
ioctl(result, I_PUSH, "ptem")
|
||||||
|
ioctl(result, I_PUSH, "ldterm")
|
||||||
|
except OSError:
|
||||||
pass
|
pass
|
||||||
else:
|
return master_fd, slave_fd
|
||||||
slave_name = os.ttyname(slave_fd)
|
|
||||||
os.close(slave_fd)
|
|
||||||
return master_fd, slave_name
|
|
||||||
|
|
||||||
return _open_terminal()
|
|
||||||
|
|
||||||
def _open_terminal():
|
def _open_terminal():
|
||||||
"""Open pty master and return (master_fd, tty_name)."""
|
"""Open pty master and return (master_fd, tty_name)."""
|
||||||
|
@ -66,26 +57,6 @@ def _open_terminal():
|
||||||
return (fd, '/dev/tty' + x + y)
|
return (fd, '/dev/tty' + x + y)
|
||||||
raise OSError('out of pty devices')
|
raise OSError('out of pty devices')
|
||||||
|
|
||||||
def slave_open(tty_name):
|
|
||||||
"""slave_open(tty_name) -> slave_fd
|
|
||||||
Open the pty slave and acquire the controlling terminal, returning
|
|
||||||
opened filedescriptor.
|
|
||||||
Deprecated, use openpty() instead."""
|
|
||||||
|
|
||||||
import warnings
|
|
||||||
warnings.warn("Use pty.openpty() instead.", DeprecationWarning, stacklevel=2) # Remove API in 3.14
|
|
||||||
|
|
||||||
result = os.open(tty_name, os.O_RDWR)
|
|
||||||
try:
|
|
||||||
from fcntl import ioctl, I_PUSH
|
|
||||||
except ImportError:
|
|
||||||
return result
|
|
||||||
try:
|
|
||||||
ioctl(result, I_PUSH, "ptem")
|
|
||||||
ioctl(result, I_PUSH, "ldterm")
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
return result
|
|
||||||
|
|
||||||
def fork():
|
def fork():
|
||||||
"""fork() -> (pid, master_fd)
|
"""fork() -> (pid, master_fd)
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
Remove deprecated :func:`!pty.master_open` and :func:`!pty.slave_open`.
|
||||||
|
Use :func:`pty.openpty` instead.
|
||||||
|
Patch by Nikita Sobolev.
|
Loading…
Reference in New Issue