Ë
    Û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  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                ó\  — d}g }t        | «      D ]  }	 |j                  t        |«      «       Œ |s"|sJ ‚t        j                  t        |«      «      ‚t        | d«      dk(  rt        |«       |S # t        $ r2}t        j                  d|j                  d«      |«       |}Y d}~Œ–d}~ww xY 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        ú[/var/www/html/kelly-backend/venv/lib/python3.12/site-packages/psycopg/_conninfo_attempts.pyÚconninfo_attemptsr!      s£   € ð €HØ€HÜ! &Ö)ˆð	Ø�O‰OÔ.¨wÓ7Õ8ð *ñ Ùˆˆxä× Ñ ¤ X£Ó/Ð/ä�Ð-Ó.°(Ò:Ü�Ôà€Oøô ò 	Ü�L‰LÐ8¸'¿+¹+ÀfÓ:MÈrÔRØ�Hûð	ús   ”A0Á0	B+Á9(B&Â&B+c                ó¦  — 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                  ||t
        j                  t
        j                  ¬	«      }|D �cg c]  }i | ¥d|d
   d   i¥‘Œ c}S c c}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Útypeé   r   )	r	   Ú
startswithr
   r   ÚcompiledÚsocketÚgetaddrinfoÚIPPROTO_TCPÚSOCK_STREAM)r   r   r&   r'   Úport_defÚansÚitems          r    r   r   :   sç   € ô �V˜VÓ$€DÙ�4—?‘? 3Ô'¨4°°!¨9¸Ò+;àˆxˆä˜ Ó,€HÙàˆxˆä�TÔà,�6Ð,˜: tÑ,Ð-Ð-ä�V˜VÓ$€DÙÜ  Ó(ˆØÒ-˜H×-Ñ-Ò7°ˆä
×
Ñ
Øˆdœ&×,Ñ,´6×3EÑ3Eô€Cñ <?Ó?¹3°4Ð.ˆvÐ.�z 4¨¡7¨1¡:Ó.¸3Ñ?Ð?ùÒ?s   Â6C)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@      sG   ðñõ #ã Û Ý å ß &ß DÑ DÝ +ð 
ˆ×	Ñ	˜9Ó	%€óôB&@r?   