summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncore.py
diff options
context:
space:
mode:
authorGiampaolo RodolĂ  <g.rodola@gmail.com>2010-10-04 21:08:36 (GMT)
committerGiampaolo RodolĂ  <g.rodola@gmail.com>2010-10-04 21:08:36 (GMT)
commit977c707b425ee753d54f3e9010f07ec77ef61274 (patch)
tree580e12fd41103a684b4c24b53d43569eb69bc6a8 /Lib/test/test_asyncore.py
parent4c94c5363091350ed56bfbdbc6cc00e1048b456c (diff)
downloadcpython-977c707b425ee753d54f3e9010f07ec77ef61274.zip
cpython-977c707b425ee753d54f3e9010f07ec77ef61274.tar.gz
cpython-977c707b425ee753d54f3e9010f07ec77ef61274.tar.bz2
Fix issue 6706: adds new handle_accepted() method to asyncore.dispatcher
Diffstat (limited to 'Lib/test/test_asyncore.py')
-rw-r--r--Lib/test/test_asyncore.py33
1 files changed, 28 insertions, 5 deletions
diff --git a/Lib/test/test_asyncore.py b/Lib/test/test_asyncore.py
index ce0a84f..205efb9 100644
--- a/Lib/test/test_asyncore.py
+++ b/Lib/test/test_asyncore.py
@@ -296,7 +296,6 @@ class DispatcherTests(unittest.TestCase):
d.handle_read()
d.handle_write()
d.handle_connect()
- d.handle_accept()
finally:
sys.stdout = stdout
@@ -304,8 +303,7 @@ class DispatcherTests(unittest.TestCase):
expected = ['warning: unhandled incoming priority event',
'warning: unhandled read event',
'warning: unhandled write event',
- 'warning: unhandled connect event',
- 'warning: unhandled accept event']
+ 'warning: unhandled connect event']
self.assertEqual(lines, expected)
def test_issue_8594(self):
@@ -451,6 +449,9 @@ class BaseTestHandler(asyncore.dispatcher):
def handle_accept(self):
raise Exception("handle_accept not supposed to be called")
+ def handle_accepted(self):
+ raise Exception("handle_accepted not supposed to be called")
+
def handle_connect(self):
raise Exception("handle_connect not supposed to be called")
@@ -481,8 +482,7 @@ class TCPServer(asyncore.dispatcher):
def address(self):
return self.socket.getsockname()[:2]
- def handle_accept(self):
- sock, addr = self.accept()
+ def handle_accepted(self, sock, addr):
self.handler(sock)
def handle_error(self):
@@ -546,6 +546,29 @@ class BaseTestAPI(unittest.TestCase):
client = BaseClient(server.address)
self.loop_waiting_for_flag(server)
+ def test_handle_accepted(self):
+ # make sure handle_accepted() is called when a client connects
+
+ class TestListener(BaseTestHandler):
+
+ def __init__(self):
+ BaseTestHandler.__init__(self)
+ self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
+ self.bind((HOST, 0))
+ self.listen(5)
+ self.address = self.socket.getsockname()[:2]
+
+ def handle_accept(self):
+ asyncore.dispatcher.handle_accept(self)
+
+ def handle_accepted(self, sock, addr):
+ self.flag = True
+
+ server = TestListener()
+ client = BaseClient(server.address)
+ self.loop_waiting_for_flag(server)
+
+
def test_handle_read(self):
# make sure handle_read is called on data received