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_CODET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 | |W S  tk
r } zp|rH |jtkrd }| D ]*}t||rp|} qt||rZ|j	} qqZ|r|j
dd n  | | W Y S  W 5 d }~X Y nX d S )N	no_reauthFr   )_BulkWriteContext)
ConnectionT)Zreauthenticate)popZpymongo.messager   Zpymongo.synchronous.poolr   r   coder   
isinstanceconnZauthenticate)r   r   r   r   r   excr   argr    ?/tmp/pip-unpacked-wheel-36gvocj8/pymongo/synchronous/helpers.pyinner'   s,    


z_handle_reauth.<locals>.inner)r   r	   )r   r   r   r   r   _handle_reauth&   s    r   )   
   r   )clsr   c                 C  s   |   S zhCompatibility function until we drop 3.9 support: https://docs.python.org/3/library/functions.html#next.)__next__r   r   r   r   nextL   s    r#   c                 C  s   |   S r    )__iter__r"   r   r   r   iterP   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   !
