--pyshell and fix for wsgi.url_scheme in pep3333

This commit is contained in:
roberto@debian32
2011-08-03 15:07:15 +02:00
parent 9aad6be26a
commit cd29998b40
8 changed files with 48 additions and 14 deletions
+3 -3
View File
@@ -286,13 +286,13 @@ int init_uwsgi_app(int loader, void *arg1, struct wsgi_request *wsgi_req, PyThre
wi->gateway_version = PyTuple_New(2);
PyTuple_SetItem(wi->gateway_version, 0, PyInt_FromLong(1));
PyTuple_SetItem(wi->gateway_version, 1, PyInt_FromLong(0));
Py_INCREF(wi->gateway_version);
Py_INCREF((PyObject *)wi->gateway_version);
wi->uwsgi_version = PyString_FromString(UWSGI_VERSION);
Py_INCREF(wi->uwsgi_version);
Py_INCREF((PyObject *)wi->uwsgi_version);
wi->uwsgi_node = PyString_FromString(uwsgi.hostname);
Py_INCREF(wi->uwsgi_node);
Py_INCREF((PyObject *)wi->uwsgi_node);
if (uwsgi.threads > 1 && id) {
// if we have multiple threads we need to initialize a PyThreadState for each one
+16
View File
@@ -44,6 +44,7 @@ struct option uwsgi_python_options[] = {
{"pep3333-input", no_argument, &up.pep3333_input, 1},
{"reload-os-env", no_argument, &up.reload_os_env, 1},
{"no-site", no_argument, &Py_NoSiteFlag, 1},
{"pyshell", no_argument, 0, LONG_ARGS_PYSHELL},
{0, 0, 0, 0},
};
@@ -703,6 +704,11 @@ int uwsgi_python_manage_options(int i, char *optarg) {
uwsgi_log("you can specify at most %d --pymodule-alias options\n", MAX_PYMODULE_ALIAS);
}
return 1;
case LONG_ARGS_PYSHELL:
uwsgi.honour_stdin = 1;
up.pyshell = 1;
uwsgi.to_hell = 1;
return 1;
case LONG_ARGS_PYIMPORT:
uwsgi_string_new_list(&up.import_list, optarg);
return 1;
@@ -1219,6 +1225,14 @@ void uwsgi_python_fixup() {
uwsgi.p[30] = uwsgi.p[0];
}
void uwsgi_python_hijack(void) {
if (up.pyshell) {
PyImport_ImportModule("readline");
PyRun_InteractiveLoop(stdin, "uwsgi");
exit(0);
}
}
struct uwsgi_plugin python_plugin = {
.name = "python",
@@ -1247,6 +1261,8 @@ struct uwsgi_plugin python_plugin = {
.suspend = uwsgi_python_suspend,
.resume = uwsgi_python_resume,
.hijack_worker = uwsgi_python_hijack,
.signal_handler = uwsgi_python_signal_handler,
.rpc = uwsgi_python_rpc,
+3
View File
@@ -18,6 +18,7 @@
#define LONG_ARGS_WEB3 LONG_ARGS_PYTHON_BASE + 8
#define LONG_ARGS_PUMP LONG_ARGS_PYTHON_BASE + 9
#define LONG_ARGS_WSGI_LITE LONG_ARGS_PYTHON_BASE + 10
#define LONG_ARGS_PYSHELL LONG_ARGS_PYTHON_BASE + 11
#define PYTHON_APP_TYPE_WSGI 0
#define PYTHON_APP_TYPE_WEB3 1
@@ -123,6 +124,8 @@ struct uwsgi_python {
char *test_module;
int pyshell;
struct uwsgi_string_list *python_path;
struct uwsgi_string_list *import_list;
struct uwsgi_string_list *post_pymodule_alias;
+4 -4
View File
@@ -81,18 +81,18 @@ void *uwsgi_request_subhandler_web3(struct wsgi_request *wsgi_req, struct uwsgi_
}
if (wsgi_req->scheme_len > 0) {
zero = PyString_FromStringAndSize(wsgi_req->scheme, wsgi_req->scheme_len);
zero = UWSGI_PYFROMSTRINGSIZE(wsgi_req->scheme, wsgi_req->scheme_len);
}
else if (wsgi_req->https_len > 0) {
if (!strncasecmp(wsgi_req->https, "on", 2) || wsgi_req->https[0] == '1') {
zero = PyString_FromString("https");
zero = UWSGI_PYFROMSTRING("https");
}
else {
zero = PyString_FromString("http");
zero = UWSGI_PYFROMSTRING("http");
}
}
else {
zero = PyString_FromString("http");
zero = UWSGI_PYFROMSTRING("http");
}
PyDict_SetItemString(wsgi_req->async_environ, "web3.url_scheme", zero);
Py_DECREF(zero);
+4 -4
View File
@@ -97,18 +97,18 @@ void *uwsgi_request_subhandler_wsgi(struct wsgi_request *wsgi_req, struct uwsgi_
}
if (wsgi_req->scheme_len > 0) {
zero = PyString_FromStringAndSize(wsgi_req->scheme, wsgi_req->scheme_len);
zero = UWSGI_PYFROMSTRINGSIZE(wsgi_req->scheme, wsgi_req->scheme_len);
}
else if (wsgi_req->https_len > 0) {
if (!strncasecmp(wsgi_req->https, "on", 2) || wsgi_req->https[0] == '1') {
zero = PyString_FromString("https");
zero = UWSGI_PYFROMSTRING("https");
}
else {
zero = PyString_FromString("http");
zero = UWSGI_PYFROMSTRING("http");
}
}
else {
zero = PyString_FromString("http");
zero = UWSGI_PYFROMSTRING("http");
}
PyDict_SetItemString(wsgi_req->async_environ, "wsgi.url_scheme", zero);
Py_DECREF(zero);
-2
View File
@@ -231,10 +231,8 @@ void spooler() {
if (interesting_fd == uwsgi.shared->spooler_signal_pipe[1]) {
uint8_t uwsgi_signal;
if (read(interesting_fd, &uwsgi_signal, 1) <= 0) {
if (uwsgi.no_orphans) {
uwsgi_log_verbose("uWSGI spooler screams: UAAAAAAH my master died, i will follow him...\n");
end_me(0);
}
}
else {
#ifdef UWSGI_DEBUG
+14 -1
View File
@@ -1824,7 +1824,7 @@ int uwsgi_start(void *v_argv) {
uwsgi_log("uwsgi socket %d inherited INET address %s fd 0\n", uwsgi_get_socket_num(uwsgi_sock), uwsgi_sock->name);
}
}
else {
else if (!uwsgi.honour_stdin) {
int fd = open("/dev/null", O_RDONLY);
if (fd < 0) {
uwsgi_error_open("/dev/null");
@@ -2200,6 +2200,19 @@ skipzero:
//from now on the process is a real worker
}
for (i = 0; i < 0xFF; i++) {
if (uwsgi.p[i]->hijack_worker) {
uwsgi.p[i]->hijack_worker();
}
}
for (i = 0; i < uwsgi.gp_cnt; i++) {
if (uwsgi.gp[i]->hijack_worker) {
uwsgi.gp[i]->hijack_worker();
}
}
uwsgi_sock = uwsgi.sockets;
while (uwsgi_sock) {
struct uwsgi_string_list *usl = uwsgi.map_socket;
+4
View File
@@ -600,6 +600,8 @@ struct uwsgi_plugin {
void (*suspend) (struct wsgi_request *);
void (*resume) (struct wsgi_request *);
void (*hijack_worker) (void);
int (*magic) (char *, char *);
void *(*encode_string) (char *);
@@ -976,6 +978,8 @@ struct uwsgi_server {
int log_micros;
char *log_strftime;
int honour_stdin;
int log_master;
int log_syslog;
int original_log_fd;