§
    YŠtj­  ã                  ó–   — 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dS )z8
Separate connection attempts from a connection string.
é    )ÚannotationsN)Úshuffleé   )Úerrors)ÚConnDictÚConnMapping)Ú	get_paramÚget_param_defÚis_ip_addressÚsplit_attemptsÚpsycopgÚparamsr   Úreturnúlist[ConnDict]c                ó  — d}g }t          | d¦  «        dk    x}rd„ |                      ¦   «         D ¦   «         } t          | ¦  «        D ]„}	 |                     t	          |¦  «        ¦  «         Œ&# t
          $ rR}t          j        d|                     d¦  «        ›d|› �¦  «        }t           
                    d|¦  «         Y d}~Œ}d}~ww xY w|s|sJ ‚|‚t          | d	¦  «        d
k    rt          |¦  «         |rd„ |D ¦   «         |z   }|S )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-standbyc                ó&   — i | ]\  }}|d k    ¯||“ŒS )r   © )Ú.0ÚkÚvs      úX/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/psycopg/_conninfo_attempts.pyú
<dictcomp>z%conninfo_attempts.<locals>.<dictcomp>)   s)   € ÐQÐQÐQ™4˜1˜a°QÐ:PÒ5PÐ5P�!�QÐ5PÐ5PÐ5Pó    zfailed to resolve host Úhostz: z%sÚload_balance_hostsÚrandomc                ó   — g | ]
}i |¥d di¥‘ŒS )r   Ústandbyr   )r   Úas     r   ú
<listcomp>z%conninfo_attempts.<locals>.<listcomp>?   s6   € ð 
ð 
ð 
Ø9:Ð4ˆqÐ4Ð(¨)Ð4Ð4ð
ð 
ð 
r   )r	   Úitemsr   ÚextendÚ_resolve_hostnamesÚOSErrorÚeÚOperationalErrorÚgetÚloggerÚdebugr   )r   Úlast_excÚattemptsÚprefer_standbyÚattemptÚexs         r   Úconninfo_attemptsr0      so  € ð €HØ€Hå�&Ð0Ñ1Ô1Ð5EÒEð€~ð Rð RÐQ 6§<¢<¡>¤>ÐQÑQÔQˆå! &Ñ)Ô)ð )ð )ˆð	)Ø�OŠOÕ.¨wÑ7Ô7Ñ8Ô8Ð8Ð8øÝð 	)ð 	)ð 	)ÝÔ)ØG¨'¯+ª+°fÑ*=Ô*=ÐGÐGÀ2ÐGÐGñô ˆHõ �LŠL˜˜xÑ(Ô(Ð(Ð(Ð(Ð(Ð(Ð(øøøøð		)øøøð ð Øˆˆˆxàˆå�Ð-Ñ.Ô.°(Ò:Ð:Ý�ÑÔÐð ð ð
ð 
Ø>Fð
ñ 
ô 
àñˆð €Os   Á"A.Á.
C
Á8ACÃC
r   c                ó–  ‡ — t          ‰ d¦  «        }|r#|                     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¦  «        }|r|j        pd}t          j        ||t
          j        t
          j        ¬	¦  «        }ˆ fd
„|D ¦   «         S )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Útypec                ó8   •— g | ]}i ‰¥d |d         d         i¥‘ŒS )r5   é   r   r   )r   Úitemr   s     €r   r!   z&_resolve_hostnames.<locals>.<listcomp>j   s1   ø€ Ð?Ð?Ð?°4Ð.ˆvÐ.�z 4¨¤7¨1¤:Ð.Ð.Ð?Ð?Ð?r   )	r	   Ú
startswithr   r
   ÚcompiledÚsocketÚgetaddrinfoÚIPPROTO_TCPÚSOCK_STREAM)r   r   r6   Úport_defÚanss   `    r   r$   r$   F   s  ø€ õ �V˜VÑ$Ô$€DØð �4—?’? 3Ñ'Ô'ð ¨4°°!°¬9¸Ò+;Ð+;àˆxˆå�˜Ñ$Ô$ð àˆxˆå�TÑÔð .à,�6Ð,˜: tÐ,Ð,Ð-Ð-å˜f fÑ-Ô-Ð-ˆDð 8Ý  Ñ(Ô(ˆØÐ-˜HÔ-Ð7°ˆå
Ô
Øˆd�&Ô,µ6Ô3Eðñ ô €Cð @Ð?Ð?Ð?¸3Ð?Ñ?Ô?Ð?r   )r   r   r   r   )r   r   r   r   )Ú__doc__Ú
__future__r   r?   Úloggingr   r   Ú r   r&   Úabcr   r   Ú_conninfo_utilsr	   r
   r   r   Ú	getLoggerr)   r0   r$   r   r   r   ú<module>rL      sà   ððð ð #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ø TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ Tà	ˆÔ	˜9Ñ	%Ô	%€ð,ð ,ð ,ð ,ð^$@ð $@ð $@ð $@ð $@ð $@r   