async def open_connection(host=None, port=None, *,
- loop=None, limit=_DEFAULT_LIMIT, **kwds):
+ limit=_DEFAULT_LIMIT, **kwds):
"""A wrapper for create_connection() returning a (reader, writer) pair.
The reader returned is a StreamReader instance; the writer is a
StreamReaderProtocol classes, just copy the code -- there's
really nothing special here except some convenience.)
"""
- if loop is None:
- loop = events.get_event_loop()
- else:
- warnings.warn("The loop argument is deprecated since Python 3.8, "
- "and scheduled for removal in Python 3.10.",
- DeprecationWarning, stacklevel=2)
+ loop = events.get_running_loop()
reader = StreamReader(limit=limit, loop=loop)
protocol = StreamReaderProtocol(reader, loop=loop)
transport, _ = await loop.create_connection(
async def start_server(client_connected_cb, host=None, port=None, *,
- loop=None, limit=_DEFAULT_LIMIT, **kwds):
+ limit=_DEFAULT_LIMIT, **kwds):
"""Start a socket server, call back for each client connected.
The first parameter, `client_connected_cb`, takes two parameters:
The return value is the same as loop.create_server(), i.e. a
Server object which can be used to stop the service.
"""
- if loop is None:
- loop = events.get_event_loop()
- else:
- warnings.warn("The loop argument is deprecated since Python 3.8, "
- "and scheduled for removal in Python 3.10.",
- DeprecationWarning, stacklevel=2)
+ loop = events.get_running_loop()
def factory():
reader = StreamReader(limit=limit, loop=loop)
# UNIX Domain Sockets are supported on this platform
async def open_unix_connection(path=None, *,
- loop=None, limit=_DEFAULT_LIMIT, **kwds):
+ limit=_DEFAULT_LIMIT, **kwds):
"""Similar to `open_connection` but works with UNIX Domain Sockets."""
- if loop is None:
- loop = events.get_event_loop()
- else:
- warnings.warn("The loop argument is deprecated since Python 3.8, "
- "and scheduled for removal in Python 3.10.",
- DeprecationWarning, stacklevel=2)
+ loop = events.get_running_loop()
+
reader = StreamReader(limit=limit, loop=loop)
protocol = StreamReaderProtocol(reader, loop=loop)
transport, _ = await loop.create_unix_connection(
return reader, writer
async def start_unix_server(client_connected_cb, path=None, *,
- loop=None, limit=_DEFAULT_LIMIT, **kwds):
+ limit=_DEFAULT_LIMIT, **kwds):
"""Similar to `start_server` but works with UNIX Domain Sockets."""
- if loop is None:
- loop = events.get_event_loop()
- else:
- warnings.warn("The loop argument is deprecated since Python 3.8, "
- "and scheduled for removal in Python 3.10.",
- DeprecationWarning, stacklevel=2)
+ loop = events.get_running_loop()
def factory():
reader = StreamReader(limit=limit, loop=loop)
def _basetest_open_connection(self, open_connection_fut):
messages = []
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
- with self.assertWarns(DeprecationWarning):
- reader, writer = self.loop.run_until_complete(open_connection_fut)
+ reader, writer = self.loop.run_until_complete(open_connection_fut)
writer.write(b'GET / HTTP/1.0\r\n\r\n')
f = reader.readline()
data = self.loop.run_until_complete(f)
def test_open_connection(self):
with test_utils.run_test_server() as httpd:
- conn_fut = asyncio.open_connection(*httpd.address,
- loop=self.loop)
+ conn_fut = asyncio.open_connection(*httpd.address)
self._basetest_open_connection(conn_fut)
@socket_helper.skip_unless_bind_unix_socket
def test_open_unix_connection(self):
with test_utils.run_test_unix_server() as httpd:
- conn_fut = asyncio.open_unix_connection(httpd.address,
- loop=self.loop)
+ conn_fut = asyncio.open_unix_connection(httpd.address)
self._basetest_open_connection(conn_fut)
def _basetest_open_connection_no_loop_ssl(self, open_connection_fut):
messages = []
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
try:
- with self.assertWarns(DeprecationWarning):
- reader, writer = self.loop.run_until_complete(open_connection_fut)
+ reader, writer = self.loop.run_until_complete(open_connection_fut)
finally:
asyncio.set_event_loop(None)
writer.write(b'GET / HTTP/1.0\r\n\r\n')
with test_utils.run_test_server(use_ssl=True) as httpd:
conn_fut = asyncio.open_connection(
*httpd.address,
- ssl=test_utils.dummy_ssl_context(),
- loop=self.loop)
+ ssl=test_utils.dummy_ssl_context())
self._basetest_open_connection_no_loop_ssl(conn_fut)
httpd.address,
ssl=test_utils.dummy_ssl_context(),
server_hostname='',
- loop=self.loop)
+ )
self._basetest_open_connection_no_loop_ssl(conn_fut)
def _basetest_open_connection_error(self, open_connection_fut):
messages = []
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
- with self.assertWarns(DeprecationWarning):
- reader, writer = self.loop.run_until_complete(open_connection_fut)
+ reader, writer = self.loop.run_until_complete(open_connection_fut)
writer._protocol.connection_lost(ZeroDivisionError())
f = reader.read()
with self.assertRaises(ZeroDivisionError):
def test_open_connection_error(self):
with test_utils.run_test_server() as httpd:
- conn_fut = asyncio.open_connection(*httpd.address,
- loop=self.loop)
+ conn_fut = asyncio.open_connection(*httpd.address)
self._basetest_open_connection_error(conn_fut)
@socket_helper.skip_unless_bind_unix_socket
def test_open_unix_connection_error(self):
with test_utils.run_test_unix_server() as httpd:
- conn_fut = asyncio.open_unix_connection(httpd.address,
- loop=self.loop)
+ conn_fut = asyncio.open_unix_connection(httpd.address)
self._basetest_open_connection_error(conn_fut)
def test_feed_empty_data(self):
sock = socket.create_server(('127.0.0.1', 0))
self.server = self.loop.run_until_complete(
asyncio.start_server(self.handle_client,
- sock=sock,
- loop=self.loop))
+ sock=sock))
return sock.getsockname()
def handle_client_callback(self, client_reader, client_writer):
sock.close()
self.server = self.loop.run_until_complete(
asyncio.start_server(self.handle_client_callback,
- host=addr[0], port=addr[1],
- loop=self.loop))
+ host=addr[0], port=addr[1]))
return addr
def stop(self):
self.server = None
async def client(addr):
- with self.assertWarns(DeprecationWarning):
- reader, writer = await asyncio.open_connection(
- *addr, loop=self.loop)
+ reader, writer = await asyncio.open_connection(*addr)
# send a line
writer.write(b"hello world!\n")
# read it back
# test the server variant with a coroutine as client handler
server = MyServer(self.loop)
- with self.assertWarns(DeprecationWarning):
- addr = server.start()
+ addr = server.start()
msg = self.loop.run_until_complete(self.loop.create_task(client(addr)))
server.stop()
self.assertEqual(msg, b"hello world!\n")
# test the server variant with a callback as client handler
server = MyServer(self.loop)
- with self.assertWarns(DeprecationWarning):
- addr = server.start_callback()
+ addr = server.start_callback()
msg = self.loop.run_until_complete(self.loop.create_task(client(addr)))
server.stop()
self.assertEqual(msg, b"hello world!\n")
def start(self):
self.server = self.loop.run_until_complete(
asyncio.start_unix_server(self.handle_client,
- path=self.path,
- loop=self.loop))
+ path=self.path))
def handle_client_callback(self, client_reader, client_writer):
self.loop.create_task(self.handle_client(client_reader,
def start_callback(self):
start = asyncio.start_unix_server(self.handle_client_callback,
- path=self.path,
- loop=self.loop)
+ path=self.path)
self.server = self.loop.run_until_complete(start)
def stop(self):
self.server = None
async def client(path):
- with self.assertWarns(DeprecationWarning):
- reader, writer = await asyncio.open_unix_connection(
- path, loop=self.loop)
+ reader, writer = await asyncio.open_unix_connection(path)
# send a line
writer.write(b"hello world!\n")
# read it back
# test the server variant with a coroutine as client handler
with test_utils.unix_socket_path() as path:
server = MyServer(self.loop, path)
- with self.assertWarns(DeprecationWarning):
- server.start()
+ server.start()
msg = self.loop.run_until_complete(
self.loop.create_task(client(path)))
server.stop()
# test the server variant with a callback as client handler
with test_utils.unix_socket_path() as path:
server = MyServer(self.loop, path)
- with self.assertWarns(DeprecationWarning):
- server.start_callback()
+ server.start_callback()
msg = self.loop.run_until_complete(
self.loop.create_task(client(path)))
server.stop()
clt.close()
async def client(host, port):
- with self.assertWarns(DeprecationWarning):
- reader, writer = await asyncio.open_connection(
- host, port, loop=self.loop)
+ reader, writer = await asyncio.open_connection(host, port)
while True:
writer.write(b"foo\n")
def test_wait_closed_on_close(self):
with test_utils.run_test_server() as httpd:
- with self.assertWarns(DeprecationWarning):
- rd, wr = self.loop.run_until_complete(
- asyncio.open_connection(*httpd.address, loop=self.loop))
+ rd, wr = self.loop.run_until_complete(
+ asyncio.open_connection(*httpd.address))
wr.write(b'GET / HTTP/1.0\r\n\r\n')
f = rd.readline()
def test_wait_closed_on_close_with_unread_data(self):
with test_utils.run_test_server() as httpd:
- with self.assertWarns(DeprecationWarning):
- rd, wr = self.loop.run_until_complete(
- asyncio.open_connection(*httpd.address, loop=self.loop))
+ rd, wr = self.loop.run_until_complete(
+ asyncio.open_connection(*httpd.address))
wr.write(b'GET / HTTP/1.0\r\n\r\n')
f = rd.readline()
self.loop.set_exception_handler(lambda loop, ctx: messages.append(ctx))
with test_utils.run_test_server() as httpd:
- with self.assertWarns(DeprecationWarning):
- rd, wr = self.loop.run_until_complete(
- asyncio.open_connection(*httpd.address,
- loop=self.loop))
+ rd, wr = self.loop.run_until_complete(
+ asyncio.open_connection(*httpd.address))
wr.close()
f = wr.wait_closed()