[Python-checkins] bpo-15037: Add a workaround for getkey() in curses for ncurses 5.7 and earlier. (GH-3826) (#4218)
Serhiy Storchaka
webhook-mailer at python.org
Wed Nov 1 10:38:38 EDT 2017
https://github.com/python/cpython/commit/1f81ea85e8e20347ec396001e5b869d36fe38398
commit: 1f81ea85e8e20347ec396001e5b869d36fe38398
branch: 3.6
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Serhiy Storchaka <storchaka at gmail.com>
date: 2017-11-01T16:38:35+02:00
summary:
bpo-15037: Add a workaround for getkey() in curses for ncurses 5.7 and earlier. (GH-3826) (#4218)
Skip a test for unget_wch()/get_wch() on OpenBSD since they are broken
in ncurses 5.7.
(cherry picked from commit 7e68790f3db75a893d5dd336e6201a63bc70212b)
files:
A Misc/NEWS.d/next/Library/2017-09-29-19-19-36.bpo-15037.ykimLK.rst
M Lib/test/test_curses.py
M Modules/_cursesmodule.c
diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py
index 514ed83167d..8bb6630284d 100644
--- a/Lib/test/test_curses.py
+++ b/Lib/test/test_curses.py
@@ -359,6 +359,9 @@ def test_issue6243(self):
self.stdscr.getkey()
@requires_curses_func('unget_wch')
+ # XXX Remove the decorator when ncurses on OpenBSD be updated
+ @unittest.skipIf(sys.platform.startswith("openbsd"),
+ "OpenBSD's curses (v.5.7) has bugs")
def test_unget_wch(self):
stdscr = self.stdscr
encoding = stdscr.encoding
diff --git a/Misc/NEWS.d/next/Library/2017-09-29-19-19-36.bpo-15037.ykimLK.rst b/Misc/NEWS.d/next/Library/2017-09-29-19-19-36.bpo-15037.ykimLK.rst
new file mode 100644
index 00000000000..a1e90ac3739
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2017-09-29-19-19-36.bpo-15037.ykimLK.rst
@@ -0,0 +1 @@
+Added a workaround for getkey() in curses for ncurses 5.7 and earlier.
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index 4a1d08a7d97..0e4cd536a31 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -1165,8 +1165,16 @@ PyCursesWindow_GetKey(PyCursesWindowObject *self, PyObject *args)
if (!PyErr_Occurred())
PyErr_SetString(PyCursesError, "no input");
return NULL;
- } else if (rtn<=255) {
- return Py_BuildValue("C", rtn);
+ } else if (rtn <= 255) {
+#ifdef NCURSES_VERSION_MAJOR
+#if NCURSES_VERSION_MAJOR*100+NCURSES_VERSION_MINOR <= 507
+ /* Work around a bug in ncurses 5.7 and earlier */
+ if (rtn < 0) {
+ rtn += 256;
+ }
+#endif
+#endif
+ return PyUnicode_FromOrdinal(rtn);
} else {
const char *knp = keyname(rtn);
return PyUnicode_FromString((knp == NULL) ? "" : knp);
More information about the Python-checkins
mailing list