mirror of
https://github.com/python/cpython.git
synced 2025-11-12 15:09:14 +00:00
(Merge 3.4) Issue #12523: asynchat.async_chat.push() now raises a TypeError if
it doesn't get a bytes string
This commit is contained in:
commit
e8209dab6b
3 changed files with 22 additions and 0 deletions
|
|
@ -181,6 +181,9 @@ class async_chat (asyncore.dispatcher):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def push (self, data):
|
def push (self, data):
|
||||||
|
if not isinstance(data, (bytes, bytearray, memoryview)):
|
||||||
|
raise TypeError('data argument must be byte-ish (%r)',
|
||||||
|
type(data))
|
||||||
sabs = self.ac_out_buffer_size
|
sabs = self.ac_out_buffer_size
|
||||||
if len(data) > sabs:
|
if len(data) > sabs:
|
||||||
for i in range(0, len(data), sabs):
|
for i in range(0, len(data), sabs):
|
||||||
|
|
|
||||||
|
|
@ -250,6 +250,22 @@ class TestAsynchat(unittest.TestCase):
|
||||||
# (which could still result in the client not having received anything)
|
# (which could still result in the client not having received anything)
|
||||||
self.assertGreater(len(s.buffer), 0)
|
self.assertGreater(len(s.buffer), 0)
|
||||||
|
|
||||||
|
def test_push(self):
|
||||||
|
# Issue #12523: push() should raise a TypeError if it doesn't get
|
||||||
|
# a bytes string
|
||||||
|
s, event = start_echo_server()
|
||||||
|
c = echo_client(b'\n', s.port)
|
||||||
|
data = b'bytes\n'
|
||||||
|
c.push(data)
|
||||||
|
c.push(bytearray(data))
|
||||||
|
c.push(memoryview(data))
|
||||||
|
self.assertRaises(TypeError, c.push, 10)
|
||||||
|
self.assertRaises(TypeError, c.push, 'unicode')
|
||||||
|
c.push(SERVER_QUIT)
|
||||||
|
asyncore.loop(use_poll=self.usepoll, count=300, timeout=.01)
|
||||||
|
s.join(timeout=TIMEOUT)
|
||||||
|
self.assertEqual(c.contents, [b'bytes', b'bytes', b'bytes'])
|
||||||
|
|
||||||
|
|
||||||
class TestAsynchat_WithPoll(TestAsynchat):
|
class TestAsynchat_WithPoll(TestAsynchat):
|
||||||
usepoll = True
|
usepoll = True
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,9 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #12523: asynchat.async_chat.push() now raises a TypeError if it doesn't
|
||||||
|
get a bytes string
|
||||||
|
|
||||||
- Issue #21707: Add missing kwonlyargcount argument to
|
- Issue #21707: Add missing kwonlyargcount argument to
|
||||||
ModuleFinder.replace_paths_in_code().
|
ModuleFinder.replace_paths_in_code().
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue