summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorValentin Bartenev <vbart@nginx.com>2018-09-20 16:04:49 +0300
committerValentin Bartenev <vbart@nginx.com>2018-09-20 16:04:49 +0300
commit510c2e15c5b55a48f15f0ba680c5e82a2db5456f (patch)
treee1e5abb930a7e83426bc0b8dff951a0f9769d6c7
parent9f29ac9f3e85b34317ab68ae297dabc6c6ffa6ae (diff)
downloadunit-510c2e15c5b55a48f15f0ba680c5e82a2db5456f.tar.gz
unit-510c2e15c5b55a48f15f0ba680c5e82a2db5456f.tar.bz2
Python: adjusted input.read(size) argument value interpretation.
Previously, passing 0 resulted in reading the whole body and all negative values raised an exception. Now the behaviour is in consistentance with io.RawIOBase.read() interface, and passing 0 returns empty (byte) string, while -1 results in reading the whole body.
Diffstat (limited to '')
-rw-r--r--src/nxt_python_wsgi.c8
-rw-r--r--test/test_python_application.py1
2 files changed, 5 insertions, 4 deletions
diff --git a/src/nxt_python_wsgi.c b/src/nxt_python_wsgi.c
index d925b33f..3a5f1913 100644
--- a/src/nxt_python_wsgi.c
+++ b/src/nxt_python_wsgi.c
@@ -1136,11 +1136,13 @@ nxt_py_input_read(nxt_py_input_t *self, PyObject *args)
return NULL;
}
- return PyErr_Format(PyExc_ValueError,
- "the read body size cannot be zero or less");
+ if (size != -1) {
+ return PyErr_Format(PyExc_ValueError,
+ "the read body size cannot be zero or less");
+ }
}
- if (size == 0 || size > (Py_ssize_t) ctx->req->content_length) {
+ if (size == -1 || size > (Py_ssize_t) ctx->req->content_length) {
size = ctx->req->content_length;
}
}
diff --git a/test/test_python_application.py b/test/test_python_application.py
index 146223ec..f1e2cbf7 100644
--- a/test/test_python_application.py
+++ b/test/test_python_application.py
@@ -243,7 +243,6 @@ Connection: close
self.assertEqual(self.post(body=body)['body'], body, 'input iter')
- @unittest.expectedFailure
def test_python_application_input_read_length(self):
self.load('input_read_length')