o
    h@                     @  sp   d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZ ddlmZ er,ddlmZ dddZdddZdS )zRConstants, types, and classes shared across Client Bulk Write API implementations.    )annotations)TYPE_CHECKINGAnyMappingMutableMappingNoReturn)ClientBulkWriteExceptionOperationFailure)_get_wce_doc)_DocumentOutops#list[tuple[str, Mapping[str, Any]]]offsetintfull_resultMutableMapping[str, Any]resultMapping[str, Any]returnNonec           	      C  s  | dr|d |d< |d  | dd7  < |d  | dd7  < |d  | dd7  < |d  | dd7  < |d  | dd7  < | d}|rp|D ]}| }|d	 | }||d	< | | d
 |d< |d | qPt|}|r|d | dS dS )z?Merge result of a single bulk write batch into the full result.errorZ	nInsertedr   ZnDeletedZnMatchedZ	nModifiedZ	nUpsertedwriteErrorsidx   opZwriteConcernErrorsN)getcopyappendr
   )	r   r   r   r   Zwrite_errorsdocreplacementZoriginal_indexZwce r    N/var/www/html/venv/lib/python3.10/site-packages/pymongo/_client_bulk_shared.py_merge_command   s&   

r"   r   verbose_resultsboolr   c                 C  s   | d r-| d j dd d | d d }|d }|d }|dkr-|d	r-d
}t||| t| d tr<t| || d t| |)z6Raise a ClientBulkWriteException from the full result.r   c                 S  s   | d S )Nr   r    )r   r    r    r!   <lambda>B   s    z4_throw_client_bulk_write_exception.<locals>.<lambda>)keyr   codeerrmsg   zTransaction numberszrThis MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.r   )sort
startswithr	   
isinstanceBaseExceptionr   )r   r#   errr'   msgr(   r    r    r!   "_throw_client_bulk_write_exception<   s   
r0   N)
r   r   r   r   r   r   r   r   r   r   )r   r   r#   r$   r   r   )__doc__
__future__r   typingr   r   r   r   r   Zpymongo.errorsr   r	   Zpymongo.helpers_sharedr
   Zpymongo.typingsr   r"   r0   r    r    r    r!   <module>   s   
 