o
    hw                     @  s   d Z ddlmZ ddlZddlZddlZddlZddlmZm	Z	m
Z
mZ ddlmZ ddlmZ dZe
de	d	ef d
ZdddZdddZejdkrSejZejZdS dddZdddZdS )z2Miscellaneous pieces that need to be synchronized.    )annotationsN)AnyCallableTypeVarcast)OperationFailure)_REAUTHENTICATION_REQUIRED_CODEFF.)boundfuncreturnc                   s   d fdd}t t|S )Nargsr   kwargsr   c               
     s   | dd}ddlm} ddlm} z | i |I d H W S  tyg } z=|r) |jtkrbd }| D ]}t||r=|} nt||rG|j	} nq2|rT|j
ddI d H  n  | i |W  Y d }~S  d }~ww )N	no_reauthFr   )AsyncConnection)_BulkWriteContextT)Zreauthenticate)popZpymongo.asynchronous.poolr   Zpymongo.messager   r   coder   
isinstanceconnZauthenticate)r   r   r   r   r   excr   argr    O/var/www/html/venv/lib/python3.10/site-packages/pymongo/asynchronous/helpers.pyinner)   s4   


z_handle_reauth.<locals>.inner)r   r   r   r   r   r   )r   r	   )r   r   r   r   r   _handle_reauth(   s   
r   hostr   portr   klist[tuple[socket.AddressFamily, socket.SocketKind, int, str, tuple[str, int] | tuple[str, int, int, int]]]c                   s<   t st }|j| |fi |I d H S tj| |fi |S )N)_IS_SYNCasyncioZget_running_loopgetaddrinfosocket)r   r   r   loopr   r   r   _getaddrinfoI   s
   r%   )   
   clsc                   s   |   I dH S )iCompatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#anext.N)	__anext__r(   r   r   r   anext`   s   r,   c                 C  s   |   S )r)   )	__aiter__r+   r   r   r   aiterd   s   r.   )r   r	   r   r	   )r   r   r   r   r   r   r   r   )r(   r   r   r   )__doc__
__future__r   r!   builtinsr#   systypingr   r   r   r   Zpymongo.errorsr   Zpymongo.helpers_sharedr   r    r	   r   r%   version_infor,   r.   r   r   r   r   <module>   s$   

!


