nxt_python_asgi.c (1980:43553aa72111) nxt_python_asgi.c (2067:78864c9d5ba8)
1
2/*
3 * Copyright (C) NGINX, Inc.
4 */
5
6
7#include <python/nxt_python.h>
8

--- 103 unchanged lines hidden (view full) ---

112
113 if (PyFunction_Check(call)) {
114 return call;
115 }
116
117 if (PyMethod_Check(call)) {
118 obj = PyMethod_GET_FUNCTION(call);
119
1
2/*
3 * Copyright (C) NGINX, Inc.
4 */
5
6
7#include <python/nxt_python.h>
8

--- 103 unchanged lines hidden (view full) ---

112
113 if (PyFunction_Check(call)) {
114 return call;
115 }
116
117 if (PyMethod_Check(call)) {
118 obj = PyMethod_GET_FUNCTION(call);
119
120 Py_INCREF(obj);
121 Py_DECREF(call);
120 if (PyFunction_Check(obj)) {
121 Py_INCREF(obj);
122
122
123 return obj;
123 } else {
124 obj = NULL;
125 }
126
127 } else {
128 obj = NULL;
124 }
125
126 Py_DECREF(call);
127
129 }
130
131 Py_DECREF(call);
132
128 return NULL;
133 return obj;
129}
130
131
132int
133nxt_python_asgi_init(nxt_unit_init_t *init, nxt_python_proto_t *proto)
134{
135 PyObject *func;
136 nxt_int_t i;

--- 19 unchanged lines hidden (view full) ---

156
157 if (nxt_slow_path(nxt_py_asgi_websocket_init() == NXT_UNIT_ERROR)) {
158 return NXT_UNIT_ERROR;
159 }
160
161 for (i = 0; i < nxt_py_targets->count; i++) {
162 func = nxt_python_asgi_get_func(nxt_py_targets->target[i].application);
163 if (nxt_slow_path(func == NULL)) {
134}
135
136
137int
138nxt_python_asgi_init(nxt_unit_init_t *init, nxt_python_proto_t *proto)
139{
140 PyObject *func;
141 nxt_int_t i;

--- 19 unchanged lines hidden (view full) ---

161
162 if (nxt_slow_path(nxt_py_asgi_websocket_init() == NXT_UNIT_ERROR)) {
163 return NXT_UNIT_ERROR;
164 }
165
166 for (i = 0; i < nxt_py_targets->count; i++) {
167 func = nxt_python_asgi_get_func(nxt_py_targets->target[i].application);
168 if (nxt_slow_path(func == NULL)) {
164 nxt_unit_alert(NULL, "Python cannot find function for callable");
165 return NXT_UNIT_ERROR;
169 nxt_unit_debug(NULL, "asgi: cannot find function for callable, "
170 "unable to check for legacy mode (#%d)", i);
171 continue;
166 }
167
168 code = (PyCodeObject *) PyFunction_GET_CODE(func);
169
170 if ((code->co_flags & CO_COROUTINE) == 0) {
171 nxt_unit_debug(NULL, "asgi: callable is not a coroutine function "
172 "switching to legacy mode");
173 nxt_py_targets->target[i].asgi_legacy = 1;

--- 1280 unchanged lines hidden ---
172 }
173
174 code = (PyCodeObject *) PyFunction_GET_CODE(func);
175
176 if ((code->co_flags & CO_COROUTINE) == 0) {
177 nxt_unit_debug(NULL, "asgi: callable is not a coroutine function "
178 "switching to legacy mode");
179 nxt_py_targets->target[i].asgi_legacy = 1;

--- 1280 unchanged lines hidden ---