� u��g�%����dZddlZddlZddlZddlZddlZddlZddlmZm Z m Z m Z m Z ddl mZddlmZmZdddddd�de ed e e ed e ed e ed e ejd e edejfd�Z dd ejdeee eefded e e ede e ejd e edejfd�Z dde ededeefd�ZdS)zBase implementation.�N)�List�Optional�Sequence�Set�Union�)� _staggered)� AddrInfoType�SocketFactoryType)�local_addr_infos�happy_eyeballs_delay� interleave�loop�socket_factory� addr_infosr r rrr�returnc ��:�������K�|x�stj���t|��dk}|�|�d}|r|st||��}d}g�|�|r9|D]5} t ��|�d����d{V��}n#t t f$rY�2wxYwn�t��� tj �����fd�|D��|���d{V��\}} } �D]K} | |urEtj t ��5| � ��ddd��n #1swxYwY�Ld�nU#�D]K} | |urEtj t ��5| � ��ddd��n #1swxYwY�Ld�wxYw|��%d��D��} | d} t| ��dkr| �t| ���t�fd�| D����r| �d�d�d �| D������} t#| t ��r3| j�t�fd �| D����rt �| ���n=t#| t ��r(td �| D����rt | ���t | ���#d} d�wxYw|S) aM Connect to a TCP server. Create a socket connection to a specified destination. The destination is specified as a list of AddrInfoType tuples as returned from getaddrinfo(). The arguments are, in order: * ``family``: the address family, e.g. ``socket.AF_INET`` or ``socket.AF_INET6``. * ``type``: the socket type, e.g. ``socket.SOCK_STREAM`` or ``socket.SOCK_DGRAM``. * ``proto``: the protocol, e.g. ``socket.IPPROTO_TCP`` or ``socket.IPPROTO_UDP``. * ``canonname``: the canonical name of the address, e.g. ``"www.python.org"``. * ``sockaddr``: the socket address This method is a coroutine which will try to establish the connection in the background. When successful, the coroutine returns a socket. The expected use case is to use this method in conjunction with loop.create_connection() to establish a connection to a server:: socket = await start_connection(addr_infos) transport, protocol = await loop.create_connection( MyProtocol, sock=socket, ...) rNc 3�V�K�|]#}tjt��|�����V��$dS�N)� functools�partial� _connect_sock)�.0�addrinfo� current_loop� exceptionsr � open_socketsrs ������e/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/aiohappyeyeballs/impl.py� <genexpr>z#start_connection.<locals>.<genexpr>Xs[����� � �!��%�%�$�"� �(�$�&��� � � � � � �c��g|] }|D]}|��� S�r")r�sub�excs r� <listcomp>z$start_connection.<locals>.<listcomp>vs%��C�C�C�#�s�C�C��#�C�C�C�Cr rc3�>�K�|]}t|���kV��dSr��str)rr$�models �rrz#start_connection.<locals>.<genexpr>~s.�����C�C�S�s�3�x�x�5�(�C�C�C�C�C�Cr zMultiple exceptions: {}z, c3�4K�|]}t|��V��dSrr'�rr$s rrz#start_connection.<locals>.<genexpr>�s(����A�A�3�c�#�h�h�A�A�A�A�A�Ar c3�X�K�|]$}t|t��o |j�kV��%dSr)� isinstance�OSError�errno)rr$� first_errnos �rrz#start_connection.<locals>.<genexpr>�sM��������#�3��0�0�M�S�Y�+�5M������r c3�@K�|]}t|t��V��dSr)r-� RuntimeErrorr+s rrz#start_connection.<locals>.<genexpr>�sE����G�G�69�J�s�L�1�1�G�G�G�G�G�Gr )�asyncio�get_running_loop�len�_interleave_addrinfosrr2r.�setr �staggered_race� contextlib�suppress�closer(�all�format�joinr-r/)rr r rrr�single_addr_info�sockr�_�s�all_exceptions�first_exception�msgrrr0r)rs ` ` @@@@@r�start_connectionrFs[�����������N!� �L�2��/�1�1� ��:���!�+���'�J�,>�� ��C�*�C�*�:�z�B�B� �$(�D�;=�J��#�'7�#�"� � �H� �*� ���$��"� ������������ �'�*� � � ��� �����,/�5�5� � �)�8� � � � � � � � �%/� � � �%� � �������J�D�!�Q�0"� "� "���D�=�=�#�,�W�5�5�"�"���� � � �"�"�"�"�"�"�"�"�"�"�"����"�"�"�"���L�L�� "� "� "���D�=�=�#�,�W�5�5�"�"���� � � �"�"�"�"�"�"�"�"�"�"�"����"�"�"�"���L� � � � � �|�C�C��C�C�C��! �,�Q�/�O��>�"�"�a�'�'�%�%��O�,�,���C�C�C�C�N�C�C�C�C�C�*�)�)�0�6�6��I�I�A�A�.�A�A�A�A�A���� �o�w�7�7� ,�"1�"7�K������#1������8�&�k�3�7�7�7� 8�  ���>�>�,�3�G�G�=K�G�G�G�D�D�,�'�s�+�+�+��c�l�l�"��!�N��J� � � � � �Ksa�A7�7B � B �/D�.D�D �D �"E0�E! � E0�!E% �%E0�(E% �)E0�DJ�Jr� addr_inforc��jK�g}|�|��|\}}} } } d} |� ||��} ntj||| ���} |�|�| ��| �d��|��|D]�\} } } } }| |kr� | �|��n�#t $rU}d|�d|jpd�����}t |j|��}|�|��Yd}~��d}~wwxYw|r|� ���t d|�d����|� | | ���d{V��| dx}}S#tt f$rr}|�|��| �U|�|� | �� | � ��n(#t $r}|�|���d}~wwxYw�d}~w| �U|�|� | �� | � ��n(#t $r}|�|���d}~wwxYw�xYw#dx}}wxYw) aq Create, bind and connect one socket. If open_sockets is passed, add the socket to the set of open sockets. Any failure caught here will remove the socket from the set and close it. Callers can use this set to close any sockets that are not the winner of all staggered tasks in the result there are runner up sockets aka multiple winners. N)�family�type�protoFz*error while attempting to bind on address z: �z&no matching local address with family=z found)�append�socket�add� setblocking�bindr.�strerror�lowerr/�pop� sock_connectr2�remover;)rrrGr rr� my_exceptionsrI�type_rKrA�addressr@�lfamily�laddrr$rE�es rrr�s ����$9;�M����m�$�$�$�'0�$�F�E�5�!�W� �D�5*� � %�!�>�)�,�,�D�D��=��U�%�H�H�H�D� � #� � � �T� "� "� "� ������� � '�+;� U� U�'���A�q�%��f�$�$�� .��I�I�e�$�$�$��E���.�.�.�:�#(�:�:��L�.�B�5�5�7�7�:�:�� "�#�)�S�1�1�C�!�(�(��-�-�-�-�-�-�-�-�����.����!�U�'�+�+�-�-�-�!�"S�F�"S�"S�"S�T�T�T�����g�.�.�.�.�.�.�.�.�.��.&*�)� �]�]��- �'� "� � � ����S�!�!�!� � ��'��#�#�D�)�)�)� �� � � � � � ��� � � ��$�$�Q�'�'�'������ ���� ����� � � ��'��#�#�D�)�)�)� �� � � � � � ��� � � ��$�$�Q�'�'�'������ ���� �����%)�)� �]�)�)�)�)s��A$E� B!�E�! D�+A C;�6E�;D�A E�H)�.G �F#�"G �# G�-G�G�G � H)�+H�?H)� H%� H � H%�%H)�)H,�,H2� addrinfos�first_address_family_countc���tj��}|D].}|d}||vrg||<||�|���/t|�����}g}|dkr4|�|dd|dz ���|dd|dz �=|�d�t j�t j |���D����|S)z-Interleave list of addrinfo tuples by family.rrNc3�K�|]}|�|V�� dSrr")r�as rrz(_interleave_addrinfos.<locals>.<genexpr>�s0������ � �=� � �=�=�=��r ) � collections� OrderedDictrM�list�values�extend� itertools�chain� from_iterable� zip_longest)r]r^�addrinfos_by_family�addrrI�addrinfos_lists� reordereds rr6r6�s#�� ��!�!���1�1���a��� �,� ,� ,�*,� �� '��F�#�*�*�4�0�0�0�0��.�5�5�7�7�8�8�O�$&�I�!�A�%�%������+�,L�.H�1�.L�,L�M�N�N�N� �A� �?�!;�a�!?�?� @� �������.�.�y�/D�o�/V�W�W������� �r )NNN)r)�__doc__r3rbr9rrgrN�typingrrrrrrLr �typesr r �float�int�AbstractEventLooprFr.r2rr6r"r r�<module>rus=������������������������ � � � �7�7�7�7�7�7�7�7�7�7�7�7�7�7�������2�2�2�2�2�2�2�2� :>�,0� $�04�26�K�K�K���&�K��x� �5�6�K�#�5�/� K� �� � K� �7�,� -� K��.�/�K� �]�K�K�K�K�d:>�15�26� K*�K*� � #�K*��T�%��� 5�6�7�8�K*��K*��x� �5�6� K*� �3�v�}�-�.� K*� �.�/� K*� �]�K*�K*�K*�K*�^JK���� �%��CF�� �,�������r
Memory