+\h5xdZddlmZddlZddlZddlZddlmZddlm Z ddl m Z m Z m Z mZmZmZddlmZddlmZdd lmZmZdd lmZmZdd lmZdd lmZdd lm Z ddl!m"Z"e r ddl#m$Z$ddl%m&Z&ddl'm(Z(m)Z)ddl*m+Z+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4ddl5m6Z6ddl7m8Z8m9Z9m:Z:ddl;mZ>m?Z?m@Z@ddlAmBZBddlCmDZDmEZEmFZFmGZGddlHmIZImJZJddlKmLZLdZMGddZNy)zIThe client-level bulk write operations interface. .. versionadded:: 4.9 ) annotationsN)MutableMapping)islice) TYPE_CHECKINGAnyMappingOptionalTypeUnion)ObjectId)RawBSONDocument)_csotcommon)AsyncClientSession_validate_session_write_concern)AsyncCollection)AsyncCommandCursor) AsyncDatabase)_handle_reauth)AsyncMongoClient)AsyncConnection)_merge_command"_throw_client_bulk_write_exception)validate_is_document_typevalidate_ok_for_replacevalidate_ok_for_update)ConfigurationErrorConnectionFailureInvalidOperationNotPrimaryErrorOperationFailureWaitQueueTimeoutError)_RETRYABLE_ERROR_CODES)_COMMAND_LOGGER_CommandStatusMessage _debug_log)_ClientBulkWriteContext_convert_client_bulk_exception_convert_exception_convert_write_result_randint)ReadPreference)ClientBulkWriteResult DeleteResultInsertOneResult UpdateResult) _DocumentOut _Pipeline) WriteConcernFc eZdZdZ d ddZeddZddZ d ddZ d ddZ d ddZ e dd Z dd Z dd Z d d Z d!d Z d" d#dZ d$dZ d%dZ d%dZ d&dZy)'_AsyncClientBulkz4The private guts of the client-level bulk write API.Nc||_||_||_|j tjd|j||_||_||_||_g|_ g|_ d|_ d|_ d|_ d|_d|_|jj j"|_d|_d|_y)z'Initialize a _AsyncClientBulk instance.NletrF)client write_concernr7rrorderedbypass_doc_valcommentverbose_resultsops namespaces idx_offset total_opsexecuteduses_collationuses_array_filtersoptions retry_writes is_retryableretryingstarted_retryable_write)selfr8r9r:bypass_document_validationr<r7r=s c/root/niggaflix-v3/playground/venv/lib/python3.12/site-packages/pymongo/asynchronous/client_bulk.py__init__z_AsyncClientBulk.__init__Ys * 88   , ,UDHH = 8 .8:%'  #"' KK//<< ',$ctSN)r')rJs rLbulk_ctx_classz_AsyncClientBulk.bulk_ctx_classxs&&rNctd|t|tsd|vs t|d<d|d}|jj d|f|j j ||xjdz c_y)z*Add an insert document to the list of ops.document_id)insertrSrVN)r isinstancer r r>appendr?rA)rJ namespacerScmds rL add_insertz_AsyncClientBulk.add_insert|sf!*h78_5(9J&jHUO2 3( y) !rNc 6t|d|||d} ||| d<| d|_|| d<||| d<| d|_|| d<| | | d <|rd |_|jj d | f|j j ||xjd z c_y) z8Create an update document and add it to the list of ops.rUupdatefilter updateModsmultiNupsertT arrayFiltershint collationsortFr_rW)rrDrCrGr>rYr?rA) rJrZselectorr_rbrcrf array_filtersrergr[s rL add_updatez_AsyncClientBulk.add_updates v&     "CM  $&*D #"/C   CK  "&D (C   CK  %D  3( y) !rNct|d||dd}|||d<|||d<| d|_||d<|||d <|jjd |f|jj||xj d z c_y) z8Create a replace document and add it to the list of ops.rUFr^NrcreTrfrgreplacerW)rrCr>rYr?rA) rJrZrh replacementrcrfrergr[s rL add_replacez_AsyncClientBulk.add_replaces ,%    "CM  CK  "&D (C   CK C() y) !rNcd||d}|||d<| d|_||d<|rd|_|jjd|f|jj||xj d z c_y) z7Create a delete document and add it to the list of ops.rU)deleter`rbNreTrfFrprW)rCrGr>rYr?rA)rJrZrhrbrfrer[s rL add_deletez_AsyncClientBulk.add_deletesvx%@  CK  "&D (C   %D  3( y) !rNcb K||d<||d<tjtjrt tt j |jj|tt||j|||jj|jj|jjd|jjd|jj  |j"r|j%|||| |jj'|||j(d{}t*j*j-|j.z } tjtjrt tt j0|jj| |tt||j|||jj|jj|jjd|jjd|jj |j"r|j3||| |j4j7||j8d{|S7g7 #t:$r} t*j*j-|j.z } t=| t>t@fr | jB} n tE| } tjtjrt tt jF|jj| | tt||j|||jj|jj|jjd|jjd|jj t=| t@|j"r|jI|| | d | i}t=| t@r:|j4j7| jB|j8d{7n/|j4j7i|j8d{7Yd} ~ |Sd} ~ wwxYww) zHA proxy for AsyncConnection.write_command that handles event publishing.r>nsInforrW messageclientIdcommand commandName databaseName requestId operationIddriverConnectionIdserverConnectionId serverHost serverPort serviceIdN rurv durationMSreplyrxryrzr{r|r}r~rrrurvrfailurerxryrzr{r|r}r~rrisServerSideErrorerror)%r$ isEnabledForloggingDEBUGr&r%STARTED_topology_settings _topology_idnextiterdb_nameconnidserver_connection_idaddress service_idpublish_start write_commandcodecdatetimenow start_time SUCCEEDED_succeedr8_process_responsesession ExceptionrXr r!detailsr)FAILED_fail) rJbwcr[ request_idmsgop_docsns_docsr8rdurationexcrs rLrz_AsyncClientBulk.write_commandseE H  ' ' 6 -5522?? cO [[$&#&88;;#&88#@#@88++A.88++A.((--  ;; JJsJ 99 E((00S#))LLE((,,.?H++GMM:#1;;#66CC' $T#Y!$( *'*xx{{'*xx'D'D"xx//2"xx//2!hh11 {{ Z9++//s{{C C CF sM, D! E((,,.?H#1ABC(+ ,S1++GMM:#188#66CC'# $T#Y!$( *'*xx{{'*xx'D'D"xx//2"xx//2!hh11&06F&G${{ *gx8cNE#/0kk33CKKMMMkk33B DDD E! EsnDR/*J+?J&EJ+J) J+$R/&J+)J++ R,5F6R'+Q.,/R'RR'!R/'R,,R/cKtjtjrt tt j |jj|tt||j|||jj|jj|jjd|jjd|jj  |j"r|j%||||} |jj'||j(d{}t*j*j-|j.z } |t1|j2||} nddi} tjtjrt tt j4|jj| | tt||j|||jj|jj|jjd|jjd|jj |j"r|j7|| | | S7W#t8$r} t*j*j-|j.z } t;| t<r"t1|j2|| j>} n(t;| t@r | j>} n tC| } tjtjrt tt jD|jj| | tt||j|||jj|jj|jjd|jjd|jj t;| t<|j"r!|j.J|jG|| | d| i} Yd} ~ | Sd} ~ wwxYww) zFA proxy for AsyncConnection.unack_write that handles event publishing.rrWrtNokrrr)$r$rrrr&r%rrrrrrrrrrrrr unack_write max_bson_sizerrrr*namerrrrXr!rr r)rr) rJrr[rrrrr8resultrrrrs rLrz_AsyncClientBulk.unack_write?s0  ' ' 6 -5522?? cO [[$&#&88;;#&88#@#@88++A.88++A.((--  ;;**S*gw?C9 #88//S5F5FGGF((,,.?H!-chhVDq "// >' 5 ? ?!'!:!:!G!G#+#$(cO%([[",$.+.88;;+.88+H+H#&88#3#3A#6#&88#3#3A#6"%(("5"5 {{ Z9@ sH4 #((,,.?H#/0(=chhS[[(YC1++,S1++GMM:#188#66CC'# $T#Y!$( *'*xx{{'*xx'D'D"xx//2"xx//2!hh11&06F&G"{{~~111 *gx8cNE ? #sDDQ )J4J 5EJ Q J QF-Q Q QQc K|j|||\}}}}|j|||||||jd{||fS7w)z6Executes a batch of bulkWrite server commands (unack).N) batch_commandrr8) rJrr[r>r?rr to_send_ops to_send_nss rL_execute_batch_unackz%_AsyncClientBulk._execute_batch_unacks]473D3DS#z3Z0 CjsCS+zSWS^S^___J&& `s=A A A c K|j|||\}}}}|j|||||||jd{} | ||fS7 w)z4Executes a batch of bulkWrite server commands (ack).N)rrr8) rJrr[r>r?rrrrrs rL_execute_batchz_AsyncClientBulk._execute_batchsa473D3DS#z3Z0 Cj)) j#{J   {J.. s=A A  A cK|jdrtt|jdd}t ||d|j ||du|j }|j|d{ |23d{}|d|jz}|j|\} } |ds"|d j||jry|dsZ|jsg| d k(r| d d } t| d } | dvrd} t|d d } | dk(r t|d }  || d|<y776y#t $r=} |j"r|j%d{7t'| |d<Yd} ~ yd} ~ wwxYww)z?Internal helper for processing the server reply command cursor.cursoradminz$cmd.bulkWrite)databaserN)rexplicit_sessionr<idxr writeErrorsrVrSrTT) acknowledged)r_rlr_)rin_client_bulkrpResultsr)getrrr8rrr<_maybe_pin_connectionr@r>rYr:r=r/r0r.ralivecloser()rJ full_resultrrrcoll cmd_cursordocoriginal_indexop_typeop inserted_idresrs rL_process_results_cursorz(_AsyncClientBulk._process_results_cursors ::h "&t{{G<%D,x  !(!4 J2248 8 8 F!+OO#%(Z$//%AN"&((>":KGRt9}-44S9<<"4yT%9%9"h.*,Z.*?K"1+D"QC"&;;&.G".sVZ"[C"h.".s"FCKN wiw$78HI  9O( F##$**,,,"@"Ew  FsA2E?4D05E?:D6<D4D2D4A D6E?D6 D6#A D6/E?2D44D65E?6 E<?E7E!E72E?7E<<E?c  Kd}d} |jj} |j|j||j|| ||| ||jj} |j |j krw|j |j z | jkr|xs|}ddi} |j | d<|j| d<|xr |j } | s|stj| ||j|j| d<|jr|j| d<|jr|j| d <|rG|r#|j s|j#d |_|j%| |t&j(||j+| ||j|j-| |j/|j| t1|j2|j d}t1|j4|j d}|j6rZ|j9| | ||d{\}}}|}|j;d r|d }t=|d xr>t?|j@tBxr"|j@j;d dtDv}t?|tFxrt?|tHtJf }|rR|s|rNtMjN|}tQ|j2|j ||tS||jn8tQ|j2|j ||tS||jd|d <g|d<|j;ddtU|krd |d<|ds(||d <tQ|j2|j ||y|rw|j;di}|j;d dtDvrMtMjN|}tQ|j2|j ||tS||j|jW||||d{tQ|j2|j ||d|_,d|_n|j[| | ||d{\}}|xj tU|z c_|d s|jr|dry|j |j krvyy777^w)zr?rrrhasattrrXrdictr#rr r"copydeepcopyrrlenrrHr)rJr9rrop_id retryablerfinal_write_concernrcmd_name listenersrr[not_in_transactionr>r? raw_resultr_rrretryable_top_level_errorretryable_network_errorfullwces rL_execute_commandz!_AsyncClientBulk._execute_commandssKK00  dkk73!!       KK % % oo.~~/33K3KK 3 D} "C$($8$8 8C !\\C N!(!G1G1G-G !))#}="".262E2E./||!%Ixx!XXE T%A%A22437D0!!#y.2H2H$O  " "3 =    $   t{{C 04??D9C$GJ))373F3FsCQTV`3a-a* K#::g&"7OEy1S&u}}d;S!MM--fa8>37K0d|&0F7O"488T__k6R **%8"=Cwwvq)-CC $}}[9&txx$O:4AUAUV22;gVVVtxx+vN!& /4,(,'@'@c3PZ'[![ Q OOs;/ /O7# ]9SIoo.H.b^W"\s?IS=S6H S=S9A S=S;AS=4S=9S=;S=c Kddggdddddiiid t d fd }jjj|||d{ds dsd rt j S7+w) z'Execute commands with w=1 WriteConcern.FNr) rrrwriteConcernErrors nInserted nUpsertednMatched nModifiednDeleted insertResults updateResults deleteResultscK|jdkr tdjj|||d{y7w)N.retryable_bulk~sY $$r)&R''""   s>A AA )bulk operation_idrrr)rOptional[AsyncClientSession]rrrboolreturnNone)r+r8_retryable_writerGrr=)rJr operationrrrs` @@rLexecute_commandz _AsyncClientBulk.execute_commandhs#"$ 1   1 !    $kk**       +    w ;}#=MaAb .{Dr?rr) rJrrrrrrr[r>r?rrs rLexecute_command_unackz&_AsyncClientBulk.execute_command_unacks] KK00  !!       KK % % oo."C $C "C N"".262E2E./#&(C ||!%Ixx!XXE    $4??D9C$GJ$(#<#F=FcK|jr td|jr td|j t d|j |d{S7w)z3Execute all operations, returning no results (w=0).z3Collation is unsupported for unacknowledged writes.z6arrayFilters is unsupported for unacknowledged writes.NzGCannot set bypass_document_validation with unacknowledged write concern)rCrrDr;r!r)rJrs rLexecute_no_resultsz#_AsyncClientBulk.execute_no_resultssg   $%Z[ [  " "$%]^ ^    *"Y //5555sAA#A!A#cK|js td|jr tdd|_t||j}|jj s~|j j||d{4d{}|jdkr td|j|d{tdddcdddd{S|j||d{}t||jj |jS777k7P#1d{7swY_xYw7Lw)zExecute operations.zNo operations to executez*Bulk operations can only be executed once.TNrrF) r>rrBrr9rr8_conn_for_writesrrr-rr=)rJrr  connectionrs rLexecutez_AsyncClientBulk.executesA xx"#=> > =="#OP P 1'4;M;MN!!..![[99'9MM A AQ[..3*V--j999,T5%@  A A A++GY??$     + +    N A :  A A A A@sxBED'E D) E/D/?D+D/ ED-E7E80E)E+D/-E/E5D8 6E=E)TNNNF)r8rr9r3r:r rKOptional[bool]r<z Optional[str]r7z Optional[Any]r=r r r )r zType[_ClientBulkWriteContext])rZstrrSr1r r )NNNNN)rZrrhMapping[str, Any]r_z#Union[Mapping[str, Any], _Pipeline]rbr rcrrfOptional[Mapping[str, Any]]riz!Optional[list[Mapping[str, Any]]]re Union[str, dict[str, Any], None]rgrr r )NNNN)rZrrhrrmrrcrrfrrerrgrr r )NN) rZrrhrrbr rfrrerr r )rr'r[MutableMapping[str, Any]rintrzUnion[bytes, dict[str, Any]]rlist[Mapping[str, Any]]rr r8rr dict[str, Any])rr'r[rrrrbytesrr rr r8rr r) rr'r[r!r>#list[tuple[str, Mapping[str, Any]]]r? list[str]r z7tuple[list[Mapping[str, Any]], list[Mapping[str, Any]]]) rr'r[r!r>r#r?r$r zGtuple[dict[str, Any], list[Mapping[str, Any]], list[Mapping[str, Any]]]) rrrrrrrrr r rP)r9r3rrrrrrrr rrrzOptional[WriteConcern]r r )rrr rr r)rrr r )rrr rr r)__name__ __module__ __qualname____doc__rMpropertyrQr\rjrnrqrrrrrrrrrrrrNrLr5r5Vs> 59!%! %- -$- - %3 -  --- ->'' ""&15;?15,0%%$%4 %  %  %/%9%/%*% %X"&1515,0$'    / /* H2615 $  /  /  ,Y $Y&Y Y * Y ) Y)Y!Y YYvW $W&W W  W ) W)W!W %Wr ' $ ' '1 '  ' A ' / $ / /1 /  / Q /1F-1F)1F 1F . 1F  1Fv7;A#A.A A  A  A.A4A AF3-33 " 3j(0(0 (0T66 6" -    rNr5)Or( __future__rrrrcollections.abcr itertoolsrtypingrrrr r r bson.objectidr bson.raw_bsonr pymongorr#pymongo.asynchronous.client_sessionrrpymongo.asynchronous.collectionr#pymongo.asynchronous.command_cursorrpymongo.asynchronous.databaserpymongo.asynchronous.helpersr!pymongo.asynchronous.mongo_clientrpymongo.asynchronous.poolrpymongo._client_bulk_sharedrrpymongo.commonrrrpymongo.errorsrrrr r!r"pymongo.helpers_sharedr#pymongo.loggerr$r%r&pymongo.messager'r(r)r*r+pymongo.read_preferencesr,pymongo.resultsr-r.r/r0pymongo.typingsr1r2pymongo.write_concernr3_IS_SYNCr5r*rNrLrDs# *#)!c;B77B9 :MM4 4. ]  ]  rN