summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2014-07-07 22:34:48 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2014-07-07 22:34:48 (GMT)
commitdb5f8fcde69d7f16261cfd763cd74a7e5e2d1383 (patch)
tree4b542ca21cee72240d4e68c23b10b7b97fb23e54
parent7b9328f51bee311ff943af660f3b5f1b35d4e196 (diff)
parent630a4f63c539345a6432d6177931b5fcc2f18aa7 (diff)
downloadcpython-db5f8fcde69d7f16261cfd763cd74a7e5e2d1383.zip
cpython-db5f8fcde69d7f16261cfd763cd74a7e5e2d1383.tar.gz
cpython-db5f8fcde69d7f16261cfd763cd74a7e5e2d1383.tar.bz2
(Merge 3.4) Issue #11259: asynchat.async_chat().set_terminator() now raises a
ValueError if the number of received bytes is negative.
-rw-r--r--Lib/asynchat.py2
-rw-r--r--Lib/test/test_asynchat.py8
-rw-r--r--Misc/NEWS3
3 files changed, 13 insertions, 0 deletions
diff --git a/Lib/asynchat.py b/Lib/asynchat.py
index 91f0bb2..fc6cabe 100644
--- a/Lib/asynchat.py
+++ b/Lib/asynchat.py
@@ -99,6 +99,8 @@ class async_chat(asyncore.dispatcher):
"""
if isinstance(term, str) and self.use_encoding:
term = bytes(term, self.encoding)
+ elif isinstance(term, int) and term < 0:
+ raise ValueError('the number of received bytes must be positive')
self.terminator = term
def get_terminator(self):
diff --git a/Lib/test/test_asynchat.py b/Lib/test/test_asynchat.py
index f6b17f9..9e30573 100644
--- a/Lib/test/test_asynchat.py
+++ b/Lib/test/test_asynchat.py
@@ -311,5 +311,13 @@ class TestFifo(unittest.TestCase):
self.assertEqual(f.pop(), (0, None))
+class TestNotConnected(unittest.TestCase):
+ def test_disallow_negative_terminator(self):
+ # Issue #11259
+ client = asynchat.async_chat()
+ self.assertRaises(ValueError, client.set_terminator, -1)
+
+
+
if __name__ == "__main__":
unittest.main()
diff --git a/Misc/NEWS b/Misc/NEWS
index ce35e3e..4fec3c3 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -108,6 +108,9 @@ Core and Builtins
Library
-------
+- Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError
+ if the number of received bytes is negative.
+
- Issue #12523: asynchat.async_chat.push() now raises a TypeError if it doesn't
get a bytes string