diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2012-08-28 23:40:57 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2012-08-28 23:40:57 (GMT) |
commit | 1d39cde50c9cd485de482ec2cce987482394bff5 (patch) | |
tree | f9226b5293d8f864bc4e8cea55e2d8c68fbb3713 | |
parent | 4e07a8c9aa5275c7a8161e02fba29e8170f0c212 (diff) | |
download | cpython-1d39cde50c9cd485de482ec2cce987482394bff5.zip cpython-1d39cde50c9cd485de482ec2cce987482394bff5.tar.gz cpython-1d39cde50c9cd485de482ec2cce987482394bff5.tar.bz2 |
Issue #15785: Modify window.get_wch() API of the curses module: return a
character for most keys, and an integer for special keys, instead of always
returning an integer. So it is now possible to distinguish special keys like
keypad keys.
-rw-r--r-- | Doc/library/curses.rst | 9 | ||||
-rw-r--r-- | Lib/test/test_curses.py | 12 | ||||
-rw-r--r-- | Misc/NEWS | 7 | ||||
-rw-r--r-- | Modules/_cursesmodule.c | 5 |
4 files changed, 20 insertions, 13 deletions
diff --git a/Doc/library/curses.rst b/Doc/library/curses.rst index ff3a793..c424148 100644 --- a/Doc/library/curses.rst +++ b/Doc/library/curses.rst @@ -869,8 +869,8 @@ the following methods and attributes: .. method:: window.get_wch([y, x]) - Get a wide character. Like :meth:`getch`, but the integer returned is the - Unicode code point for the key pressed, so it can be passed to :func:`chr`. + Get a wide character. Return a character for most keys, or an integer for + function keys, keypad keys, and other special keys. .. versionadded:: 3.3 @@ -878,8 +878,9 @@ the following methods and attributes: .. method:: window.getkey([y, x]) Get a character, returning a string instead of an integer, as :meth:`getch` - does. Function keys, keypad keys and so on return a multibyte string containing - the key name. In no-delay mode, an exception is raised if there is no input. + does. Function keys, keypad keys and other special keys return a multibyte + string containing the key name. In no-delay mode, an exception is raised if + there is no input. .. method:: window.getmaxyx() diff --git a/Lib/test/test_curses.py b/Lib/test/test_curses.py index 21ac608..e959622 100644 --- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -267,8 +267,7 @@ def test_issue6243(stdscr): def test_unget_wch(stdscr): if not hasattr(curses, 'unget_wch'): return - import locale - encoding = locale.getpreferredencoding() + encoding = stdscr.encoding for ch in ('a', '\xe9', '\u20ac', '\U0010FFFF'): try: ch.encode(encoding) @@ -277,18 +276,17 @@ def test_unget_wch(stdscr): try: curses.unget_wch(ch) except Exception as err: - raise Exception("unget_wch(%a) failed with locale encoding %s: %s" - % (ch, encoding, err)) + raise Exception("unget_wch(%a) failed with encoding %s: %s" + % (ch, stdscr.encoding, err)) read = stdscr.get_wch() - read = chr(read) if read != ch: raise AssertionError("%r != %r" % (read, ch)) code = ord(ch) curses.unget_wch(code) read = stdscr.get_wch() - if read != code: - raise AssertionError("%r != %r" % (read, code)) + if read != ch: + raise AssertionError("%r != %r" % (read, ch)) def test_issue10570(): b = curses.tparm(curses.tigetstr("cup"), 5, 3) @@ -48,6 +48,11 @@ Core and Builtins Library ------- +- Issue #15785: Modify window.get_wch() API of the curses module: return + a character for most keys, and an integer for special keys, instead of + always returning an integer. So it is now possible to distinguish special + keys like keypad keys. + What's New in Python 3.3.0 Release Candidate 1? =============================================== @@ -58,7 +63,7 @@ Core and Builtins ----------------- - Issue #15573: memoryview comparisons are now performed by value with full - support for any valid struct module format definition. + support for any valid struct module format definition. - Issue #15316: When an item in the fromlist for __import__ doesn't exist, don't raise an error, but if an exception is raised as part of an import do diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c index de45f51..0436e7f 100644 --- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -1203,7 +1203,10 @@ PyCursesWindow_Get_WCh(PyCursesWindowObject *self, PyObject *args) PyErr_SetString(PyCursesError, "no input"); return NULL; } - return PyLong_FromLong(rtn); + if (ct == KEY_CODE_YES) + return PyLong_FromLong(rtn); + else + return PyUnicode_FromOrdinal(rtn); } #endif |