11592Smax.romanov@nginx.com 21592Smax.romanov@nginx.com /* 31592Smax.romanov@nginx.com * Copyright (C) NGINX, Inc. 41592Smax.romanov@nginx.com */ 51592Smax.romanov@nginx.com 61592Smax.romanov@nginx.com #ifndef _NXT_PYTHON_H_INCLUDED_ 71592Smax.romanov@nginx.com #define _NXT_PYTHON_H_INCLUDED_ 81592Smax.romanov@nginx.com 91592Smax.romanov@nginx.com 101592Smax.romanov@nginx.com #include <Python.h> 111624Smax.romanov@nginx.com #include <nxt_main.h> 121592Smax.romanov@nginx.com #include <nxt_unit.h> 131592Smax.romanov@nginx.com 141592Smax.romanov@nginx.com 151624Smax.romanov@nginx.com #if PY_MAJOR_VERSION == 3 161624Smax.romanov@nginx.com #define NXT_PYTHON_BYTES_TYPE "bytestring" 171624Smax.romanov@nginx.com 181624Smax.romanov@nginx.com #define PyString_FromStringAndSize(str, size) \ 191624Smax.romanov@nginx.com PyUnicode_DecodeLatin1((str), (size), "strict") 201624Smax.romanov@nginx.com #define PyString_AS_STRING PyUnicode_DATA 211624Smax.romanov@nginx.com 221624Smax.romanov@nginx.com #else 231624Smax.romanov@nginx.com #define NXT_PYTHON_BYTES_TYPE "string" 241624Smax.romanov@nginx.com 251624Smax.romanov@nginx.com #define PyBytes_FromStringAndSize PyString_FromStringAndSize 261624Smax.romanov@nginx.com #define PyBytes_Check PyString_Check 271624Smax.romanov@nginx.com #define PyBytes_GET_SIZE PyString_GET_SIZE 281624Smax.romanov@nginx.com #define PyBytes_AS_STRING PyString_AS_STRING 291624Smax.romanov@nginx.com #define PyUnicode_InternInPlace PyString_InternInPlace 301624Smax.romanov@nginx.com #define PyUnicode_AsUTF8 PyString_AS_STRING 31*1648Svbart@nginx.com #define PyUnicode_GET_LENGTH PyUnicode_GET_SIZE 321624Smax.romanov@nginx.com #endif 331624Smax.romanov@nginx.com 341624Smax.romanov@nginx.com #if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5 351624Smax.romanov@nginx.com #define NXT_HAVE_ASGI 1 361624Smax.romanov@nginx.com #endif 371624Smax.romanov@nginx.com 381592Smax.romanov@nginx.com extern PyObject *nxt_py_application; 391592Smax.romanov@nginx.com 401592Smax.romanov@nginx.com typedef struct { 411592Smax.romanov@nginx.com nxt_str_t string; 421592Smax.romanov@nginx.com PyObject **object_p; 431592Smax.romanov@nginx.com } nxt_python_string_t; 441592Smax.romanov@nginx.com 451624Smax.romanov@nginx.com 461592Smax.romanov@nginx.com nxt_int_t nxt_python_init_strings(nxt_python_string_t *pstr); 471592Smax.romanov@nginx.com void nxt_python_done_strings(nxt_python_string_t *pstr); 481592Smax.romanov@nginx.com 491592Smax.romanov@nginx.com void nxt_python_print_exception(void); 501592Smax.romanov@nginx.com 511592Smax.romanov@nginx.com nxt_int_t nxt_python_wsgi_init(nxt_task_t *task, nxt_unit_init_t *init); 521592Smax.romanov@nginx.com int nxt_python_wsgi_run(nxt_unit_ctx_t *ctx); 531592Smax.romanov@nginx.com void nxt_python_wsgi_done(void); 541592Smax.romanov@nginx.com 551624Smax.romanov@nginx.com int nxt_python_asgi_check(PyObject *obj); 561624Smax.romanov@nginx.com nxt_int_t nxt_python_asgi_init(nxt_task_t *task, nxt_unit_init_t *init); 571624Smax.romanov@nginx.com nxt_int_t nxt_python_asgi_run(nxt_unit_ctx_t *ctx); 581624Smax.romanov@nginx.com void nxt_python_asgi_done(void); 591624Smax.romanov@nginx.com 601592Smax.romanov@nginx.com 611592Smax.romanov@nginx.com #endif /* _NXT_PYTHON_H_INCLUDED_ */ 62