summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2019-09-04 03:11:59 -0700
committerChris Dent <cdent@anticdent.org>2019-09-04 11:11:59 +0100
commita55bf98f51c57880e9c2cead4c01b5c23ce09839 (patch)
treeb7241aad669b616c37d8ff6275dcb60be9eb8596
parentcdd2a9a58c59b8e599aa42b66b3c55ea47c7a4b7 (diff)
downloadpaste-git-a55bf98f51c57880e9c2cead4c01b5c23ce09839.tar.gz
Make LimitedLengthFile file return empty bytes rather than empty string when it's done. (#32)
-rwxr-xr-xpaste/httpserver.py2
-rw-r--r--tests/test_httpserver.py10
2 files changed, 10 insertions, 2 deletions
diff --git a/paste/httpserver.py b/paste/httpserver.py
index f91eb20..063c180 100755
--- a/paste/httpserver.py
+++ b/paste/httpserver.py
@@ -487,7 +487,7 @@ class LimitedLengthFile(object):
length = min(length, left)
# next two lines are hnecessary only if read(0) blocks
if not left:
- return ''
+ return b''
data = self.file.read(length)
self._consumed += len(data)
return data
diff --git a/tests/test_httpserver.py b/tests/test_httpserver.py
index 3d72c79..20a4320 100644
--- a/tests/test_httpserver.py
+++ b/tests/test_httpserver.py
@@ -1,6 +1,7 @@
import email
+import io
-from paste.httpserver import WSGIHandler
+from paste.httpserver import LimitedLengthFile, WSGIHandler
from six.moves import StringIO
@@ -43,3 +44,10 @@ def test_environ_with_multiple_values():
wsgi_handler.wsgi_setup()
assert wsgi_handler.wsgi_environ['HTTP_HOST'] == 'host1,host2'
+
+
+def test_limited_length_file():
+ backing = io.BytesIO(b'0123456789')
+ f = LimitedLengthFile(backing, 9)
+ assert f.read() == b'012345678'
+ assert f.read() == b''