diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-07-07 22:26:36 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-07-07 22:26:36 (GMT) |
commit | 630a4f63c539345a6432d6177931b5fcc2f18aa7 (patch) | |
tree | bed6342759b5925823a2ae7ece387925ad263ce2 | |
parent | fd5d1b51d64280d938b7cdc9d78c632b21b45dff (diff) | |
download | cpython-630a4f63c539345a6432d6177931b5fcc2f18aa7.zip cpython-630a4f63c539345a6432d6177931b5fcc2f18aa7.tar.gz cpython-630a4f63c539345a6432d6177931b5fcc2f18aa7.tar.bz2 |
Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError if
the number of received bytes is negative.
-rw-r--r-- | Lib/asynchat.py | 2 | ||||
-rw-r--r-- | Lib/test/test_asynchat.py | 8 | ||||
-rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 13 insertions, 0 deletions
diff --git a/Lib/asynchat.py b/Lib/asynchat.py index 682dbd7..6e16891 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 3471739..84867ec 100644 --- a/Lib/test/test_asynchat.py +++ b/Lib/test/test_asynchat.py @@ -304,5 +304,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() @@ -27,6 +27,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 |