
    nh.                        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y)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y)	_Runz'Represents a batch of write operations.c                <    || _         g | _        g | _        d| _        y)zInitialize a new Run object.r   N)op_type	index_mapops
idx_offset)selfr!   s     y/var/www/html/SchoolMeal/SchoolMeal/pds_admin_SchoolMeal/Backend/venv/lib/python3.12/site-packages/pymongo/bulk_shared.py__init__z_Run.__init__/   s    #$&      c                     | 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%   idxs     r&   indexz
_Run.index6   s    
 ~~c""r(   c                p    | j                   j                  |       | j                  j                  |       y)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%   original_index	operations      r&   addz_Run.add=   s&     	n-	"r(   N)r!   r   returnNone)r*   r   r1   r   )r.   r   r/   r   r1   r2   )__name__
__module____qualname____doc__r'   r+   r0    r(   r&   r   r   ,   s    1!##r(   r   c                
   |j                  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|j                  d      }|r^t        |      }|D ]  }| j                  |d   |z         |d<    |d   j                  |       |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<   |j                  d
      }|rY|D ]T  }|j                         }	|d   |z   }
| j                  |
      |	d<   | j                  |
   |	d<   |d
   j                  |	       V t        |      }|r|d   j                  |       yy)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   )runfull_resultoffsetresultaffectedr<   
n_upserteddocwrite_errorsreplacementr*   wces               r&   _merge_commandrQ   H   s    zz#q!H
{{gK H, 		J8+		::j)XJ @"yyW)>?G@
#**84$
2$
#x*'<<#
#x/#K F;$77 ::m,L 	;C((*Kg,'C#&99S>K  #K&--k:	; v
C
()005 r(   c                    | d   rM| d   j                  d        | d   d   }|d   }|d   }|dk(  r |j                  d      rd	}t        |||       t        |       )
z5Raise a BulkWriteError from the full bulk api result.r@   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	   )rH   errrW   msgrX   s        r&   _raise_bulk_write_errorr^   t   s}     =!M"'',H'I-(+6{(m2:#..)>?- 
 #64==

%%r(   N)
rG   r   rH   zMutableMapping[str, Any]rI   r   rJ   zMapping[str, Any]r1   r2   )rH   r   r1   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   rQ   r^   r7   r(   r&   <module>rf      s     R " H H ; /  , S S  
C   c "@	 @# #8)6	)6))6 )6 	)6
 
)6X&r(   