
    i)i.                        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rd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          Zd$dZ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                  *    e Zd ZdZddZddZddZdS )_Runz'Represents a batch of write operations.op_typer   returnNonec                >    || _         g | _        g | _        d| _        dS )zInitialize a new Run object.r   N)r    	index_mapops
idx_offset)selfr    s     e/Users/user/workspace/sujinbaek/cqa-test-app/venv/lib/python3.11/site-packages/pymongo/bulk_shared.py__init__z_Run.__init__/   s"    #$&      idxc                    | 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+   s     r(   indexz
_Run.index6   s    
 ~c""r*   original_index	operationr   c                n    | 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/   s      r(   addz_Run.add=   s4     	n---	"""""r*   N)r    r   r!   r"   )r+   r   r!   r   )r.   r   r/   r   r!   r"   )__name__
__module____qualname____doc__r)   r-   r2    r*   r(   r   r   ,   sV        11! ! ! !# # # ## # # # # #r*   r   runfull_resultMutableMapping[str, Any]offsetresultMapping[str, Any]r!   r"   c                   |                     dd          }| j        t          k    r|dxx         |z  cc<   n| j        t          k    r|dxx         |z  cc<   n| j        t          k    r|                     d          }|rtt          |          }|D ]#}|                     |d         |z             |d<   $|d                             |           |dxx         |z  cc<   |dxx         ||z
  z  cc<   n|dxx         |z  cc<   |d	xx         |d	         z  cc<   |                     d
          }|rg|D ]d}|                                }	|d         |z   }
|                     |
          |	d<   | j	        |
         |	d<   |d
         
                    |	           et          |          }|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%   r1   r   )r8   r9   r;   r<   affectedrB   
n_upserteddocwrite_errorsreplacementr+   wces               r(   _merge_commandrS   H   s)    zz#q!!H
{gK   H,    			J8+			::j)) 	0XJ @ @"yyW)>??G
#**8444$$$
2$$$
###x*'<<####
###x/###K   F;$77   ::m,,L ; 	; 	;C((**Kg,'C#&99S>>K  #K&--k::::
v

C
 6()00555556 6r*   r   r   c                   | d         ri| d                              d            | d         d         }|d         }|d         }|dk    r(|                    d          rd	}t          |||           t          |           )
z5Raise a BulkWriteError from the full bulk api result.rF   c                    | d         S )Nr-   r7   )errors    r(   <lambda>z)_raise_bulk_write_error.<locals>.<lambda>x   s
    %. r*   )keyr   codeerrmsg   zTransaction numberszrThis MongoDB deployment does not support retryable writes. Please add retryWrites=false to your connection string.)sort
startswithr
   r	   )r9   errrY   msgrZ   s        r(   _raise_bulk_write_errorr`   t   s     =! >M"'',H,H'III-(+6{(m2::#..)>??:- 
 #64===

%
%%r*   N)
r8   r   r9   r:   r;   r   r<   r=   r!   r"   )r9   r   r!   r   )r6   
__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   rS   r`   r7   r*   r(   <module>rh      s    R Q Q " " " " " " H H H H H H H H H H H H H H ; ; ; ; ; ; ; ; / / / / / /           -,,,,,,          
             "@	 @ @ @ @# # # # # # # #8)6 )6 )6 )6X& & & & & &r*   