[Python-checkins] cpython (3.4): Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError if

victor.stinner python-checkins at python.org
Tue Jul 8 00:35:11 CEST 2014


http://hg.python.org/cpython/rev/f67df13dd512
changeset:   91604:f67df13dd512
branch:      3.4
parent:      91602:c8207b0148dc
user:        Victor Stinner <victor.stinner at gmail.com>
date:        Tue Jul 08 00:26:36 2014 +0200
summary:
  Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError if
the number of received bytes is negative.

files:
  Lib/asynchat.py           |  2 ++
  Lib/test/test_asynchat.py |  8 ++++++++
  Misc/NEWS                 |  3 +++
  3 files changed, 13 insertions(+), 0 deletions(-)


diff --git a/Lib/asynchat.py b/Lib/asynchat.py
--- a/Lib/asynchat.py
+++ b/Lib/asynchat.py
@@ -99,6 +99,8 @@
         """
         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
--- a/Lib/test/test_asynchat.py
+++ b/Lib/test/test_asynchat.py
@@ -304,5 +304,13 @@
         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
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -27,6 +27,9 @@
 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
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list