From 00bd8cc52536bcc73a6ee9f4ab8017fdcbc40bc4 Mon Sep 17 00:00:00 2001 From: Unbit Date: Sat, 6 Apr 2013 07:44:12 +0200 Subject: [PATCH] improved pyshell --- plugins/python/python_plugin.c | 24 +++++++++++++++++------- plugins/python/uwsgi_python.h | 2 +- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/plugins/python/python_plugin.c b/plugins/python/python_plugin.c index 1de43f30..1bb63d82 100644 --- a/plugins/python/python_plugin.c +++ b/plugins/python/python_plugin.c @@ -25,7 +25,12 @@ void uwsgi_opt_pythonpath(char *opt, char *value, void *foobar) { void uwsgi_opt_pyshell(char *opt, char *value, void *foobar) { uwsgi.honour_stdin = 1; - up.pyshell = 1; + if (value) { + up.pyshell = value; + } + else { + up.pyshell = ""; + } if (!strcmp("pyshell-oneshot", opt)) { up.pyshell_oneshot = 1; @@ -127,8 +132,8 @@ struct uwsgi_option uwsgi_python_options[] = { {"no-site", no_argument, 0, "do not import site module", uwsgi_opt_true, &Py_NoSiteFlag, 0}, #endif #endif - {"pyshell", no_argument, 0, "run an interactive python shell in the uWSGI environment", uwsgi_opt_pyshell, NULL, 0}, - {"pyshell-oneshot", no_argument, 0, "run an interactive python shell in the uWSGI environment (one-shot variant)", uwsgi_opt_pyshell, NULL, 0}, + {"pyshell", optional_argument, 0, "run an interactive python shell in the uWSGI environment", uwsgi_opt_pyshell, NULL, 0}, + {"pyshell-oneshot", optional_argument, 0, "run an interactive python shell in the uWSGI environment (one-shot variant)", uwsgi_opt_pyshell, NULL, 0}, {"python", required_argument, 0, "run a python script in the uWSGI environment", uwsgi_opt_pyrun, NULL, 0}, {"py", required_argument, 0, "run a python script in the uWSGI environment", uwsgi_opt_pyrun, NULL, 0}, @@ -1688,11 +1693,17 @@ void uwsgi_python_hijack(void) { } } UWSGI_GET_GIL; - PyImport_ImportModule("readline"); + int ret = -1; + if (up.pyshell[0] != 0) { + ret = PyRun_SimpleString(up.pyshell); + } + else { + PyImport_ImportModule("readline"); #ifndef UWSGI_PYPY - int ret = PyRun_InteractiveLoop(stdin, "uwsgi"); - + ret = PyRun_InteractiveLoop(stdin, "uwsgi"); +#endif + } if (up.pyshell_oneshot) { exit(UWSGI_DE_HIJACKED_CODE); } @@ -1700,7 +1711,6 @@ void uwsgi_python_hijack(void) { if (ret == 0) { exit(UWSGI_QUIET_CODE); } -#endif exit(0); } } diff --git a/plugins/python/uwsgi_python.h b/plugins/python/uwsgi_python.h index 30901c33..a10a5b2c 100644 --- a/plugins/python/uwsgi_python.h +++ b/plugins/python/uwsgi_python.h @@ -106,7 +106,7 @@ struct uwsgi_python { char *test_module; - int pyshell; + char *pyshell; int pyshell_oneshot;