mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
(Merge 3.4) Issue #16133: The asynchat.async_chat.handle_read() method now
ignores BlockingIOError exceptions. Initial patch written by Xavier de Gaye. Document also in asyncore documentation that recv() may raise BlockingIOError.
This commit is contained in:
commit
316b16de13
4 changed files with 26 additions and 0 deletions
|
@ -115,6 +115,8 @@ class async_chat(asyncore.dispatcher):
|
|||
|
||||
try:
|
||||
data = self.recv(self.ac_in_buffer_size)
|
||||
except BlockingIOError:
|
||||
return
|
||||
except OSError as why:
|
||||
self.handle_error()
|
||||
return
|
||||
|
|
|
@ -7,11 +7,13 @@ thread = support.import_module('_thread')
|
|||
|
||||
import asynchat
|
||||
import asyncore
|
||||
import errno
|
||||
import socket
|
||||
import sys
|
||||
import time
|
||||
import unittest
|
||||
import warnings
|
||||
import unittest.mock
|
||||
try:
|
||||
import threading
|
||||
except ImportError:
|
||||
|
@ -274,6 +276,21 @@ class TestAsynchat_WithPoll(TestAsynchat):
|
|||
usepoll = True
|
||||
|
||||
|
||||
class TestAsynchatMocked(unittest.TestCase):
|
||||
def test_blockingioerror(self):
|
||||
# Issue #16133: handle_read() must ignore BlockingIOError
|
||||
sock = unittest.mock.Mock()
|
||||
sock.recv.side_effect = BlockingIOError(errno.EAGAIN)
|
||||
|
||||
dispatcher = asynchat.async_chat()
|
||||
dispatcher.set_socket(sock)
|
||||
self.addCleanup(dispatcher.del_channel)
|
||||
|
||||
with unittest.mock.patch.object(dispatcher, 'handle_error') as error:
|
||||
dispatcher.handle_read()
|
||||
self.assertFalse(error.called)
|
||||
|
||||
|
||||
class TestHelperFunctions(unittest.TestCase):
|
||||
def test_find_prefix_at_end(self):
|
||||
self.assertEqual(asynchat.find_prefix_at_end("qwerty\r", "\r\n"), 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue