summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham Dumpleton <Graham.Dumpleton@gmail.com>2017-01-21 14:16:00 +1100
committerGraham Dumpleton <Graham.Dumpleton@gmail.com>2017-01-21 14:16:00 +1100
commit0fc3da69e96f6f3ee392b1150494e337fca7934b (patch)
tree3c8c0363862ed07e7d94f4fe172e7d87028ab7e7
parent5a3ee55ad0ec61644cc37b289fbf772b625545c5 (diff)
downloadmod_wsgi-0fc3da69e96f6f3ee392b1150494e337fca7934b.tar.gz
Expose name attribute on the log object to avoid code failing which doesn’t cope with fact that it doesn’t have to exist.
-rw-r--r--docs/release-notes.rst1
-rw-r--r--docs/release-notes/version-4.5.14.rst17
-rw-r--r--src/server/mod_wsgi.c2
-rw-r--r--src/server/wsgi_interp.c4
-rw-r--r--src/server/wsgi_logger.c13
-rw-r--r--tests/environ.wsgi5
6 files changed, 39 insertions, 3 deletions
diff --git a/docs/release-notes.rst b/docs/release-notes.rst
index 1a8f678..bd85435 100644
--- a/docs/release-notes.rst
+++ b/docs/release-notes.rst
@@ -5,6 +5,7 @@ Release Notes
.. toctree::
:maxdepth: 2
+ release-notes/version-4.5.14
release-notes/version-4.5.13
release-notes/version-4.5.12
release-notes/version-4.5.11
diff --git a/docs/release-notes/version-4.5.14.rst b/docs/release-notes/version-4.5.14.rst
new file mode 100644
index 0000000..742147d
--- /dev/null
+++ b/docs/release-notes/version-4.5.14.rst
@@ -0,0 +1,17 @@
+==============
+Version 4.5.14
+==============
+
+Version 4.5.14 of mod_wsgi can be obtained from:
+
+ https://codeload.github.com/GrahamDumpleton/mod_wsgi/tar.gz/4.5.14
+
+New Features
+------------
+
+* Added a ``name`` attribute to the log object used in place of
+ ``sys.stdout`` and ``sys.stderr``, and which is also used for
+ ``wsgi.errors`` in the per request ``environ`` dictionary. This is
+ because although the ``name`` attribute is not required to exist, one can
+ find code out there that assumes it always does exist for file like
+ objects. Adding the attribute ensures that such code doesn't fail.
diff --git a/src/server/mod_wsgi.c b/src/server/mod_wsgi.c
index 680e4bf..3451619 100644
--- a/src/server/mod_wsgi.c
+++ b/src/server/mod_wsgi.c
@@ -2013,7 +2013,7 @@ static AdapterObject *newAdapterObject(request_rec *r)
self->input = newInputObject(r, self->config->ignore_activity);
- self->log_buffer = newLogBufferObject(r, APLOG_ERR, "wsgi.errors", 0);
+ self->log_buffer = newLogBufferObject(r, APLOG_ERR, "<wsgi.errors>", 0);
self->log = newLogWrapperObject(self->log_buffer);
return self;
diff --git a/src/server/wsgi_interp.c b/src/server/wsgi_interp.c
index e428201..32f2d2d 100644
--- a/src/server/wsgi_interp.c
+++ b/src/server/wsgi_interp.c
@@ -516,7 +516,7 @@ InterpreterObject *newInterpreterObject(const char *name)
* the 'pdb' module.
*/
- object = newLogObject(NULL, APLOG_ERR, "stderr", 1);
+ object = newLogObject(NULL, APLOG_ERR, "<stderr>", 1);
PySys_SetObject("stderr", object);
Py_DECREF(object);
@@ -529,7 +529,7 @@ InterpreterObject *newInterpreterObject(const char *name)
Py_DECREF(object);
}
else {
- object = newLogObject(NULL, APLOG_ERR, "stdout", 1);
+ object = newLogObject(NULL, APLOG_ERR, "<stdout>", 1);
PySys_SetObject("stdout", object);
Py_DECREF(object);
}
diff --git a/src/server/wsgi_logger.c b/src/server/wsgi_logger.c
index 68a0082..6ee0f78 100644
--- a/src/server/wsgi_logger.c
+++ b/src/server/wsgi_logger.c
@@ -51,6 +51,9 @@ PyObject *newLogBufferObject(request_rec *r, int level, const char *name,
if (self == NULL)
return NULL;
+ if (!name)
+ name = "<log>";
+
self->name = name;
self->proxy = proxy;
self->r = r;
@@ -437,6 +440,15 @@ static PyObject *Log_fileno(LogObject *self, PyObject *args)
}
#endif
+static PyObject *Log_name(LogObject *self, void *closure)
+{
+#if PY_MAJOR_VERSION >= 3
+ return PyUnicode_FromString(self->name);
+#else
+ return PyString_FromString(self->name);
+#endif
+}
+
static PyObject *Log_closed(LogObject *self, void *closure)
{
Py_INCREF(Py_False);
@@ -512,6 +524,7 @@ static PyMethodDef Log_methods[] = {
};
static PyGetSetDef Log_getset[] = {
+ { "name", (getter)Log_name, NULL, 0 },
{ "closed", (getter)Log_closed, NULL, 0 },
#if PY_MAJOR_VERSION < 3
{ "softspace", (getter)Log_get_softspace, (setter)Log_set_softspace, 0 },
diff --git a/tests/environ.wsgi b/tests/environ.wsgi
index 5be59cb..c7b8dfd 100644
--- a/tests/environ.wsgi
+++ b/tests/environ.wsgi
@@ -37,6 +37,11 @@ def application(environ, start_response):
print('CWD: %s' % os.getcwd(), file=output)
print(file=output)
+ print('STDOUT:', sys.stdout.name, file=output)
+ print('STDERR:', sys.stderr.name, file=output)
+ print('ERRORS:', environ['wsgi.errors'].name, file=output)
+ print(file=output)
+
print('python.version: %r' % (sys.version,), file=output)
print('python.prefix: %r' % (sys.prefix,), file=output)
print('python.path: %r' % (sys.path,), file=output)