
    ,h                        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Jr   SSK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get_param_defis_ip_addresssplit_attemptspsycopgc                t  #    Sn/ n[        U S5      S:H  =n(       a+  U R                  5        VVs0 sH  u  pEUS:w  d  M  XE_M     n nn[        U 5       H&  n UR                  [	        U5      I Sh  vN 5        M(     U(       d(  U(       d   e[        R                  " [        U5      5      e[        U S5      S:X  a  [        U5        U(       a  U Vs/ sH  n0 UESS0EPM     snU-   nU$ s  snnf  N! [
         a3  n[        R                  SUR                  S5      U5        Un SnAM  SnAff = fs  snf 7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.
Ntarget_session_attrszprefer-standbyzfailed to resolve host %r: %shostload_balance_hostsrandomstandby)r	   itemsr   extend_resolve_hostnamesOSErrorloggerdebuggeteOperationalErrorstrr   )	paramslast_excattemptsprefer_standbykvattemptexas	            [/var/www/html/Ai_home/venv/lib/python3.13/site-packages/psycopg/_conninfo_attempts_async.pyconninfo_attempts_asyncr(      s-     HH"6+ABFVVV~V#)<<>Q>41Q:P5P$!$>Q!&)	OO"4W"==> * x  X//-.(: >F
>F4q4()4h
 O1 R > 	LL8'++f:MrRH	
s^   .D8C+C+D8C30C1
1C39AD8D3#D81C33
D0=(D+%D8+D00D8c                &  #    [        U S5      nU(       a  UR                  S5      (       d	  USS S:X  a  U /$ [        U S5      (       a  U /$ [        U5      (       a	  0 U ESU0E/$ [        U S5      =n(       d)  [        S5      nU=(       a    UR                  =(       d    Sn [
        R                  " 5       nUR                  X[        R                  [        R                  S	9I S
h  vN nU Vs/ sH  n0 U ESUS   S   0EPM     sn$  N"s  snf 7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typeN   r   )r	   
startswithr   r
   compiledasyncioget_running_loopgetaddrinfosocketIPPROTO_TCPSOCK_STREAM)r   r   r.   port_defloopansitems          r'   r   r   B   s     VV$D4??3''4!9+;x$$xT,6,:t,--ff--D- (-H--7'')$$f00v7I7I % 
 
 <??34.v.z471:.3??
 @s$   C%D'D
(D0DDD)r   r   returnlist[ConnDict])r   r   r?   r@   )__doc__
__future__r   r8   loggingr   r    r   r   abcr   r   _conninfo_utilsr	   r
   r   r   r5   	getLoggerr   r(   r        r'   <module>rJ      sF    #     & T T			9	%(V*@rI   