
    (ph                        S r SSKJr  SSKrSSKrSSKJr  SSKJr	  SSK
JrJr  SSKJrJrJr  SS	KJr  \R$                  " S
5      rSS jrSS jrg)z8
Separate connection attempts from a connection string.
    )annotationsN)shuffle   )errors)ConnDictConnMapping)	get_paramis_ip_addressget_param_def)split_attemptspsycopgc                |   Sn/ n[        U 5       H  n UR                  [        U5      5        M      U(       d(  U(       d   e[        R                  " [        U5      5      e[        U S5      S:X  a  [        U5        U$ ! [         a3  n[        R                  SUR                  S5      U5        Un SnAM  SnAff = f)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.
Nzfailed to resolve host %r: %shostload_balance_hostsrandom)r   extend_resolve_hostnamesOSErrorloggerdebuggeteOperationalErrorstrr	   r   )paramslast_excattemptsattemptexs        M/var/www/html/venv/lib/python3.13/site-packages/psycopg/_conninfo_attempts.pyconninfo_attemptsr!      s     HH!&)	OO.w78 * x  X//-.(:O  	LL8'++f:MrRH	s   A>>
B;(B66B;c                   [        U S5      nU(       a  UR                  S5      (       d	  USS S:X  a  U /$ [        U S5      nU(       a  U /$ [        U5      (       a	  0 U ESU0E/$ [        U S5      nU(       d)  [        S5      nU=(       a    UR                  =(       d    Sn[
        R                  " X[
        R                  [
        R                  S	9nU Vs/ s H  n0 U ESUS
   S   0EPM     sn$ s  snf )a  
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5432)prototype   r   )	r	   
startswithr
   r   compiledsocketgetaddrinfoIPPROTO_TCPSOCK_STREAM)r   r   r&   r'   port_defansitems          r    r   r   :   s     VV$D4??3''4!9+;x,HxT,6,:t,--VV$D (-H--7


&,,63E3EC <??34.v.z471:.3???s   C2)r   r   returnlist[ConnDict])r   r   r5   r6   )__doc__
__future__r   r.   loggingr   r    r   r   abcr   r   _conninfo_utilsr	   r
   r   r   	getLoggerr   r!   r        r    <module>r@      sE    #     & D D + 
		9	%B&@r?   