]> granicus.if.org Git - python/commitdiff
bpo-15037: Add a workaround for getkey() in curses for ncurses 5.7 and earlier. ...
authorSerhiy Storchaka <storchaka@gmail.com>
Wed, 1 Nov 2017 14:03:40 +0000 (16:03 +0200)
committerGitHub <noreply@github.com>
Wed, 1 Nov 2017 14:03:40 +0000 (16:03 +0200)
Skip a test for unget_wch()/get_wch() on OpenBSD since they are broken
in ncurses 5.7.

Lib/test/test_curses.py
Misc/NEWS.d/next/Library/2017-09-29-19-19-36.bpo-15037.ykimLK.rst [new file with mode: 0644]
Modules/_cursesmodule.c

index 514ed83167d7945f5025764a74489ab3680f1e4d..8bb6630284dbecdee8f5e930f35d7b46b2dc534b 100644 (file)
@@ -359,6 +359,9 @@ class TestCurses(unittest.TestCase):
         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 (file)
index 0000000..a1e90ac
--- /dev/null
@@ -0,0 +1 @@
+Added a workaround for getkey() in curses for ncurses 5.7 and earlier.
index 7962936966906fffd405780e4956faeca0f2cff7..1f6897a57013de9faf393aee31fccb7bef218a68 100644 (file)
@@ -1163,8 +1163,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);