Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 630a4f6

Browse files
committed
Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError if
the number of received bytes is negative.
1 parent fd5d1b5 commit 630a4f6

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

Lib/asynchat.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ def set_terminator(self, term):
9999
"""
100100
if isinstance(term, str) and self.use_encoding:
101101
term = bytes(term, self.encoding)
102+
elif isinstance(term, int) and term < 0:
103+
raise ValueError('the number of received bytes must be positive')
102104
self.terminator = term
103105

104106
def get_terminator(self):

Lib/test/test_asynchat.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,5 +304,13 @@ def test_given_list(self):
304304
self.assertEqual(f.pop(), (0, None))
305305

306306

307+
class TestNotConnected(unittest.TestCase):
308+
def test_disallow_negative_terminator(self):
309+
# Issue #11259
310+
client = asynchat.async_chat()
311+
self.assertRaises(ValueError, client.set_terminator, -1)
312+
313+
314+
307315
if __name__ == "__main__":
308316
unittest.main()

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ Core and Builtins
2727
Library
2828
-------
2929

30+
- Issue #11259: asynchat.async_chat().set_terminator() now raises a ValueError
31+
if the number of received bytes is negative.
32+
3033
- Issue #12523: asynchat.async_chat.push() now raises a TypeError if it doesn't
3134
get a bytes string
3235

0 commit comments

Comments
 (0)