mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-31680: Add curses.ncurses_version. (GH-4217)
Use curses.ncurses_version for conditionally skipping a test.
This commit is contained in:
parent
3e429dcc24
commit
b232df9197
5 changed files with 119 additions and 3 deletions
|
|
@ -4289,6 +4289,59 @@ _curses_use_default_colors_impl(PyObject *module)
|
|||
}
|
||||
#endif /* STRICT_SYSV_CURSES */
|
||||
|
||||
|
||||
#ifdef NCURSES_VERSION
|
||||
|
||||
PyDoc_STRVAR(ncurses_version__doc__,
|
||||
"curses.ncurses_version\n\
|
||||
\n\
|
||||
Ncurses version information as a named tuple.");
|
||||
|
||||
static PyTypeObject NcursesVersionType;
|
||||
|
||||
static PyStructSequence_Field ncurses_version_fields[] = {
|
||||
{"major", "Major release number"},
|
||||
{"minor", "Minor release number"},
|
||||
{"patch", "Patch release number"},
|
||||
{0}
|
||||
};
|
||||
|
||||
static PyStructSequence_Desc ncurses_version_desc = {
|
||||
"curses.ncurses_version", /* name */
|
||||
ncurses_version__doc__, /* doc */
|
||||
ncurses_version_fields, /* fields */
|
||||
3
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
make_ncurses_version(void)
|
||||
{
|
||||
PyObject *ncurses_version;
|
||||
int pos = 0;
|
||||
|
||||
ncurses_version = PyStructSequence_New(&NcursesVersionType);
|
||||
if (ncurses_version == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define SetIntItem(flag) \
|
||||
PyStructSequence_SET_ITEM(ncurses_version, pos++, PyLong_FromLong(flag)); \
|
||||
if (PyErr_Occurred()) { \
|
||||
Py_CLEAR(ncurses_version); \
|
||||
return NULL; \
|
||||
}
|
||||
|
||||
SetIntItem(NCURSES_VERSION_MAJOR)
|
||||
SetIntItem(NCURSES_VERSION_MINOR)
|
||||
SetIntItem(NCURSES_VERSION_PATCH)
|
||||
#undef SetIntItem
|
||||
|
||||
return ncurses_version;
|
||||
}
|
||||
|
||||
#endif /* NCURSES_VERSION */
|
||||
|
||||
|
||||
/* List of functions defined in the module */
|
||||
|
||||
static PyMethodDef PyCurses_methods[] = {
|
||||
|
|
@ -4426,6 +4479,30 @@ PyInit__curses(void)
|
|||
PyDict_SetItemString(d, "__version__", v);
|
||||
Py_DECREF(v);
|
||||
|
||||
#ifdef NCURSES_VERSION
|
||||
/* ncurses_version */
|
||||
if (NcursesVersionType.tp_name == NULL) {
|
||||
if (PyStructSequence_InitType2(&NcursesVersionType,
|
||||
&ncurses_version_desc) < 0)
|
||||
return NULL;
|
||||
}
|
||||
v = make_ncurses_version();
|
||||
if (v == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
PyDict_SetItemString(d, "ncurses_version", v);
|
||||
Py_DECREF(v);
|
||||
|
||||
/* prevent user from creating new instances */
|
||||
NcursesVersionType.tp_init = NULL;
|
||||
NcursesVersionType.tp_new = NULL;
|
||||
if (PyDict_DelItemString(NcursesVersionType.tp_dict, "__new__") < 0 &&
|
||||
PyErr_ExceptionMatches(PyExc_KeyError))
|
||||
{
|
||||
PyErr_Clear();
|
||||
}
|
||||
#endif /* NCURSES_VERSION */
|
||||
|
||||
SetDictInt("ERR", ERR);
|
||||
SetDictInt("OK", OK);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue