Ë
    Ûq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 dd	l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Úis_ip_addressÚget_param_def)Úsplit_attemptsÚpsycopgc              ƒ  óx  K  — d}g }t        | «      D ]%  }	 |j                  t        |«      ƒ d{  –—† «       Œ' |s"|sJ ‚t        j                  t        |«      «      ‚t        | d«      dk(  rt        |«       |S 7 ŒJ# t        $ r2}t        j                  d|j                  d«      |«       |}Y d}~Œ d}~ww xY 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.
    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        úa/var/www/html/kelly-backend/venv/lib/python3.12/site-packages/psycopg/_conninfo_attempts_async.pyÚconninfo_attempts_asyncr!      s¬   è ø€ ð €HØ€HÜ! &Ö)ˆð	Ø�O‰OÔ"4°WÓ"=×=Õ>ð *ñ Ùˆˆxä× Ñ ¤ X£Ó/Ð/ä�Ð-Ó.°(Ò:Ü�Ôà€Oð >ùÜò 	Ü�L‰LÐ8¸'¿+¹+ÀfÓ:MÈrÔRØ�Hûð	üs>   ‚B:–A<¯A:
°A<¸AB:Á:A<Á<	B7Â(B2Â-B:Â2B7Â7B: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«      }|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&   r'   Úport_defÚloopÚansÚitems           r    r   r   9   s  è ø€ ô �V˜VÓ$€DÙ�4—?‘? 3Ô'¨4°°!¨9¸Ò+;àˆxˆä˜ Ó,€HÙàˆxˆä�TÔà,�6Ð,˜: tÑ,Ð-Ð-ä�V˜VÓ$€DÙÜ  Ó(ˆØÒ-˜H×-Ñ-Ò7°ˆàÜ×'Ñ'Ó)ˆØ×$Ñ$Ø�$œf×0Ñ0´v×7IÑ7Ið %ó 
÷ 
ˆñ <?Ó?¹3°4Ð.ˆvÐ.�z 4¨¡7¨1¡:Ó.¸3Ñ?Ð?ð
úò @ùs$   ‚CC0ÃC)Ã	C0ÃC+Ã&C0Ã+C0)r   r   Úreturnúlist[ConnDict])r   r   r8   r9   )Ú__doc__Ú
__future__r   r1   Úloggingr   r   Ú r   r   Úabcr   r   Ú_conninfo_utilsr	   r
   r   r   r.   Ú	getLoggerr   r!   r   © ó    r    Ú<module>rC      sK   ðñõ #ã Û Ý å ß &ß DÑ DÝ +àÛà	ˆ×	Ñ	˜9Ó	%€óôB,@rB   