
    gi                        d Z ddlmZ ddlZddlZddlmZ ddlmZ	 ddl
mZmZ ddlmZmZmZmZ 	 ddlZ ej        d
          ZddZddZdS )z8
Separate connection attempts from a connection string.
    )annotationsN)shuffle   )errors)ConnDictConnMapping)	get_paramget_param_defis_ip_addresssplit_attemptsTpsycopgparamsr   returnlist[ConnDict]c                6  K   d}g }t          | d          dk    x}rd |                                 D             } t          |           D ]s}	 |                    t	          |           d{V            ,# t
          $ r;}t                              d|                    d          |           |}Y d}~ld}~ww xY w|s%|sJ t          j
        t          |                    t          | d          dk    rt          |           |rd	 |D             |z   }|S )
a  Split a set of connection params on the single attempts to perform.

    A connection param can perform more than one attempt more than one ``host``
    is provided.

    Also perform async resolution of the hostname into hostaddr. Because a host
    can resolve to more than one address, this can lead to yield more attempts
    too. Raise `OperationalError` if no host could be resolved.

    Because the libpq async function doesn't honour the timeout, we need to
    reimplement the repeated attempts.
    Ntarget_session_attrszprefer-standbyc                &    i | ]\  }}|d k    ||S )r    ).0kvs      p/var/www/html/Pagina-Ingenieria-Requisitos/venv/lib/python3.11/site-packages/psycopg/_conninfo_attempts_async.py
<dictcomp>z+conninfo_attempts_async.<locals>.<dictcomp>'   s)    QQQ41aQ:P5P5P!Q5P5P5P    zfailed to resolve host %r: %shostload_balance_hostsrandomc                    g | ]
}i |d diS )r   standbyr   )r   as     r   
<listcomp>z+conninfo_attempts_async.<locals>.<listcomp>;   s6     
 
 
9:4q4()44
 
 
r   )r	   itemsr   extend_resolve_hostnamesOSErrorloggerdebuggeteOperationalErrorstrr   )r   last_excattemptsprefer_standbyattemptexs         r   conninfo_attempts_asyncr1      sn      HH"6+ABBFVVV~ RQQ6<<>>QQQ!&))  	OO"4W"="=======>>>> 	 	 	LL8'++f:M:MrRRRHHHHHH	  0 X///-..(::  
 
>F
 
 
 Os   (A66
B; 1B66B;r   c                   K   t           d          }|r#|                    d          s|dd         dk    r gS t           d          r gS t          |          r	i  d|igS t           d          x}st          d          }|r|j        pd}	 t          j                    }|                    ||t          j	        t          j
        
           d{V } fd|D             S )aD  
    Perform async DNS lookup of the hosts and return a list of connection attempts.

    If a ``host`` param is present but not ``hostname``, resolve the host
    addresses asynchronously.

    :param params: The input parameters, for instance as returned by
        `~psycopg.conninfo.conninfo_to_dict()`. The function expects at most
        a single entry for host, hostaddr because it is designed to further
        process the input of split_attempts().

    :return: A list of attempts to make (to include the case of a hostname
        resolving to more than one IP).
    r   /r      :hostaddrport5432T)prototypeNc                8    g | ]}i d |d         d         iS )r6      r   r   )r   itemr   s     r   r!   z&_resolve_hostnames.<locals>.<listcomp>l   s1    ???4.v.z471:..???r   )r	   
startswithr   r
   compiledasyncioget_running_loopgetaddrinfosocketIPPROTO_TCPSOCK_STREAM)r   r   r7   port_defloopanss   `     r   r$   r$   B   s:      VV$$D 4??3'' 4!9+;+;x$$ xT .,6,:t,,--ff---D 8 ((-H-7
'))$$$f0v7I % 
 
 
 
 
 
 
 
 @???3????r   )r   r   r   r   )r   r   r   r   )__doc__
__future__r   rC   loggingr   r    r   r)   abcr   r   _conninfo_utilsr	   r
   r   r   r@   	getLoggerr&   r1   r$   r   r   r   <module>rP      s     # " " " " "               & & & & & & & & T T T T T T T T T T T TNNN		9	%	%( ( ( (V*@ *@ *@ *@ *@ *@r   