From: Yury Selivanov Date: Fri, 11 Dec 2015 16:32:59 +0000 (-0500) Subject: asyncio: Sync with github X-Git-Tag: v3.4.5rc1~63 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=dddc781998da741511178c7cb4e303e3db5aac45;p=python asyncio: Sync with github --- diff --git a/Lib/asyncio/streams.py b/Lib/asyncio/streams.py index 6b5e96aea2..9097e38271 100644 --- a/Lib/asyncio/streams.py +++ b/Lib/asyncio/streams.py @@ -494,6 +494,9 @@ class StreamReader: @coroutine def readexactly(self, n): + if n < 0: + raise ValueError('readexactly size can not be less than zero') + if self._exception is not None: raise self._exception diff --git a/Lib/test/test_asyncio/test_streams.py b/Lib/test/test_asyncio/test_streams.py index 6f657ad5f8..b716a504de 100644 --- a/Lib/test/test_asyncio/test_streams.py +++ b/Lib/test/test_asyncio/test_streams.py @@ -351,8 +351,8 @@ class StreamReaderTests(test_utils.TestCase): self.assertEqual(b'', data) self.assertEqual(self.DATA, stream._buffer) - data = self.loop.run_until_complete(stream.readexactly(-1)) - self.assertEqual(b'', data) + with self.assertRaisesRegexp(ValueError, 'less than zero'): + self.loop.run_until_complete(stream.readexactly(-1)) self.assertEqual(self.DATA, stream._buffer) def test_readexactly(self):