8000 gh-110392: Fix tty functions (GH-110642) · python/cpython@84e2096 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84e2096

Browse files
gh-110392: Fix tty functions (GH-110642)
* tty.setraw() and tty.setcbreak() previously returned partially modified list of the original tty attributes. Now they return the correct list of the original tty attributes * tty.cfmakeraw() and tty.cfmakecbreak() now make a copy of the list of special characters before modifying it.
1 parent 7284e0e commit 84e2096

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

Lib/test/test_tty.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ def test_cfmakecbreak(self):
5858
self.assertEqual(mode[5], self.mode[5])
5959

6060
def test_setraw(self):
61-
mode = tty.setraw(self.fd)
61+
mode0 = termios.tcgetattr(self.fd)
62+
mode1 = tty.setraw(self.fd)
63+
self.assertEqual(mode1, mode0)
6264
mode2 = termios.tcgetattr(self.fd)
6365
self.check_raw(mode2)
6466
mode3 = tty.setraw(self.fd, termios.TCSANOW)
@@ -67,7 +69,9 @@ def test_setraw(self):
6769
tty.setraw(fd=self.fd, when=termios.TCSANOW)
6870

6971
def test_setcbreak(self):
70-
mode = tty.setcbreak(self.fd)
72+
mode0 = termios.tcgetattr(self.fd)
73+
mode1 = tty.setcbreak(self.fd)
74+
self.assertEqual(mode1, mode0)
7175
mode2 = termios.tcgetattr(self.fd)
7276
self.check_cbreak(mode2)
7377
mode3 = tty.setcbreak(self.fd, termios.TCSANOW)

Lib/tty.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def cfmakeraw(mode):
3939
# Case B: MIN>0, TIME=0
4040
# A pending read shall block until MIN (here 1) bytes are received,
4141
# or a signal is received.
42+
mode[CC] = list(mode[CC])
4243
mode[CC][VMIN] = 1
4344
mode[CC][VTIME] = 0
4445

@@ -54,6 +55,7 @@ def cfmakecbreak(mode):
5455
# Case B: MIN>0, TIME=0
5556
# A pending read shall block until MIN (here 1) bytes are received,
5657
# or a signal is received.
58+
mode[CC] = list(mode[CC])
5759
mode[CC][VMIN] = 1
5860
mode[CC][VTIME] = 0
5961

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix :func:`tty.setraw` and :func:`tty.setcbreak`: previously they returned
2+
partially modified list of the original tty attributes.
3+
:func:`tty.cfmakeraw` and :func:`tty.cfmakecbreak` now make a copy of the
4+
list of special characters before modifying it.

0 commit comments

Comments
 (0)
0