diff --git a/ChangeLog b/ChangeLog index be0daf29..8c5d3200 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,21 @@ *** september 2010 *** + * 0.9.6.5 [20100929] + +- PEP 3333 support +- fix --pythonpath with --wsgi-file +- x-wsgiorg.uwsgi.version renamed to uwsgi.version + + * 0.9.6.4 [20100925] + +- fix a stupid bug in conditional logging backport + + * 0.9.6.3 [20100925] + +- fix a buffer overflow in .ini parsing (it throws a glibc error on malloc) +- backport of conditional logging from 0.9.7-dev +- backport of backlog queue monitor from 0.9.7-dev (only Linux) + * 0.9.6.2 [20100915] - fix a regression in virtual hosting mode diff --git a/testpy3.py b/testpy3.py new file mode 100644 index 00000000..b54f16ca --- /dev/null +++ b/testpy3.py @@ -0,0 +1,14 @@ +import uwsgi + +def app1(e, sr): + print(e) + sr('200 Ok', [('Content-Type','text/plain')]) + return b'i Am a Python 3.x bytestring' + +def app2(e, sr): + print(e) + sr('404 Not Found', [('Content-Type','text/plain')]) + return b'i Am a Python 3.x Not Found page' + + +uwsgi.applications = {b'': app1, b'/test': app2} diff --git a/utils.c b/utils.c index e190fae9..038aa383 100644 --- a/utils.c +++ b/utils.c @@ -471,11 +471,7 @@ void sanitize_args(struct uwsgi_server *uwsgi) { #endif #endif - if (uwsgi->wsgi_config) { - uwsgi->single_interpreter = 1 ; - } - - if (uwsgi->wsgi_file) { + if (uwsgi->wsgi_config || uwsgi->wsgi_file || uwsgi->eval) { uwsgi->single_interpreter = 1 ; } diff --git a/uwsgi.c b/uwsgi.c index a53f6f0b..fb751b35 100644 --- a/uwsgi.c +++ b/uwsgi.c @@ -1612,20 +1612,21 @@ void init_uwsgi_vars() { // simulate a pythonhome directive if (uwsgi.wsgi_req->pyhome_len > 0) { - PyObject *venv_path = PyString_FromStringAndSize(uwsgi.wsgi_req->pyhome, uwsgi.wsgi_req->pyhome_len) ; + PyObject *venv_path = UWSGI_PYFROMSTRINGSIZE(uwsgi.wsgi_req->pyhome, uwsgi.wsgi_req->pyhome_len) ; #ifdef UWSGI_DEBUG - uwsgi_debug("setting dynamic virtualenv to %s\n", PyString_AsString(venv_path)); + uwsgi_debug("setting dynamic virtualenv to %.*s\n", uwsgi.wsgi_req->pyhome_len, uwsgi.wsgi_req->pyhome); #endif PyDict_SetItemString(pysys_dict, "prefix", venv_path); PyDict_SetItemString(pysys_dict, "exec_prefix", venv_path); venv_version[14] = 0 ; - if (snprintf(venv_version, 15, "/lib/python%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION) == -1) { + if (snprintf(venv_version, 15, "%.*s/lib/python%d.%d", PY_MAJOR_VERSION, PY_MINOR_VERSION) == -1) { return ; } + // check here PyString_Concat( &venv_path, PyString_FromString(venv_version) ); if ( PyList_Insert(pypath, 0, venv_path) ) { diff --git a/uwsgi.h b/uwsgi.h index 73f28b6e..8def1cb1 100644 --- a/uwsgi.h +++ b/uwsgi.h @@ -272,6 +272,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t); #ifdef PYTHREE #define UWSGI_PYFROMSTRING(x) PyUnicode_FromString(x) +#define UWSGI_PYFROMSTRINGSIZE(x, y) PyUnicode_FromStringAndSize(x, y) #define PyInt_FromLong PyLong_FromLong #define PyInt_AsLong PyLong_AsLong #define PyInt_Check PyLong_Check @@ -286,6 +287,7 @@ PyAPI_FUNC(PyObject *) PyMarshal_ReadObjectFromString(char *, Py_ssize_t); #else #define UWSGI_PYFROMSTRING(x) PyString_FromString(x) +#define UWSGI_PYFROMSTRINGSIZE(x, y) PyString_FromStringAndSize(x, y) #endif #define NL_SIZE 2 diff --git a/wsgi_handlers.c b/wsgi_handlers.c index 4f77a627..9ea9e13d 100644 --- a/wsgi_handlers.c +++ b/wsgi_handlers.c @@ -77,8 +77,6 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req size_t post_remains = wsgi_req->post_cl; ssize_t post_chunk; - PyObject *zero; - PyObject *pydictkey, *pydictvalue; static PyObject *uwsgi_version = NULL; @@ -92,6 +90,9 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req uwsgi_version = PyString_FromString(UWSGI_VERSION); } + char *what; + int what_len; + #ifdef UWSGI_ASYNC if (wsgi_req->async_status == UWSGI_AGAIN) { // get rid of timeout @@ -138,19 +139,19 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req wsgi_req->script_name = ""; if (uwsgi->vhost) { - zero = PyString_FromStringAndSize(wsgi_req->host, wsgi_req->host_len); - PyString_Concat(&zero, PyString_FromString("|")); - PyString_Concat(&zero, PyString_FromStringAndSize(wsgi_req->script_name, wsgi_req->script_name_len)); + what = uwsgi_concat3n(wsgi_req->host, wsgi_req->host_len, "|",1, wsgi_req->script_name, wsgi_req->script_name_len); + what_len = wsgi_req->host_len + 1 + wsgi_req->script_name_len ; #ifdef UWSGI_DEBUG - uwsgi_debug("VirtualHost SCRIPT_NAME=%s\n", PyString_AsString(zero)); + uwsgi_debug("VirtualHost SCRIPT_NAME=%s\n", what); #endif } else { - zero = PyString_FromStringAndSize(wsgi_req->script_name, wsgi_req->script_name_len); + what = wsgi_req->script_name; + what_len = wsgi_req->script_name_len ; } - if ( (wsgi_req->app_id = uwsgi_get_app_id(uwsgi, wsgi_req->script_name, wsgi_req->script_name_len)) == -1) { + if ( (wsgi_req->app_id = uwsgi_get_app_id(uwsgi, what, what_len)) == -1) { if (wsgi_req->script_name_len > 1 || uwsgi->default_app < 0 || uwsgi->vhost) { /* unavailable app for this SCRIPT_NAME */ wsgi_req->app_id = -1; @@ -160,7 +161,6 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req } } - Py_DECREF(zero); } else { wsgi_req->app_id = 0; @@ -233,8 +233,13 @@ int uwsgi_request_wsgi(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req uwsgi_debug("%.*s: %.*s\n", wsgi_req->hvec[i].iov_len, wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i+1].iov_len, wsgi_req->hvec[i+1].iov_base); #endif */ +#ifdef PYTHREE + pydictkey = PyUnicode_DecodeLatin1(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len, "ignore"); + pydictvalue = PyUnicode_DecodeLatin1(wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len, "ignore"); +#else pydictkey = PyString_FromStringAndSize(wsgi_req->hvec[i].iov_base, wsgi_req->hvec[i].iov_len); pydictvalue = PyString_FromStringAndSize(wsgi_req->hvec[i + 1].iov_base, wsgi_req->hvec[i + 1].iov_len); +#endif PyDict_SetItem(wsgi_req->async_environ, pydictkey, pydictvalue); Py_DECREF(pydictkey); Py_DECREF(pydictvalue); diff --git a/wsgi_headers.c b/wsgi_headers.c index f1f06a88..c3f77ca9 100644 --- a/wsgi_headers.c +++ b/wsgi_headers.c @@ -6,6 +6,8 @@ static char *nl = "\r\n"; static char *h_sep = ": "; static const char *http_protocol = "HTTP/1.1"; +// check here + PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { PyObject *headers, *head; PyObject *h_key, *h_value; @@ -20,7 +22,7 @@ PyObject *py_uwsgi_spit(PyObject * self, PyObject * args) { // is a Web3 response ? if (PyTuple_Size(args) == 3) { - shift = 1; + shift = 0; } head = PyTuple_GetItem(args, 0+shift);