o
    C©Ì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%   úb/var/www/html/Moveonwheels/move_on_wheels/venv/lib/python3.10/site-packages/pymongo/bulk_shared.pyÚ__init__/   s   
z_Run.__init__Úidxc                 C  s
   | j | S )z€Get 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 )zÒAdd 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"   
,