]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] gh-110392: Fix tty functions (GH-110642) (GH-110853)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sat, 14 Oct 2023 06:18:14 +0000 (08:18 +0200)
committerGitHub <noreply@github.com>
Sat, 14 Oct 2023 06:18:14 +0000 (06:18 +0000)
* 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.

(cherry picked from commit 84e2096fbdea880799f2fdb3f0992a8961106bed)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Lib/test/test_tty.py
Lib/tty.py
Misc/NEWS.d/next/Library/2023-10-10-17-56-41.gh-issue-110392.6g6CnP.rst [new file with mode: 0644]

index 6993047492b5ecc177118eb498f5f99a5f8a002c..af20864aac361e26e78b6c9b23ef9e6201eb055f 100644 (file)
@@ -58,7 +58,9 @@ class TestTty(unittest.TestCase):
         self.assertEqual(mode[5], self.mode[5])
 
     def test_setraw(self):
-        mode = tty.setraw(self.fd)
+        mode0 = termios.tcgetattr(self.fd)
+        mode1 = tty.setraw(self.fd)
+        self.assertEqual(mode1, mode0)
         mode2 = termios.tcgetattr(self.fd)
         self.check_raw(mode2)
         mode3 = tty.setraw(self.fd, termios.TCSANOW)
@@ -67,7 +69,9 @@ class TestTty(unittest.TestCase):
         tty.setraw(fd=self.fd, when=termios.TCSANOW)
 
     def test_setcbreak(self):
-        mode = tty.setcbreak(self.fd)
+        mode0 = termios.tcgetattr(self.fd)
+        mode1 = tty.setcbreak(self.fd)
+        self.assertEqual(mode1, mode0)
         mode2 = termios.tcgetattr(self.fd)
         self.check_cbreak(mode2)
         mode3 = tty.setcbreak(self.fd, termios.TCSANOW)
index 7d916029ff2ce9d716a4c6cea27c39e91961f3bb..283e5c334f5751cc267e0c23e3e2535dfa41ecbc 100644 (file)
@@ -39,6 +39,7 @@ def cfmakeraw(mode):
     # Case B: MIN>0, TIME=0
     # A pending read shall block until MIN (here 1) bytes are received,
     # or a signal is received.
+    mode[CC] = list(mode[CC])
     mode[CC][VMIN] = 1
     mode[CC][VTIME] = 0
 
@@ -54,6 +55,7 @@ def cfmakecbreak(mode):
     # Case B: MIN>0, TIME=0
     # A pending read shall block until MIN (here 1) bytes are received,
     # or a signal is received.
+    mode[CC] = list(mode[CC])
     mode[CC][VMIN] = 1
     mode[CC][VTIME] = 0
 
diff --git a/Misc/NEWS.d/next/Library/2023-10-10-17-56-41.gh-issue-110392.6g6CnP.rst b/Misc/NEWS.d/next/Library/2023-10-10-17-56-41.gh-issue-110392.6g6CnP.rst
new file mode 100644 (file)
index 0000000..47e4e8e
--- /dev/null
@@ -0,0 +1,4 @@
+Fix :func:`tty.setraw` and :func:`tty.setcbreak`: previously they returned
+partially modified list of the original tty attributes.
+:func:`tty.cfmakeraw` and :func:`tty.cfmakecbreak` now make a copy of the
+list of special characters before modifying it.