summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2019-04-10 03:07:12 -0500
committerMichael Merickel <michael@merickel.org>2019-04-10 04:01:51 -0500
commitb6f2f696f9280c46f66a0ec62da02ca6f85e04ae (patch)
treee6cc8c40096cd4b793faee44fe5be1621060b183
parentbbc4db38d7d47a6f1d2e15d30a2722e085ecf972 (diff)
downloadwaitress-b6f2f696f9280c46f66a0ec62da02ca6f85e04ae.tar.gz
test for seekable method and use it
-rw-r--r--waitress/buffers.py7
-rw-r--r--waitress/tests/fixtureapps/filewrapper.py3
2 files changed, 7 insertions, 3 deletions
diff --git a/waitress/buffers.py b/waitress/buffers.py
index cacc094..aa11b70 100644
--- a/waitress/buffers.py
+++ b/waitress/buffers.py
@@ -129,6 +129,11 @@ class BytesIOBasedBuffer(FileBasedBuffer):
def newfile(self):
return BytesIO()
+def _is_seekable(fp):
+ if hasattr(fp, 'seekable'):
+ return fp.seekable()
+ return hasattr(fp, 'seek') and hasattr(fp, 'tell')
+
class ReadOnlyFileBasedBuffer(FileBasedBuffer):
# used as wsgi.file_wrapper
@@ -137,7 +142,7 @@ class ReadOnlyFileBasedBuffer(FileBasedBuffer):
self.block_size = block_size # for __iter__
def prepare(self, size=None):
- if hasattr(self.file, 'seek') and hasattr(self.file, 'tell'):
+ if _is_seekable(self.file):
start_pos = self.file.tell()
self.file.seek(0, 2)
end_pos = self.file.tell()
diff --git a/waitress/tests/fixtureapps/filewrapper.py b/waitress/tests/fixtureapps/filewrapper.py
index f38c606..d4e9a51 100644
--- a/waitress/tests/fixtureapps/filewrapper.py
+++ b/waitress/tests/fixtureapps/filewrapper.py
@@ -58,8 +58,7 @@ def app(environ, start_response): # pragma: no cover
('Content-Type', 'image/jpeg'),
]
else:
- with open(fn, 'rb') as fp:
- data = fp.read()
+ data = open(fn, 'rb').read()
cl = len(data)
f = KindaFilelike(data)
if path_info == '/notfilelike':