summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-01-21 23:41:03 (GMT)
committerGitHub <noreply@github.com>2024-01-21 23:41:03 (GMT)
commit33c1907de2710e7449a38aa27e7b55f274792342 (patch)
tree28892f4036b190dc83794cd6bc182d3a39d123df /Lib
parent4c42d981542372f57bc0071481dee42dbf119927 (diff)
downloadcpython-33c1907de2710e7449a38aa27e7b55f274792342.zip
cpython-33c1907de2710e7449a38aa27e7b55f274792342.tar.gz
cpython-33c1907de2710e7449a38aa27e7b55f274792342.tar.bz2
[3.12] gh-114328: tty cbreak mode should not alter ICRNL (GH-114335) (#114410)
The terminal CR -> NL mapping setting should be inherited in cbreak mode as OSes do not specify altering it as part of their stty cbreak mode definition. (cherry picked from commit fd49e226700e2483a452c3c92da6f15d822ae054) Co-authored-by: Gregory P. Smith <greg@krypto.org>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_tty.py12
-rw-r--r--Lib/tty.py3
2 files changed, 11 insertions, 4 deletions
diff --git a/Lib/test/test_tty.py b/Lib/test/test_tty.py
index af20864..4cb730c 100644
--- a/Lib/test/test_tty.py
+++ b/Lib/test/test_tty.py
@@ -19,7 +19,6 @@ class TestTty(unittest.TestCase):
self.addCleanup(termios.tcsetattr, self.fd, termios.TCSAFLUSH, self.mode)
def check_cbreak(self, mode):
- self.assertEqual(mode[0] & termios.ICRNL, 0)
self.assertEqual(mode[3] & termios.ECHO, 0)
self.assertEqual(mode[3] & termios.ICANON, 0)
self.assertEqual(mode[6][termios.VMIN], 1)
@@ -56,6 +55,14 @@ class TestTty(unittest.TestCase):
self.assertEqual(mode[2], self.mode[2])
self.assertEqual(mode[4], self.mode[4])
self.assertEqual(mode[5], self.mode[5])
+ mode[tty.IFLAG] |= termios.ICRNL
+ tty.cfmakecbreak(mode)
+ self.assertEqual(mode[tty.IFLAG] & termios.ICRNL, termios.ICRNL,
+ msg="ICRNL should not be cleared by cbreak")
+ mode[tty.IFLAG] &= ~termios.ICRNL
+ tty.cfmakecbreak(mode)
+ self.assertEqual(mode[tty.IFLAG] & termios.ICRNL, 0,
+ msg="ICRNL should not be set by cbreak")
def test_setraw(self):
mode0 = termios.tcgetattr(self.fd)
@@ -74,6 +81,9 @@ class TestTty(unittest.TestCase):
self.assertEqual(mode1, mode0)
mode2 = termios.tcgetattr(self.fd)
self.check_cbreak(mode2)
+ ICRNL = termios.ICRNL
+ self.assertEqual(mode2[tty.IFLAG] & ICRNL, mode0[tty.IFLAG] & ICRNL,
+ msg="ICRNL should not be altered by cbreak")
mode3 = tty.setcbreak(self.fd, termios.TCSANOW)
self.assertEqual(mode3, mode2)
tty.setcbreak(self.stream)
diff --git a/Lib/tty.py b/Lib/tty.py
index 283e5c3..5a49e04 100644
--- a/Lib/tty.py
+++ b/Lib/tty.py
@@ -45,9 +45,6 @@ def cfmakeraw(mode):
def cfmakecbreak(mode):
"""Make termios mode cbreak."""
- # Do not map CR to NL on input.
- mode[IFLAG] &= ~(ICRNL)
-
# Do not echo characters; disable canonical input.
mode[LFLAG] &= ~(ECHO | ICANON)