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 dcb5fd842fe96a9843540df5bc2a156cb66ec17b
parent 1db3cd96d85a242100fe98456f40c3743dd9c106
Author: Joris Vink <joris@coders.se>
Date:   Thu, 26 Jan 2017 12:01:28 +0100

Expose get/post params via req.argument for python.

Diffstat:
includes/python_methods.h | 2++
src/python.c | 22++++++++++++++++++++++
2 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/includes/python_methods.h b/includes/python_methods.h @@ -65,6 +65,7 @@ struct pyhttp_request { static void pyhttp_dealloc(struct pyhttp_request *); static PyObject *pyhttp_response(struct pyhttp_request *, PyObject *); +static PyObject *pyhttp_argument(struct pyhttp_request *, PyObject *); static PyObject *pyhttp_body_read(struct pyhttp_request *, PyObject *); static PyObject *pyhttp_populate_get(struct pyhttp_request *, PyObject *); static PyObject *pyhttp_populate_post(struct pyhttp_request *, PyObject *); @@ -73,6 +74,7 @@ static PyObject *pyhttp_response_header(struct pyhttp_request *, PyObject *); static PyMethodDef pyhttp_request_methods[] = { METHOD("response", pyhttp_response, METH_VARARGS), + METHOD("argument", pyhttp_argument, METH_VARARGS), METHOD("body_read", pyhttp_body_read, METH_VARARGS), METHOD("populate_get", pyhttp_populate_get, METH_NOARGS), METHOD("populate_post", pyhttp_populate_post, METH_NOARGS), diff --git a/src/python.c b/src/python.c @@ -658,6 +658,28 @@ pyhttp_populate_post(struct pyhttp_request *pyreq, PyObject *args) } static PyObject * +pyhttp_argument(struct pyhttp_request *pyreq, PyObject *args) +{ + const char *name; + PyObject *value; + char *string; + + if (!PyArg_ParseTuple(args, "s", &name)) { + PyErr_SetString(PyExc_TypeError, "invalid parameters"); + return (NULL); + } + + if (!http_argument_get_string(pyreq->req, name, &string)) { + Py_RETURN_NONE; + } + + if ((value = PyUnicode_FromString(string)) == NULL) + return (PyErr_NoMemory()); + + return (value); +} + +static PyObject * pyhttp_get_host(struct pyhttp_request *pyreq, void *closure) { PyObject *host;