
    i$                    @   S r SSKJr  SSKJrJrJr  SSKJrJ	r	J
r
Jr  SSKJr  SSKJr  SSKJr  SSKJrJr  \(       a2  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK J!r!  SSK"J#r#J$r$  Sr% " S S5      r& " S S\&5      r' " S S\'5      r( " S S\&5      r)g)z;Perform aggregation operations on a collection or database.    )annotations)CallableMappingMutableMapping)TYPE_CHECKINGAnyOptionalUnion)common)validate_collation_or_none)ConfigurationError)ReadPreference_AggWritePref)_ServerMode)ClientSession)
Collection)CommandCursor)Database)
Connection)Server)_DocumentType	_PipelineTc                      \ rS rSrSr    S                 SS jjr\SS j5       r\SS j5       rSS jr	\SS j5       r
    SS	 jr          SS
 jrSrg)_AggregationCommand'   zThe internal abstract base class for aggregation cursors.

Should not be called directly by application developers. Use
:meth:`pymongo.collection.Collection.aggregate`, or
:meth:`pymongo.database.Database.aggregate` instead.
Nc	                   SU;   a  [        S5      eXl        [        R                  " SU5      nX0l        SU l        U(       a  SUS   ;   d	  SUS   ;   a  SU l        [        R                  " S	U5        Ub  [        R                  " S
U5        XTS
'   Ub  XS'   X@l        [        R                  " SU R                  R                  SS 5      5      U l
        U R                  R                  S0 5        U R                  b-  U R
                  (       d  U R                  U R                  S   S'   X l        X`l        Xpl        [        UR                  SS 5      5      U l        UR                  SS 5      U l        S U l        g )NexplainzBThe explain option is not supported. Use Database.command instead.pipelineFz$outz$mergeToptionsletcomment	batchSizecursor	collationmaxAwaitTimeMS)r   _targetr   validate_list	_pipeline_performs_writevalidate_is_mapping_options%validate_non_negative_integer_or_nonepop_batch_size
setdefault_cursor_class_user_fields_result_processorr   
_collation_max_await_time_ms_write_preference)	selftargetcursor_classr   r    r!   user_fieldsresult_processorr"   s	            L/app/mltbenv/lib/python3.13/site-packages/pymongo/synchronous/aggregation.py__init___AggregationCommand.__init__/   sW    $T  ''
H=!$8B</8x|3K#'D ""9g6?&&uc2 EN!(I "GG**;=

 	  2. '0D0D373C3CDMM(#K0)'!14W[[d5ST")++.>"E:>    c                    [         e)z.The argument to pass to the aggregate command.NotImplementedErrorr7   s    r<   _aggregation_target'_AggregationCommand._aggregation_targetf   
     "!r?   c                    [         e)z4The namespace in which the aggregate command is run.rA   rC   s    r<   _cursor_namespace%_AggregationCommand._cursor_namespacek   rF   r?   c                    [         e5The Collection used for the aggregate command cursor.rA   )r7   
cursor_docs     r<   _cursor_collection&_AggregationCommand._cursor_collectionp   s    !!r?   c                    [         e)z:The database against which the aggregation command is run.rA   rC   s    r<   	_database_AggregationCommand._databaset   rF   r?   c                    U R                   (       a  U R                   $ U R                  R                  U5      nU R                  (       a&  U[        R
                  :w  a  [        U5      =U l         nU$ N)r6   r'   _read_preference_forr*   r   PRIMARYr   )r7   sessionprefs      r<   get_read_preference'_AggregationCommand.get_read_preferencey   sZ     !!)))||009DN,B,B$B,9$,??D"Tr?   c                   U R                   U R                  S.nUR                  U R                  5        SU;  a8  U R                  (       a  UR
                  S:  a  U R                  R                  nOS nSU;  a-  U R                  (       a  U R                  R                  U5      nOS nUR                  U R                  R                  UUU R                  R                  SUUU R                  UU R                  R                  U R                  S9nU R                   (       a  U R!                  X5        SU;   a  US   n	O SUR#                  S	/ 5      U R$                  S
.n	U R'                  U R)                  U	5      U	UR*                  U R,                  =(       d    SU R.                  UU R                  R#                  S5      S9n
U
R1                  U5        U
$ )N)	aggregater   readConcern   writeConcernT)parse_write_concern_errorread_concernwrite_concernr%   rW   clientr:   r$   r   result)id
firstBatchnsr"   )
batch_sizemax_await_time_msrW   r"   )rD   r)   updater,   r*   max_wire_versionr'   ra   _write_concern_forcommandrQ   namecodec_optionsr4   rc   r2   r3   getrH   r1   rN   addressr/   r5   _maybe_pin_connection)r7   rW   serverconnread_preferencecmdra   rb   rd   r$   
cmd_cursors              r<   
get_cursor_AggregationCommand.get_cursor   s    !44$..Q

4==! $$$)>)>!)C<<44LL
 $)=)= LL;;GDM M NNLL&&&*%'oo>>(())  
 !!""60 vH%F $jj26,,F ''##F+LL'',1"55MM%%i0 ( 

 	((.r?   )r/   r4   r1   r5   r,   r*   r)   r3   r'   r2   r6   )NNNN)r8   z%Union[Database[Any], Collection[Any]]r9   ztype[CommandCursor[Any]]r   r   r    zMutableMapping[str, Any]r!   zOptional[Mapping[str, Any]]r:   z"Optional[MutableMapping[str, Any]]r;   z9Optional[Callable[[Mapping[str, Any], Connection], None]]r"   r   returnNone)rz   zUnion[str, int]rz   str)rM   Mapping[str, Any]rz   Collection[Any]rz   Database[Any])rW   Optional[ClientSession]rz   z!Union[_AggWritePref, _ServerMode])
rW   r   rs   r   rt   r   ru   r   rz   zCommandCursor[_DocumentType])__name__
__module____qualname____firstlineno____doc__r=   propertyrD   rH   rN   rQ   rY   rx   __static_attributes__ r?   r<   r   r   '   s    ,0:>VZ5?55? /5? 	5?
 *5? )5? 85? T5? 5? 
5?n " " " "" " ".	*F(F F 	F
 %F 
&Fr?   r   c                  f    \ rS rSr% S\S'   \S
S j5       r\S
S j5       rSS jr\SS j5       r	Sr
g	)_CollectionAggregationCommand   r   r'   c                .    U R                   R                  $ rT   r'   rn   rC   s    r<   rD   1_CollectionAggregationCommand._aggregation_target   s    ||   r?   c                .    U R                   R                  $ rT   )r'   	full_namerC   s    r<   rH   /_CollectionAggregationCommand._cursor_namespace   s    ||%%%r?   c                    U R                   $ rK   r'   )r7   r$   s     r<   rN   0_CollectionAggregationCommand._cursor_collection       ||r?   c                .    U R                   R                  $ rT   )r'   databaserC   s    r<   rQ   '_CollectionAggregationCommand._database   s    ||$$$r?   r   Nr|   r$   r~   rz   r   r   )r   r   r   r   __annotations__r   rD   rH   rN   rQ   r   r   r?   r<   r   r      sG    ! ! & & % %r?   r   c                  ,   ^  \ rS rSrSU 4S jjrSrU =r$ ) _CollectionRawAggregationCommand   c                n   > [         TU ]  " U0 UD6  U R                  (       d  SU R                  S   S'   g g )Nr   r$   r#   )superr=   r*   r,   )r7   argskwargs	__class__s      r<   r=   )_CollectionRawAggregationCommand.__init__   s8    $)&) ##34DMM(#K0 $r?   r   )r   r   r   r   rz   r{   )r   r   r   r   r=   r   __classcell__)r   s   @r<   r   r      s    5 5r?   r   c                  f    \ rS rSr% S\S'   \S
S j5       r\SS j5       r\SS j5       rSS jr	Sr
g	)_DatabaseAggregationCommand   r   r'   c                    g)N   r   rC   s    r<   rD   /_DatabaseAggregationCommand._aggregation_target   s    r?   c                4    U R                   R                   S3$ )Nz.$cmd.aggregater   rC   s    r<   rH   -_DatabaseAggregationCommand._cursor_namespace   s    ,,##$O44r?   c                    U R                   $ rT   r   rC   s    r<   rQ   %_DatabaseAggregationCommand._database   r   r?   c                |    UR                  SU R                  5      R                  SS5      u  p#U R                  U   $ )rL   rg   .r   )rp   rH   splitrQ   )r7   r$   _collnames       r<   rN   ._DatabaseAggregationCommand._cursor_collection   s8    
 jjt'='=>DDS!L~~h''r?   r   N)rz   intr|   r   r   )r   r   r   r   r   r   rD   rH   rQ   rN   r   r   r?   r<   r   r      sG      5 5  (r?   r   N)*r   
__future__r   collections.abcr   r   r   typingr   r   r	   r
   pymongor   pymongo.collationr   pymongo.errorsr   pymongo.read_preferencesr   r   r   "pymongo.synchronous.client_sessionr   pymongo.synchronous.collectionr   "pymongo.synchronous.command_cursorr   pymongo.synchronous.databaser   pymongo.synchronous.poolr   pymongo.synchronous.serverr   pymongo.typingsr   r   _IS_SYNCr   r   r   r   r   r?   r<   <module>r      sz    B " = = 6 6  8 - B4@9@5318b bJ%$7 %(5'D 5("5 (r?   