diff -r 6b0ca4cb7e4e Lib/asynchat.py --- a/Lib/asynchat.py Sat Feb 23 19:37:01 2013 +0100 +++ b/Lib/asynchat.py Sat Feb 23 13:35:59 2013 -0600 @@ -100,6 +100,8 @@ "Set the input delimiter. Can be a fixed string of any length, an integer, or None" if isinstance(term, str) and self.use_encoding: term = bytes(term, self.encoding) + elif isinstance(term, int) and term < 0: + raise ValueError('Negative terminator value is not allowed') self.terminator = term def get_terminator (self): @@ -129,7 +131,7 @@ while self.ac_in_buffer: lb = len(self.ac_in_buffer) - terminator = self.get_terminator() + terminator = self.terminator if not terminator: # no terminator, collect it all self.collect_incoming_data (self.ac_in_buffer) @@ -140,7 +142,7 @@ if lb < n: self.collect_incoming_data (self.ac_in_buffer) self.ac_in_buffer = b'' - self.terminator = self.terminator - lb + self.terminator -= lb else: self.collect_incoming_data (self.ac_in_buffer[:n]) self.ac_in_buffer = self.ac_in_buffer[n:] diff -r 6b0ca4cb7e4e Lib/test/test_asynchat.py --- a/Lib/test/test_asynchat.py Sat Feb 23 19:37:01 2013 +0100 +++ b/Lib/test/test_asynchat.py Sat Feb 23 13:35:59 2013 -0600 @@ -166,6 +166,9 @@ def test_numeric_terminator2(self): self.numeric_terminator_check(6) + def test_disallow_negative_terminator(self): + self.assertRaises(ValueError, self.numeric_terminator_check, -42) + def test_none_terminator(self): # Try reading a fixed number of bytes s, event = start_echo_server()

AltStyle によって変換されたページ (->オリジナル) /