changeset: 91605:d164fda9063a parent: 91603:bf677505a951 parent: 91604:f67df13dd512 user: Victor Stinner date: Tue Jul 08 00:34:48 2014 +0200 files: Lib/asynchat.py Lib/test/test_asynchat.py Misc/NEWS description: (Merge 3.4) Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError if the number of received bytes is negative. diff -r bf677505a951 -r d164fda9063a Lib/asynchat.py --- a/Lib/asynchat.py Tue Jul 08 00:19:33 2014 +0200 +++ b/Lib/asynchat.py Tue Jul 08 00:34:48 2014 +0200 @@ -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 -r bf677505a951 -r d164fda9063a Lib/test/test_asynchat.py --- a/Lib/test/test_asynchat.py Tue Jul 08 00:19:33 2014 +0200 +++ b/Lib/test/test_asynchat.py Tue Jul 08 00:34:48 2014 +0200 @@ -311,5 +311,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 -r bf677505a951 -r d164fda9063a Misc/NEWS --- a/Misc/NEWS Tue Jul 08 00:19:33 2014 +0200 +++ b/Misc/NEWS Tue Jul 08 00:34:48 2014 +0200 @@ -108,6 +108,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