§
    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 	 ddl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_attemptsTÚpsycopgÚparamsr   Úreturnúlist[ConnDict]c              ƒ  ó&  K  — d}g }t          | d¦  «        dk    x}rd„ |                      ¦   «         D ¦   «         } t          | ¦  «        D ]Š}	 |                     t	          |¦  «        ƒ d{V —†¦  «         Œ,# 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      ú^/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/psycopg/_conninfo_attempts_async.pyú
<dictcomp>z+conninfo_attempts_async.<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_async.<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_attempts_asyncr0      s€  è è € ð €HØ€HÝ" 6Ð+AÑBÔBÐFVÒVÐV€~ð RØQÐQ 6§<¢<¡>¤>ÐQÑQÔQˆå! &Ñ)Ô)ð )ð )ˆð	)Ø�OŠOÕ"4°WÑ"=Ô"=Ð=Ð=Ð=Ð=Ð=Ð=Ñ>Ô>Ð>Ð>øÝð 	)ð 	)ð 	)ÝÔ)ØG¨'¯+ª+°fÑ*=Ô*=ÐGÐGÀ2ÐGÐGñô ˆHõ �LŠL˜˜xÑ(Ô(Ð(Ð(Ð(Ð(Ð(Ð(øøøøð		)øøøð ð Øˆˆˆxàˆå�Ð-Ñ.Ô.°(Ò:Ð:Ý�ÑÔÐð ð ð
ð 
Ø>Fð
ñ 
ô 
àñˆð €Os   Á(A6Á6
CÂ ACÃCr   c              ƒ  óÐ  ‡ K  — 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
        ¬
¦  «        ƒ d{V —†}ˆ 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Ú5432T)ÚprotoÚtypeNc                ó8   •— g | ]}i ‰¥d |d         d         i¥‘ŒS )r5   é   r   r   )r   Úitemr   s     €r   r!   z&_resolve_hostnames.<locals>.<listcomp>n   s1   ø€ Ð?Ð?Ð?°4Ð.ˆvÐ.�z 4¨¤7¨1¤:Ð.Ð.Ð?Ð?Ð?r   )r	   Ú
startswithr   r
   ÚcompiledÚasyncioÚget_running_loopÚgetaddrinfoÚsocketÚIPPROTO_TCPÚSOCK_STREAM)r   r   r6   Úport_defÚloopÚanss   `     r   r$   r$   D   s:  øè è € õ �V˜VÑ$Ô$€DØð �4—?’? 3Ñ'Ô'ð ¨4°°!°¬9¸Ò+;Ð+;àˆxˆå�˜Ñ$Ô$ð àˆxˆå�TÑÔð .à,�6Ð,˜: tÐ,Ð,Ð-Ð-å˜f fÑ-Ô-Ð-ˆDð 8Ý  Ñ(Ô(ˆØÐ-˜HÔ-Ð7°ˆð
ÝÔ'Ñ)Ô)ˆØ×$Ò$Ø�$�fÔ0µvÔ7Ið %ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ˆð @Ð?Ð?Ð?¸3Ð?Ñ?Ô?Ð?r   )r   r   r   r   )r   r   r   r   )Ú__doc__Ú
__future__r   rB   Úloggingr   r   Ú r   r&   Úabcr   r   Ú_conninfo_utilsr	   r
   r   r   r?   Ú	getLoggerr)   r0   r$   r   r   r   ú<module>rO      sî   ððð ð #Ð "Ð "Ð "Ð "Ð "à €€€Ø €€€Ø Ð Ð Ð Ð Ð à Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ø TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TðØ€N€N€Nà	ˆÔ	˜9Ñ	%Ô	%€ð*ð *ð *ð *ðZ*@ð *@ð *@ð *@ð *@ð *@r   