mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-36802: Drop awrite()/aclose(), support await write() and await close() instead (#13099)
This commit is contained in:
parent
3b2f9ab31d
commit
a076e4f5e4
4 changed files with 118 additions and 51 deletions
|
@ -1035,24 +1035,42 @@ os.close(fd)
|
|||
messages[0]['message'])
|
||||
|
||||
def test_async_writer_api(self):
|
||||
async def inner(httpd):
|
||||
rd, wr = await asyncio.open_connection(*httpd.address)
|
||||
|
||||
await wr.write(b'GET / HTTP/1.0\r\n\r\n')
|
||||
data = await rd.readline()
|
||||
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
|
||||
data = await rd.read()
|
||||
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
|
||||
await wr.close()
|
||||
|
||||
messages = []
|
||||
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
|
||||
|
||||
with test_utils.run_test_server() as httpd:
|
||||
rd, wr = self.loop.run_until_complete(
|
||||
asyncio.open_connection(*httpd.address,
|
||||
loop=self.loop))
|
||||
self.loop.run_until_complete(inner(httpd))
|
||||
|
||||
f = wr.awrite(b'GET / HTTP/1.0\r\n\r\n')
|
||||
self.loop.run_until_complete(f)
|
||||
f = rd.readline()
|
||||
data = self.loop.run_until_complete(f)
|
||||
self.assertEqual(messages, [])
|
||||
|
||||
def test_async_writer_api(self):
|
||||
async def inner(httpd):
|
||||
rd, wr = await asyncio.open_connection(*httpd.address)
|
||||
|
||||
await wr.write(b'GET / HTTP/1.0\r\n\r\n')
|
||||
data = await rd.readline()
|
||||
self.assertEqual(data, b'HTTP/1.0 200 OK\r\n')
|
||||
f = rd.read()
|
||||
data = self.loop.run_until_complete(f)
|
||||
data = await rd.read()
|
||||
self.assertTrue(data.endswith(b'\r\n\r\nTest message'))
|
||||
f = wr.aclose()
|
||||
self.loop.run_until_complete(f)
|
||||
wr.close()
|
||||
with self.assertRaises(ConnectionResetError):
|
||||
await wr.write(b'data')
|
||||
|
||||
messages = []
|
||||
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
|
||||
|
||||
with test_utils.run_test_server() as httpd:
|
||||
self.loop.run_until_complete(inner(httpd))
|
||||
|
||||
self.assertEqual(messages, [])
|
||||
|
||||
|
@ -1066,7 +1084,7 @@ os.close(fd)
|
|||
asyncio.open_connection(*httpd.address,
|
||||
loop=self.loop))
|
||||
|
||||
f = wr.aclose()
|
||||
f = wr.close()
|
||||
self.loop.run_until_complete(f)
|
||||
assert rd.at_eof()
|
||||
f = rd.read()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue