o
0id @ s& d Z ddlZddlZddlZddlZddlZeedre d7 Z ddlmZ ddlm Z ddlm
Z
dd lmZ dd
lmZ ddl
mZ ddlmZ d
ZdedddZdedddZeedrpd edddZd edddZG dd dejZG dd deejZG dd dZG dd dZdS )!)StreamReaderStreamWriterStreamReaderProtocolopen_connectionstart_server NZAF_UNIX)open_unix_connectionstart_unix_server )
coroutines)events)
exceptions)format_helpers) protocols)logger)sleepi )limitc s` t }t||d}t||d |j fdd| |fi |I dH \}}t| ||}||fS )a A wrapper for create_connection() returning a (reader, writer) pair.
The reader returned is a StreamReader instance; the writer is a
StreamWriter instance.
The arguments are all the usual arguments to create_connection()
except protocol_factory; most common are positional host and port,
with various optional keyword arguments following.
Additional optional keyword arguments are loop (to set the event loop
instance to use) and limit (to set the buffer limit passed to the
StreamReader).
(If you want to customize the StreamReader and/or
StreamReaderProtocol classes, just copy the code -- there's
really nothing special here except some convenience.)
r loopr c S N r protocolr 6/opt/alt/python310/lib64/python3.10/asyncio/streams.py1 z!open_connection..N)r get_running_loopr r Zcreate_connectionr ) hostportr kwdsr reader transport_writerr r r r s r c s6 t fdd}j|||fi |I dH S )a Start a socket server, call back for each client connected.
The first parameter, `client_connected_cb`, takes two parameters:
client_reader, client_writer. client_reader is a StreamReader
object, while client_writer is a StreamWriter object. This
parameter can either be a plain callback function or a coroutine;
if it is a coroutine, it will be automatically converted into a
Task.
The rest of the arguments are all the usual arguments to
loop.create_server() except protocol_factory; most common are
positional host and port, with various optional keyword arguments
following. The return value is the same as loop.create_server().
Additional optional keyword arguments are loop (to set the event loop
instance to use) and limit (to set the buffer limit passed to the
StreamReader).
The return value is the same as loop.create_server(), i.e. a
Server object which can be used to stop the service.
c t d} t| d}|S Nr r r r r! r client_connected_cbr r r r factoryO
zstart_server..factoryN)r r Z
create_server)r* r r r r r+ r r) r r 6 s r c s^ t }t||d}t||d |j fdd| fi |I dH \}}t| ||}||fS )z@Similar to `open_connection` but works with UNIX Domain Sockets.r r c r r r r r r r r c r z&open_unix_connection..N)r r r r Zcreate_unix_connectionr )pathr r r r! r" r# r$ r r r r [ s r c s4 t fdd}j||fi |I dH S )z=Similar to `start_server` but works with UNIX Domain Sockets.c r% r&