ó
    Ð]j­  ã                  óœ   • 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  \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                óV  • 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      5        M      U(       d  U(       d   eU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 ! [
         aM  n[        R                  " SUR                  S5      < SU 35      n[        R                  SU5         SnAMÌ  SnAff = fs  sn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 Ú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	            ÚW/home/mande/repo/quber/.venv/lib/python3.13/site-packages/psycopg/_conninfo_attempts.pyÚconninfo_attemptsr'      s8  € ð €HØ€Hä�&Ð0Ó1Ð5EÑEð€~õ ð $*§<¡<¤>ÔQ¢>™4˜1°QÐ:PÑ5P“$�!’$¡>ˆÑQä! &Ö)ˆð	)Ø�O‰OÔ.¨wÓ7Ö8ñ *ö Þˆˆxàˆä�Ð-Ó.°(Ó:Ü�Ôö á>Fó
Ú>F¸Ð4ˆqÐ4Ð(¨)Ô4¹hñ
àñˆð €Oùó5 Røô
 ó 	)Ü×)Ò)Ø)¨'¯+©+°fÓ*=Ñ)@ÀÀ2À$ÐGóˆHô �L‰L˜˜x×(Ò(ûð		)üò"
s)   ®C¾CÁCÂ,D&Ã
D#ÃADÄD#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                  " 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-   Úport_defÚansÚitems         r&   r   r   F   sì   € ô �V˜VÓ$€DÞ�4—?‘? 3×'Ñ'¨4°°!¨9¸Ó+;àˆxˆä�˜×$Ñ$àˆxˆä�T×Ñà,�6Ð,˜: tÑ,Ð-Ð-ä˜f fÓ-Ð-ˆDÕ-Ü  Ó(ˆØ×-˜H×-Ñ-×7°ˆä
×
Ò
Øœ&×,Ñ,´6×3EÑ3Eñ€Cñ <?Ó?º3°4Ð.ˆvÐ.�z 4¨¡7¨1¡:Ô.¹3Ñ?Ð?ùÒ?s   ÃC0)r   r   Úreturnúlist[ConnDict])r   r   r;   r<   )Ú__doc__Ú
__future__r   r4   Úloggingr   r   Ú r   r   Úabcr   r   Ú_conninfo_utilsr	   r
   r   r   Ú	getLoggerr   r'   r   © ó    r&   Ú<module>rF      s@   ðñõ #ã Û Ý å ß &ß TÓ Tà	×	Ò	˜9Ó	%€ô,õ^$@rE   