
    ]*i$                    6   d Z ddlmZ ddlmZmZmZ ddlmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ ddlmZmZ er2dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z#m$Z$ dZ% G d d      Z& G d de&      Z' G d de'      Z( G d de&      Z)y)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                      e Zd ZdZ	 	 	 	 d
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZedd       Zedd       ZddZedd       Z		 	 	 	 ddZ
	 	 	 	 	 	 	 	 	 	 dd	Zy)_AggregationCommandzThe 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	                   d|v rt        d      || _        t        j                  d|      }|| _        d| _        |rd|d   v sd|d   v rd| _        t        j                  d	|       |t        j                  d
|       ||d
<   |||d<   || _        t        j                  d| j                  j                  dd             | _
        | j                  j                  di        | j                  (| j
                  s| j                  | j                  d   d<   || _        || _        || _        t        |j                  dd             | _        |j                  dd       | _        d | _        y )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	            Y/home/alumno/antonio/venv/lib/python3.12/site-packages/pymongo/synchronous/aggregation.py__init__z_AggregationCommand.__init__/   sg    $T  ''
H=!$8B</8x|3K#'D ""9g6?&&uc2 GEN!(GI "GG**;=

 	  2. '0D0D373C3CDMM(#K0)'!14W[[d5ST")++.>"E:>    c                    t         )z.The argument to pass to the aggregate command.NotImplementedErrorr6   s    r;   _aggregation_targetz'_AggregationCommand._aggregation_targetf   
     "!r=   c                    t         )z4The namespace in which the aggregate command is run.r?   rA   s    r;   _cursor_namespacez%_AggregationCommand._cursor_namespacek   rC   r=   c                    t         5The Collection used for the aggregate command cursor.r?   )r6   
cursor_docs     r;   _cursor_collectionz&_AggregationCommand._cursor_collectionp   s    !!r=   c                    t         )z:The database against which the aggregation command is run.r?   rA   s    r;   	_databasez_AggregationCommand._databaset   rC   r=   c                    | j                   r| j                   S | j                  j                  |      }| j                  r%|t        j
                  k7  rt        |      x| _         }|S N)r5   r&   _read_preference_forr)   r   PRIMARYr   )r6   sessionprefs      r;   get_read_preferencez'_AggregationCommand.get_read_preferencey   sZ     !!)))||009DN,B,B$B,9$,??D"Tr=   c                   | j                   | j                  d}|j                  | j                         d|vr2| j                  r|j
                  dk\  r| j                  j                  }nd }d|vr(| j                  r| j                  j                  |      }nd }|j                  | j                  j                  ||| j                  j                  d||| j                  || j                  j                  | j                        }| j                   r| j!                  ||       d|v r|d   }	n d|j#                  d	g       | j$                  d
}	| j'                  | j)                  |	      |	|j*                  | j,                  xs d| j.                  || j                  j#                  d            }
|
j1                  |       |
S )N)	aggregater   readConcern   writeConcernT)parse_write_concern_errorread_concernwrite_concernr$   rQ   clientr9   r#   r   result)id
firstBatchnsr!   )
batch_sizemax_await_time_msrQ   r!   )rB   r(   updater+   r)   max_wire_versionr&   rZ   _write_concern_forcommandrL   namecodec_optionsr3   r\   r1   r2   getrE   r0   rJ   addressr.   r4   _maybe_pin_connection)r6   rQ   serverconnread_preferencecmdrZ   r[   r]   r#   
cmd_cursors              r;   
get_cursorz_AggregationCommand.get_cursor   s    !44$..Q

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

 	((.r=   )NNNN)r7   z%Union[Database[Any], Collection[Any]]r8   ztype[CommandCursor[Any]]r   r   r   zMutableMapping[str, Any]r    zOptional[Mapping[str, Any]]r9   z"Optional[MutableMapping[str, Any]]r:   z9Optional[Callable[[Mapping[str, Any], Connection], None]]r!   r   returnNone)rr   zUnion[str, int]rr   str)rI   Mapping[str, Any]rr   Collection[Any]rr   Database[Any])rQ   Optional[ClientSession]rr   z!Union[_AggWritePref, _ServerMode])
rQ   rz   rl   r   rm   r   rn   r   rr   zCommandCursor[_DocumentType])__name__
__module____qualname____doc__r<   propertyrB   rE   rJ   rL   rS   rq    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                  V    e Zd ZU ded<   edd       Zedd       Zd	dZed
d       Zy)_CollectionAggregationCommandrw   r&   c                .    | j                   j                  S rN   r&   rg   rA   s    r;   rB   z1_CollectionAggregationCommand._aggregation_target   s    ||   r=   c                .    | j                   j                  S rN   )r&   	full_namerA   s    r;   rE   z/_CollectionAggregationCommand._cursor_namespace   s    ||%%%r=   c                    | j                   S rG   r&   )r6   r#   s     r;   rJ   z0_CollectionAggregationCommand._cursor_collection       ||r=   c                .    | j                   j                  S rN   )r&   databaserA   s    r;   rL   z'_CollectionAggregationCommand._database   s    ||$$$r=   Nrt   r#   rv   rr   rw   rx   )	r{   r|   r}   __annotations__r   rB   rE   rJ   rL   r   r=   r;   r   r      sG    ! ! & & % %r=   r   c                        e Zd Zd fdZ xZS ) _CollectionRawAggregationCommandc                b    t        |   |i | | j                  sd| j                  d   d<   y y )Nr   r#   r"   )superr<   r)   r+   )r6   argskwargs	__class__s      r;   r<   z)_CollectionRawAggregationCommand.__init__   s8    $)&) ##34DMM(#K0 $r=   )r   r   r   r   rr   rs   )r{   r|   r}   r<   __classcell__)r   s   @r;   r   r      s    5 5r=   r   c                  V    e Zd ZU ded<   edd       Zed	d       Zed
d       ZddZy)_DatabaseAggregationCommandry   r&   c                     y)N   r   rA   s    r;   rB   z/_DatabaseAggregationCommand._aggregation_target   s    r=   c                4    | j                   j                   dS )Nz.$cmd.aggregater   rA   s    r;   rE   z-_DatabaseAggregationCommand._cursor_namespace   s    ,,##$O44r=   c                    | j                   S rN   r   rA   s    r;   rL   z%_DatabaseAggregationCommand._database   r   r=   c                ~    |j                  d| j                        j                  dd      \  }}| j                  |   S )rH   r`   .r   )ri   rE   splitrL   )r6   r#   _collnames       r;   rJ   z._DatabaseAggregationCommand._cursor_collection   s:    
 jjt'='=>DDS!L8~~h''r=   N)rr   intrt   rx   r   )	r{   r|   r}   r   r   rB   rE   rL   rJ   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=   