cpython: c3581ca21a57 (original) (raw)

--- a/Doc/library/curses.rst +++ b/Doc/library/curses.rst @@ -653,7 +653,7 @@ Window Objects -------------- Window objects, as returned by :func:initscr and :func:newwin above, have -the following methods: +the following methods and attributes: .. method:: window.addch([y, x,] ch[, attr]) @@ -834,6 +834,16 @@ the following methods: event. +.. attribute:: window.encoding +

+ .. method:: window.erase() Clear the window.

--- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -333,6 +333,11 @@ function to the :mod:crypt module. curses ------

--- a/Include/py_curses.h +++ b/Include/py_curses.h @@ -76,6 +76,7 @@ extern "C" { typedef struct { PyObject_HEAD WINDOW *win; + char *encoding; } PyCursesWindowObject; #define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)

--- a/Lib/test/test_curses.py +++ b/Lib/test/test_curses.py @@ -267,24 +267,42 @@ def test_issue6243(stdscr): def test_unget_wch(stdscr): if not hasattr(curses, 'unget_wch'): return

def test_issue10570(): b = curses.tparm(curses.tigetstr("cup"), 5, 3) assert type(b) is bytes curses.putp(b) +def test_encoding(stdscr):

+ def main(stdscr): curses.savetty() try: @@ -295,6 +313,7 @@ def main(stdscr): test_issue6243(stdscr) test_unget_wch(stdscr) test_issue10570()

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -395,6 +395,10 @@ Core and Builtins Library ------- +- Issue #12567: The curses module uses Unicode functions for Unicode arguments

--- a/Modules/_cursesmodule.c +++ b/Modules/_cursesmodule.c @@ -121,6 +121,10 @@ extern int setupterm(char *,int,int ); #include <term.h> #endif +#ifdef HAVE_LANGINFO_H +#include <langinfo.h> +#endif + #if !defined(HAVE_NCURSES_H) && (defined(sgi) || defined(__sun) || defined(SCO5)) #define STRICT_SYSV_CURSES / Don't use ncurses extensions / typedef chtype attr_t; / No attr_t type is available / @@ -143,6 +147,8 @@ static int initialised = FALSE; / Tells whether start_color() has been called to initialise color usage. */ static int initialisedcolors = FALSE; +static char screen_encoding = NULL; + / Utility Macros */ #define PyCursesSetupTermCalled [](#l6.21) if (initialised_setupterm != TRUE) { [](#l6.22) @@ -175,7 +181,7 @@ static int initialisedcolors = FALSE; */ static PyObject * -PyCursesCheckERR(int code, char *fname) +PyCursesCheckERR(int code, const char *fname) { if (code != ERR) { Py_INCREF(Py_None); @@ -190,28 +196,193 @@ PyCursesCheckERR(int code, char fname) } } +/ Convert an object to a byte (an integer of type chtype): +

+} + +/* Convert an object to a byte (chtype) or a character (cchar_t): +

+

+static int +PyCurses_ConvertToCchar_t(PyCursesWindowObject *win, PyObject *obj,

+#ifdef HAVE_NCURSESW

+#endif

+{

+#ifdef HAVE_NCURSESW

+#endif +

+#ifdef HAVE_NCURSESW

+#else

+#endif

+#ifdef HAVE_NCURSESW

+#else

+#endif

+#ifdef HAVE_NCURSESW

+#endif

+} + +/* Convert an object to a byte string (char*) or a wide character string

+static int +PyCurses_ConvertToString(PyCursesWindowObject *win, PyObject *obj,

+{

+#ifdef HAVE_NCURSESW

+#else

+#endif

+

} /* Function versions of the 3 functions for testing whether curses has been @@ -357,13 +528,37 @@ Window_TwoArgNoReturnFunction(wresize, i /* Allocation and deallocation of Window Objects */ static PyObject * -PyCursesWindow_New(WINDOW *win) +PyCursesWindow_New(WINDOW *win, const char *encoding) { PyCursesWindowObject *wo;

+#if defined(MS_WINDOWS)

+#elif defined(CODESET)

+#endif

+ wo = PyObject_NEW(PyCursesWindowObject, &PyCursesWindow_Type); if (wo == NULL) return NULL; wo->win = win;

@@ -371,6 +566,8 @@ static void PyCursesWindow_Dealloc(PyCursesWindowObject *wo) { if (wo->win != stdscr) delwin(wo->win);

+#ifdef HAVE_NCURSESW

+#endif attr_t attr = A_NORMAL; long lattr;

switch (PyTuple_Size(args)) { case 1:

@@ -412,17 +614,33 @@ PyCursesWindow_AddCh(PyCursesWindowObjec return NULL; }

+#ifdef HAVE_NCURSESW

+#else

+#endif

} static PyObject * @@ -430,29 +648,34 @@ PyCursesWindow_AddStr(PyCursesWindowObje { int rtn; int x, y;

+#ifdef HAVE_NCURSESW

+#endif attr_t attr = A_NORMAL , attr_old = A_NORMAL; long lattr; int use_xy = FALSE, use_attr = FALSE;

switch (PyTuple_Size(args)) { case 1:

@@ -461,47 +684,74 @@ PyCursesWindow_AddStr(PyCursesWindowObje PyErr_SetString(PyExc_TypeError, "addstr requires 1 to 4 arguments"); return NULL; } - +#ifdef HAVE_NCURSESW

+#else

+#endif

+#ifdef HAVE_NCURSESW

+#endif

} static PyObject * PyCursesWindow_AddNStr(PyCursesWindowObject *self, PyObject *args) { int rtn, x, y, n;

+#ifdef HAVE_NCURSESW

+#endif attr_t attr = A_NORMAL , attr_old = A_NORMAL; long lattr; int use_xy = FALSE, use_attr = FALSE;

switch (PyTuple_Size(args)) { case 2:

@@ -510,18 +760,41 @@ PyCursesWindow_AddNStr(PyCursesWindowObj PyErr_SetString(PyExc_TypeError, "addnstr requires 2 to 5 arguments"); return NULL; } +#ifdef HAVE_NCURSESW

+#else

+#endif

if (use_attr == TRUE) { attr_old = getattrs(self->win); (void)wattrset(self->win,attr); }

+#ifdef HAVE_NCURSESW

+#endif

} static PyObject * @@ -547,10 +820,8 @@ PyCursesWindow_Bkgd(PyCursesWindowObject return NULL; }

return PyCursesCheckERR(wbkgd(self->win, bkgd | attr), "bkgd"); } @@ -605,10 +876,8 @@ PyCursesWindow_BkgdSet(PyCursesWindowObj return NULL; }

wbkgdset(self->win, bkgd | attr); return PyCursesCheckERR(0, "bkgdset"); @@ -633,11 +902,8 @@ PyCursesWindow_Border(PyCursesWindowObje return NULL; for(i=0; i<8; i++) {

} static PyObject * @@ -810,10 +1076,8 @@ PyCursesWindow_EchoChar(PyCursesWindowOb return NULL; }

#ifdef WINDOW_HAS_FLAGS if (self->win->_flags & _ISPAD) @@ -1034,11 +1298,8 @@ PyCursesWindow_Hline(PyCursesWindowObjec } if (code != ERR) {

@@ -1079,11 +1340,8 @@ PyCursesWindow_InsCh(PyCursesWindowObjec return NULL; }

if (use_xy == TRUE) rtn = mvwinsch(self->win,y,x, ch | attr); @@ -1154,29 +1412,34 @@ PyCursesWindow_InsStr(PyCursesWindowObje { int rtn; int x, y;

+#ifdef HAVE_NCURSESW

+#endif attr_t attr = A_NORMAL , attr_old = A_NORMAL; long lattr; int use_xy = FALSE, use_attr = FALSE;

switch (PyTuple_Size(args)) { case 1:

@@ -1186,46 +1449,75 @@ PyCursesWindow_InsStr(PyCursesWindowObje return NULL; } +#ifdef HAVE_NCURSESW

+#else

+#endif

+ if (use_attr == TRUE) { attr_old = getattrs(self->win); (void)wattrset(self->win,attr); }

+#ifdef HAVE_NCURSESW

+#endif

} static PyObject * PyCursesWindow_InsNStr(PyCursesWindowObject *self, PyObject *args) { int rtn, x, y, n;

+#ifdef HAVE_NCURSESW

+#endif attr_t attr = A_NORMAL , attr_old = A_NORMAL; long lattr; int use_xy = FALSE, use_attr = FALSE;

switch (PyTuple_Size(args)) { case 2:

@@ -1235,17 +1527,41 @@ PyCursesWindow_InsNStr(PyCursesWindowObj return NULL; } +#ifdef HAVE_NCURSESW

+#else

+#endif

+ if (use_attr == TRUE) { attr_old = getattrs(self->win); (void)wattrset(self->win,attr); }

+#ifdef HAVE_NCURSESW

+#endif

} static PyObject * @@ -1528,7 +1844,7 @@ PyCursesWindow_SubWin(PyCursesWindowObje return NULL; }

} static PyObject * @@ -1604,16 +1920,51 @@ PyCursesWindow_Vline(PyCursesWindowObjec } if (code != ERR) {

} +static PyObject * +PyCursesWindow_get_encoding(PyCursesWindowObject *self, void *closure) +{

+} + +static int +PyCursesWindow_set_encoding(PyCursesWindowObject *self, PyObject *value) +{

+

+

+} + + static PyMethodDef PyCursesWindow_Methods[] = { {"addch", (PyCFunction)PyCursesWindow_AddCh, METH_VARARGS}, {"addnstr", (PyCFunction)PyCursesWindow_AddNStr, METH_VARARGS}, @@ -1701,6 +2052,13 @@ static PyMethodDef PyCursesWindow_Method {NULL, NULL} /* sentinel */ }; +static PyGetSetDef PyCursesWindow_getsets[] = {

+}; + /* -------------------------------------------------------*/ PyTypeObject PyCursesWindow_Type = { @@ -1733,6 +2091,8 @@ PyTypeObject PyCursesWindow_Type = { 0, /tp_iter/ 0, /tp_iternext/ PyCursesWindow_Methods, /tp_methods/

}; /********************************************************************* @@ -1956,7 +2316,7 @@ PyCurses_GetWin(PyCursesWindowObject *se PyErr_SetString(PyCursesError, catchall_NULL); return NULL; }

} static PyObject * @@ -2034,10 +2394,11 @@ static PyObject * PyCurses_InitScr(PyObject *self) { WINDOW *win;

if (initialised == TRUE) { wrefresh(stdscr);

} static PyObject * @@ -2331,7 +2694,7 @@ PyCurses_NewPad(PyObject *self, PyObject return NULL; }

} static PyObject * @@ -2363,7 +2726,7 @@ PyCurses_NewWindow(PyObject *self, PyObj return NULL; }

} static PyObject * @@ -2680,10 +3043,8 @@ PyCurses_UnCtrl(PyObject *self, PyObject if (!PyArg_ParseTuple(args,"O;ch or int",&temp)) return NULL;

return PyBytes_FromString(unctrl(ch)); } @@ -2696,12 +3057,11 @@ PyCurses_UngetCh(PyObject *self, PyObjec PyCursesInitialised;

-

+

return PyCursesCheckERR(ungetch(ch), "ungetch"); }