diff -r 5b0595339c9d Doc/library/curses.rst --- a/Doc/library/curses.rst Sun Aug 26 07:33:10 2012 +0300 +++ b/Doc/library/curses.rst Wed Aug 29 00:14:59 2012 +0200 @@ -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 an integer for for function keys, + keypad keys and so, or a character for other keys. .. versionadded:: 3.3 diff -r 5b0595339c9d Lib/test/test_curses.py --- a/Lib/test/test_curses.py Sun Aug 26 07:33:10 2012 +0300 +++ b/Lib/test/test_curses.py Wed Aug 29 00:14:59 2012 +0200 @@ -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) diff -r 5b0595339c9d Modules/_cursesmodule.c --- a/Modules/_cursesmodule.c Sun Aug 26 07:33:10 2012 +0300 +++ b/Modules/_cursesmodule.c Wed Aug 29 00:14:59 2012 +0200 @@ -1203,7 +1203,10 @@ PyCursesWindow_Get_WCh(PyCursesWindowObj 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