kore

Kore is a web application platform for writing scalable, concurrent web based processes in C or Python.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit 5c8efde84184739b26ad8d3bdf8ec113799bf34a
parent baafa4897e29d2c274bf6b271455214458dc2540
Author: Joris Vink <joris@coders.se>
Date:   Fri, 16 Nov 2018 11:07:21 +0100

allow foo.method symbols in python.

this way you can create page handlers that reside inside
of other objects.

eg:

static / restapi.index

Diffstat:
src/python.c | 35+++++++++++++++++++++++++++++------
1 file changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/python.c b/src/python.c @@ -1310,17 +1310,40 @@ python_import(const char *path) static PyObject * python_callable(PyObject *module, const char *symbol) { - PyObject *obj; + char *base, *method; + PyObject *res, *obj, *meth; - if ((obj = PyObject_GetAttrString(module, symbol)) == NULL) - return (NULL); + res = NULL; + obj = NULL; + base = kore_strdup(symbol); + + if ((method = strchr(base, '.')) != NULL) + *(method)++ = '\0'; + + if ((obj = PyObject_GetAttrString(module, base)) == NULL) + goto out; + + if (method != NULL) { + if ((meth = PyObject_GetAttrString(obj, method)) == NULL) + goto out; - if (!PyCallable_Check(obj)) { Py_DECREF(obj); - return (NULL); + obj = meth; } - return (obj); + if (!PyCallable_Check(obj)) + goto out; + + res = obj; + obj = NULL; + +out: + if (obj != NULL) + Py_DECREF(obj); + + kore_free(base); + + return (res); } static PyObject *