From c4c2f90c5b532c1ec283d211e0fd50e4538c2a51 Mon Sep 17 00:00:00 2001 From: Max Romanov Date: Thu, 1 Oct 2020 23:55:23 +0300 Subject: Python: ASGI server introduced. This closes #461 issue on GitHub. --- src/python/nxt_python.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'src/python/nxt_python.h') diff --git a/src/python/nxt_python.h b/src/python/nxt_python.h index 417df7fd..3211026b 100644 --- a/src/python/nxt_python.h +++ b/src/python/nxt_python.h @@ -8,9 +8,32 @@ #include +#include #include +#if PY_MAJOR_VERSION == 3 +#define NXT_PYTHON_BYTES_TYPE "bytestring" + +#define PyString_FromStringAndSize(str, size) \ + PyUnicode_DecodeLatin1((str), (size), "strict") +#define PyString_AS_STRING PyUnicode_DATA + +#else +#define NXT_PYTHON_BYTES_TYPE "string" + +#define PyBytes_FromStringAndSize PyString_FromStringAndSize +#define PyBytes_Check PyString_Check +#define PyBytes_GET_SIZE PyString_GET_SIZE +#define PyBytes_AS_STRING PyString_AS_STRING +#define PyUnicode_InternInPlace PyString_InternInPlace +#define PyUnicode_AsUTF8 PyString_AS_STRING +#endif + +#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5 +#define NXT_HAVE_ASGI 1 +#endif + extern PyObject *nxt_py_application; typedef struct { @@ -18,6 +41,7 @@ typedef struct { PyObject **object_p; } nxt_python_string_t; + nxt_int_t nxt_python_init_strings(nxt_python_string_t *pstr); void nxt_python_done_strings(nxt_python_string_t *pstr); @@ -27,5 +51,10 @@ nxt_int_t nxt_python_wsgi_init(nxt_task_t *task, nxt_unit_init_t *init); int nxt_python_wsgi_run(nxt_unit_ctx_t *ctx); void nxt_python_wsgi_done(void); +int nxt_python_asgi_check(PyObject *obj); +nxt_int_t nxt_python_asgi_init(nxt_task_t *task, nxt_unit_init_t *init); +nxt_int_t nxt_python_asgi_run(nxt_unit_ctx_t *ctx); +void nxt_python_asgi_done(void); + #endif /* _NXT_PYTHON_H_INCLUDED_ */ -- cgit