Ë
    êëj  ã                  ó¢   — 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y)z8
Separate connection attempts from a connection string.
é    )ÚannotationsN)Úshuffleé   )Úerrors)ÚConnDictÚConnMapping)Ú	get_paramÚget_param_defÚis_ip_addressÚsplit_attemptsÚpsycopgc              ƒ  ó0  K  — d}g }t        | d«      dk(  x}r)| j                  «       D ��ci c]  \  }}|dk7  sŒ||“Œ } }}t        | «      D ]%  }	 |j                  t	        |«      ƒ d{  –—† «       Œ' |s|sJ ‚|‚t        | d«      d	k(  rt        |«       |r|D �cg c]
  }i |¥dd
i¥‘Œ c}|z   }|S c c}}w 7 ŒO# t
        $ rJ}t        j                  d|j                  d«      ›d|› �«      }t        j                  d|«       Y d}~Œ½d}~ww xY wc c}w ­w)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 Úhostz: z%sÚload_balance_hostsÚrandomÚstandby)r	   Úitemsr   ÚextendÚ_resolve_hostnamesÚOSErrorÚeÚOperationalErrorÚgetÚloggerÚdebugr   )	ÚparamsÚlast_excÚattemptsÚprefer_standbyÚkÚvÚattemptÚexÚas	            úg/var/www/html/kelly/kelly-backend/venv/lib/python3.12/site-packages/psycopg/_conninfo_attempts_async.pyÚconninfo_attempts_asyncr'      s>  è ø€ ð €HØ€HÜ" 6Ð+AÓBÐFVÑVÐV€~ÐVØ#)§<¡<¤>ÔQ¡>™4˜1˜a°QÐ:PÓ5P�!�Q‘$ >ˆÑQä! &Ö)ˆð	)Ø�O‰OÔ"4°WÓ"=×=Õ>ð *ñ Ùˆˆxàˆä�Ð-Ó.°(Ò:Ü�Ôñ á>Fó
Ù>F¸Ð4ˆqÐ4Ð(¨)Ó4¸hñ
àñˆð €Oùó5 Rð >ùÜò 	)Ü×)Ñ)Ø)¨'¯+©+°fÓ*=Ð)@ÀÀ2À$ÐGóˆHô �L‰L˜˜x×(Ñ(ûð		)üò"
ùs]   ‚)D«B3¹B3¾DÁB;Á)B9
Á*B;Á2*DÂDÂ+DÂ9B;Â;	DÃA D	ÄDÄ	DÄDc              ƒ  óà  K  — t        | d«      }|r|j                  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«      }|xr |j                  xs d}	 t        j                  «       }|j                  ||t        j                  t        j                  ¬	«      ƒ d
{  –—† }|D �cg c]  }i | ¥d|d   d   i¥‘Œ c}S 7 Œ c c}w ­w)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Ú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   D   s  è ø€ ô �V˜VÓ$€DÙ�4—?‘? 3Ô'¨4°°!¨9¸Ò+;àˆxˆä�˜Ô$àˆxˆä�TÔà,�6Ð,˜: tÑ,Ð-Ð-ä˜f fÓ-Ð-ˆDÐ-Ü  Ó(ˆØÒ-˜H×-Ñ-Ò7°ˆàÜ×'Ñ'Ó)ˆØ×$Ñ$Ø�$œf×0Ñ0´v×7IÑ7Ið %ó 
÷ 
ˆñ <?Ó?¹3°4Ð.ˆvÐ.�z 4¨¡7¨1¡:Ó.¸3Ñ?Ð?ð
úò @ùs$   ‚CC.ÃC'ÃC.ÃC)Ã$C.Ã)C.)r   r   Úreturnúlist[ConnDict])r   r   r>   r?   )Ú__doc__Ú
__future__r   r7   Úloggingr   r   Ú r   r   Úabcr   r   Ú_conninfo_utilsr	   r
   r   r   r4   Ú	getLoggerr   r'   r   © ó    r&   Ú<module>rI      sH   ðñõ #ã Û Ý å ß &ß TÓ TàÛà	ˆ×	Ñ	˜9Ó	%€ó*ôZ*@rH   