o
    'h.                     @  s   U 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 ddlmZmZmZ er7ddlmZ dZded	< d
Zded< dZded< dZded< dZded< dZded< G dd dZd&dd Zd'd#d$Zd%S )(zKConstants, types, and classes shared across Bulk Write API implementations.    )annotations)TYPE_CHECKINGAnyMappingMutableMappingNoReturn)BulkWriteErrorOperationFailure)_get_wce_doc)_DELETE_INSERT_UPDATE)_DocumentOutint_DELETE_ALL   _DELETE_ONE   
_BAD_VALUE   _UNKNOWN_ERROR@   _WRITE_CONCERN_ERROR)insertupdatedeleteztuple[str, str, str]	_COMMANDSc                   @  s.   e Zd ZdZdddZdd	d
ZdddZdS )_Runz'Represents a batch of write operations.op_typer   returnNonec                 C  s   || _ g | _g | _d| _dS )zInitialize a new Run object.r   N)r   	index_mapops
idx_offset)selfr    r%   O/var/www/html/olx_land/venv/lib/python3.10/site-packages/pymongo/bulk_shared.py__init__/   s   
z_Run.__init__idxc                 C  s
   | j | S )zGet the original index of an operation in this run.

        :param idx: The Run index that maps to the original index.
        )r!   )r$   r(   r%   r%   r&   index6   s   
z
_Run.indexoriginal_index	operationr   c                 C  s   | j | | j| dS )zAdd an operation to this Run instance.

        :param original_index: The original index of this operation
            within a larger bulk operation.
        :param operation: The operation document.
        N)r!   appendr"   )r$   r*   r+   r%   r%   r&   add=   s   z_Run.addN)r   r   r   r    )r(   r   r   r   )r*   r   r+   r   r   r    )__name__
__module____qualname____doc__r'   r)   r-   r%   r%   r%   r&   r   ,   s
    

r   runfull_resultMutableMapping[str, Any]offsetresultMapping[str, Any]r   r    c                 C  sT  | dd}| jtkr|d  |7  < nZ| jtkr"|d  |7  < nL| jtkrn| d}|r\t|}|D ]}| |d | |d< q4|d | |d  |7  < |d  || 7  < n|d  |7  < |d	  |d	 7  < | d
}|r|D ]!}| }	|d | }
| |
|	d< | j	|
 |	d< |d
 
|	 qwt|}|r|d 
| dS dS )z7Merge a write command result into the full bulk result.nr   	nInsertednRemovedupsertedr)   	nUpsertednMatched	nModifiedwriteErrorsopwriteConcernErrorsN)getr   r   r   r   lenr)   extendcopyr"   r,   r
   )r2   r3   r5   r6   affectedr;   
n_upserteddocwrite_errorsreplacementr(   wcer%   r%   r&   _merge_commandH   s8   




rL   r   r   c                 C  sb   | d r-| d j dd d | d d }|d }|d }|dkr-|d	r-d
}t||| t| )z5Raise a BulkWriteError from the full bulk api result.r?   c                 S  s   | d S )Nr)   r%   )errorr%   r%   r&   <lambda>x   s    z)_raise_bulk_write_error.<locals>.<lambda>)keyr   codeerrmsg   zTransaction numberszrThis MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.)sort
startswithr	   r   )r3   errrP   msgrQ   r%   r%   r&   _raise_bulk_write_errort   s   rW   N)
r2   r   r3   r4   r5   r   r6   r7   r   r    )r3   r   r   r   )r1   
__future__r   typingr   r   r   r   r   pymongo.errorsr   r	   pymongo.helpers_sharedr
   pymongo.messager   r   r   pymongo.typingsr   r   __annotations__r   r   r   r   r   r   rL   rW   r%   r%   r%   r&   <module>   s"   
,