blob: a5c1d9a63e4b952ad1238d5f4df71141cba639e0 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
/*
* Copyright (C) NGINX, Inc.
*/
#ifndef _NXT_PYTHON_H_INCLUDED_
#define _NXT_PYTHON_H_INCLUDED_
#include <Python.h>
#include <nxt_main.h>
#include <nxt_unit.h>
#define NXT_PYTHON_VER(maj, min) ((maj << 24) | (min << 16))
#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
#define PyUnicode_GET_LENGTH PyUnicode_GET_SIZE
#endif
#if PY_VERSION_HEX >= NXT_PYTHON_VER(3, 5)
#define NXT_HAVE_ASGI 1
#endif
typedef struct {
PyObject *application;
nxt_bool_t asgi_legacy;
} nxt_python_target_t;
typedef struct {
nxt_int_t count;
nxt_python_target_t target[0];
} nxt_python_targets_t;
extern nxt_python_targets_t *nxt_py_targets;
typedef struct {
nxt_str_t string;
PyObject **object_p;
} nxt_python_string_t;
typedef struct {
int (*ctx_data_alloc)(void **pdata);
void (*ctx_data_free)(void *data);
int (*startup)(void *data);
int (*run)(nxt_unit_ctx_t *ctx);
int (*ready)(nxt_unit_ctx_t *ctx);
void (*done)(void);
} nxt_python_proto_t;
int nxt_python_init_strings(nxt_python_string_t *pstr);
void nxt_python_done_strings(nxt_python_string_t *pstr);
void nxt_python_print_exception(void);
int nxt_python_wsgi_init(nxt_unit_init_t *init, nxt_python_proto_t *proto);
int nxt_python_asgi_check(PyObject *obj);
int nxt_python_asgi_init(nxt_unit_init_t *init, nxt_python_proto_t *proto);
#endif /* _NXT_PYTHON_H_INCLUDED_ */
|