Ë
    êë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  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                ó  — d}g }t        | d«      dk(  x}r)| j                  «       D ��ci c]  \  }}|dk7  sŒ||“Œ } }}t        | «      D ]  }	 |j                  t	        |«      «       Œ |s|sJ ‚|‚t        | d«      d	k(  rt        |«       |r|D �cg c]
  }i |¥dd
i¥‘Œ c}|z   }|S c c}}w # t
        $ rJ}t        j                  d|j                  d«      ›d|› �«      }t        j                  d|«       Y d}~Œ³d}~ww xY wc c}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	            úa/var/www/html/kelly/kelly-backend/venv/lib/python3.12/site-packages/psycopg/_conninfo_attempts.pyÚconninfo_attemptsr'      s:  € ð €HØ€Hä�&Ð0Ó1Ð5EÑEð€~ð ð $*§<¡<¤>ÔQ¡>™4˜1˜a°QÐ:PÓ5P�!�Q‘$ >ˆÑ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)   ©B)·B)ÁB/ÂDÂ/	DÂ8A C=Ã=D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«      x}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-   Ú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°ˆä
×
Ñ
Øˆdœ&×,Ñ,´6×3EÑ3Eô€Cñ <?Ó?¹3°4Ð.ˆvÐ.�z 4¨¡7¨1¡:Ó.¸3Ñ?Ð?ùÒ?s   Â4C)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      sB   ðñõ #ã Û Ý å ß &ß TÓ Tà	ˆ×	Ñ	˜9Ó	%€ó,ô^$@rE   