U
    ~fh
                     @  s   d Z ddlm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ddZejdkrejZejZn dddddZdd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ddd fdd}t t|S )Nr   )argskwargsr   c               
     s   | dd}ddlm} ddlm} z | |I d H W S  tk
r } zv|rN |jtkrd }| D ]*}t||rv|} qt||r`|j	} qq`|r|j
ddI d H  n  | | W Y S  W 5 d }~X Y nX d S )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    @/tmp/pip-unpacked-wheel-36gvocj8/pymongo/asynchronous/helpers.pyinner'   s,    


z_handle_reauth.<locals>.inner)r   r	   )r   r   r   r   r   _handle_reauth&   s    r   )   
   r   )clsr   c                   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   anextL   s    r#   c                 C  s   |   S )r    )	__aiter__r"   r   r   r   aiterP   s    r%   )__doc__
__future__r   builtinssystypingr   r   r   r   Zpymongo.errorsr   Zpymongo.helpers_sharedr   Z_IS_SYNCr	   r   version_infor#   r%   r   r   r   r   <module>   s   !
