allow foo.method symbols in python.

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

eg:

static / restapi.index
This commit is contained in:
Joris Vink 2018-11-16 11:07:21 +01:00
parent baafa4897e
commit 5c8efde841
1 changed files with 29 additions and 6 deletions

View File

@ -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 *