BaseStreamFileLike: handle reads that return None

Fixes #555.
This commit is contained in:
Jimmy Zelinskie 2015-09-30 16:24:04 -04:00
parent abe43a0e07
commit ffeb99d4ee
2 changed files with 12 additions and 1 deletions

View file

@ -90,6 +90,15 @@ class TestLimitingStream(unittest.TestCase):
class TestStreamSlice(unittest.TestCase):
def test_none_read(self):
class NoneReader(object):
def read(self, size=None):
return None
stream = StreamSlice(NoneReader(), 0)
self.assertEquals(None, stream.read(-1))
self.assertEquals(0, stream.tell())
def test_noslice(self):
fileobj = StringIO('this is a cool test')
stream = StreamSlice(fileobj, 0)
@ -123,4 +132,4 @@ class TestStreamSlice(unittest.TestCase):
if __name__ == '__main__':
unittest.main()
unittest.main()

View file

@ -15,6 +15,8 @@ class BaseStreamFilelike(object):
def read(self, size=READ_UNTIL_END):
buf = self._fileobj.read(size)
if buf is None:
return None
self._cursor_position += len(buf)
return buf