summaryrefslogtreecommitdiffstats
path: root/Python/sysmodule.c
diff options
context:
space:
mode:
authorYury Selivanov <yselivanov@sprymix.com>2015-05-12 02:57:16 (GMT)
committerYury Selivanov <yselivanov@sprymix.com>2015-05-12 02:57:16 (GMT)
commit7544508f0245173bff5866aa1598c8f6cce1fc5f (patch)
treebf80850d9cd46fc811f04b8c2484fb50775c697d /Python/sysmodule.c
parent4e6bf4b3da03b132b0698f30ee931a350585b117 (diff)
downloadcpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.zip
cpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.tar.gz
cpython-7544508f0245173bff5866aa1598c8f6cce1fc5f.tar.bz2
PEP 0492 -- Coroutines with async and await syntax. Issue #24017.
Diffstat (limited to 'Python/sysmodule.c')
-rw-r--r--Python/sysmodule.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/Python/sysmodule.c b/Python/sysmodule.c
index 9ec2521..bf9a96f 100644
--- a/Python/sysmodule.c
+++ b/Python/sysmodule.c
@@ -645,6 +645,49 @@ sys_setrecursionlimit(PyObject *self, PyObject *args)
return Py_None;
}
+static PyObject *
+sys_set_coroutine_wrapper(PyObject *self, PyObject *wrapper)
+{
+ if (wrapper != Py_None) {
+ if (!PyCallable_Check(wrapper)) {
+ PyErr_Format(PyExc_TypeError,
+ "callable expected, got %.50s",
+ Py_TYPE(wrapper)->tp_name);
+ return NULL;
+ }
+
+ PyEval_SetCoroutineWrapper(wrapper);
+ }
+ else
+ PyEval_SetCoroutineWrapper(NULL);
+ Py_INCREF(Py_None);
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(set_coroutine_wrapper_doc,
+"set_coroutine_wrapper(wrapper)\n\
+\n\
+Set a wrapper for coroutine objects."
+);
+
+static PyObject *
+sys_get_coroutine_wrapper(PyObject *self, PyObject *args)
+{
+ PyObject *wrapper = PyEval_GetCoroutineWrapper();
+ if (wrapper == NULL) {
+ wrapper = Py_None;
+ }
+ Py_INCREF(wrapper);
+ return wrapper;
+}
+
+PyDoc_STRVAR(get_coroutine_wrapper_doc,
+"get_coroutine_wrapper()\n\
+\n\
+Return the wrapper for coroutine objects set by sys.set_coroutine_wrapper."
+);
+
+
static PyTypeObject Hash_InfoType;
PyDoc_STRVAR(hash_info_doc,
@@ -1215,6 +1258,10 @@ static PyMethodDef sys_methods[] = {
{"call_tracing", sys_call_tracing, METH_VARARGS, call_tracing_doc},
{"_debugmallocstats", sys_debugmallocstats, METH_NOARGS,
debugmallocstats_doc},
+ {"set_coroutine_wrapper", sys_set_coroutine_wrapper, METH_O,
+ set_coroutine_wrapper_doc},
+ {"get_coroutine_wrapper", sys_get_coroutine_wrapper, METH_NOARGS,
+ get_coroutine_wrapper_doc},
{NULL, NULL} /* sentinel */
};