o
    l=8jj                  	   @   s  d Z ddlZddlZddlmZ deeeeef eeeef B eeef B dB dee dB fddZ		dd	ee d
edB ddfddZ
deeef eeeeef B deejef eejeeef B fddZd	ee deeef eeeeef B ddfddZdS )z'Utility functions for aiohappyeyeballs.    N   )AddrInfoTypeaddrreturnc                 C   s   | du rdS | d }| d }d|v }|r6d}d}t | }|dkr$| d }|dkr,| d }||||f} tj}n||f} tj}|tjtjd| fgS )	z7Convert an address tuple to a list of addr_info tuples.Nr   r   :          )lensocketAF_INET6AF_INETSOCK_STREAMIPPROTO_TCP)r   hostportis_ipv6flowinfoscopeidaddr_lenfamily r   ]/home/nk/hobo-godmode/plappi-mvp/.venv/lib/python3.10/site-packages/aiohappyeyeballs/utils.pyaddr_to_addr_infos	   s$   r   
addr_infos
interleavec                 C   st   i }|du rd}g }| D ]!}|d }||vrd||< || |k r%| | ||  d7  < q|D ]}| | q0dS )z
    Pop addr_info from the list of addr_infos by family up to interleave times.

    The interleave parameter is used to know how many addr_infos for
    each family should be popped of the top of the list.
    Nr   r   )appendremove)r   r   seen	to_remove	addr_infor   r   r   r   pop_addr_infos_interleave"   s   	
r"   c                 C   s   t | d g| dd R S )z+Convert an address tuple to an IPv4Address.r   r   N)	ipaddress
ip_address)r   r   r   r   _addr_tuple_to_ip_address:   s   r%   c                 C   s   g }| D ]}|d |kr| | q|r |D ]}| | qdS t|}| D ]}|t|d kr5| | q&|rD|D ]}| | q:dS td| d)z
    Remove an address from the list of addr_infos.

    The addr value is typically the return value of
    sock.getpeername().
    NzAddress z not found in addr_infos)r   r   r%   
ValueError)r   r   bad_addrs_infosr!   bad_addr_info
match_addrr   r   r   remove_addr_infosA   s&   


r+   )N)__doc__r#   r   typesr   tuplestrintlistr   r"   IPv4AddressIPv6Addressr%   r+   r   r   r   r   <module>   s:    ,



