o
    .j                     @  s   d dl mZ d dlZd dlZd dlZd dlmZ d dlmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ d	d
lmZ d	dlmZmZ dgZeedsMde_ededddd dd#d"dZdS )$    )annotationsN)asynccontextmanager)AsyncGeneratorCallablecast   )QuicConfiguration)QuicConnection)SessionTicketHandler   )#create_optimized_datagram_transport)QuicConnectionProtocolQuicStreamHandlerconnectIPPROTO_IPV6)   T)configurationcreate_protocolsession_ticket_handlerstream_handlerwait_connected
local_porthoststrportintr   QuicConfiguration | Noner   Callable | Noner   SessionTicketHandler | Noner   QuicStreamHandler | Noner   boolr   return&AsyncGenerator[QuicConnectionProtocol]c                 s  t  }d}	z	t|  d}
W n ty   | }
Y nw |j| |tjdI dH }|d d }t|dkr@d|d  |d ddf}|du rIt	d	d
}|j
du rQ|
|_
t||d ttjtj}d}z|tjtjd ||	|ddf d	}W |s}|  n|s|  w w t| fdd|dI dH \}}tt|}z#|| |r| I dH  |V  W |  | I dH  |  dS |  | I dH  |  w )aa  
    Connect to a QUIC server at the given `host` and `port`.

    :meth:`connect()` returns an awaitable. Awaiting it yields a
    :class:`~qh3.asyncio.QuicConnectionProtocol` which can be used to
    create streams.

    :func:`connect` also accepts the following optional arguments:

    * ``configuration`` is a :class:`~qh3.quic.configuration.QuicConfiguration`
      configuration object.
    * ``create_protocol`` allows customizing the :class:`~asyncio.Protocol` that
      manages the connection. It should be a callable or class accepting the same
      arguments as :class:`~qh3.asyncio.QuicConnectionProtocol` and returning
      an instance of :class:`~qh3.asyncio.QuicConnectionProtocol` or a subclass.
    * ``session_ticket_handler`` is a callback which is invoked by the TLS
      engine when a new session ticket is received.
    * ``stream_handler`` is a callback which is invoked whenever a stream is
      created. It must accept two arguments: a :class:`asyncio.StreamReader`
      and a :class:`asyncio.StreamWriter`.
    * ``local_port`` is the UDP port number that this client wants to bind.
    z::N)typer      r   z::ffff:r   T)	is_client)r   r   Fc                     s    dS )N)r    r&   
connectionr   r   r&   G/home/thesage/.local/lib/python3.10/site-packages/qh3/asyncio/client.py<lambda>_   s    zconnect.<locals>.<lambda>)sock)asyncioget_running_loop	ipaddress
ip_address
ValueErrorgetaddrinfosocket
SOCK_DGRAMlenr   server_namer	   AF_INET6
setsockoptr   IPV6_V6ONLYbindcloser   r   r   r   r   wait_closed)r   r   r   r   r   r   r   r   loop
local_hostr5   infosaddrr+   	completed	transportprotocolr&   r'   r)   r      sb   "






)r   r   r   r   r   r   r   r   r   r   r   r   r   r    r   r   r!   r"   )
__future__r   r,   r.   r2   
contextlibr   typingr   r   r   quic.configurationr   quic.connectionr	   tlsr
   
_transportr   rB   r   r   __all__hasattrr   r   r&   r&   r&   r)   <module>   s,    
