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.error	nInsertedr   nDeletednMatched	nModified	nUpsertedwriteErrorsidx   opwriteConcernErrorsN)getcopyappendr
   )	r   r   r   r   write_errorsdocreplacementoriginal_indexwce r)   W/var/www/html/olx_land/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,   errr0   msgr1   r)   r)   r*   "_throw_client_bulk_write_exception<   s   
r9   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   pymongo.errorsr   r	   pymongo.helpers_sharedr
   pymongo.typingsr   r+   r9   r)   r)   r)   r*   <module>   s   
 