
    h\"                         d 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
  G d de      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.    )SON)common)validate_collation_or_none)ConfigurationError)ReadPreferencec                   |    e Zd ZdZ	 ddZed        Zed        Zed        Zed        Z	e
d        Zd	 Zd
 Z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
| j                  j                  d
d             | _
        | j                  j                  di        | j                  (| j
                  s| j                  | j                  d   d
<   || _        || _        || _        || _        t!        |j                  dd             | _        |j                  dd       | _        y )NexplainzBThe explain option is not supported. Use Database.command instead.pipelineFz$outz$mergeToptions	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_explicit_session_user_fields_result_processorr   
_collation_max_await_time_ms)selftargetcursor_classr   r   explicit_sessionuser_fieldsresult_processors           V/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/pymongo/aggregation.py__init__z_AggregationCommand.__init__    s?   $ &E F F Z2!$8B</8x|3K#'D ""9g6 "GG**;=? 	  2. '0D0D373C3CDMM(#K0)!1'!14KKT*, #*++.>"E    c                     t         )z.The argument to pass to the aggregate command.NotImplementedErrorr#   s    r)   _aggregation_targetz'_AggregationCommand._aggregation_targetG   
     "!r+   c                     t         )z4The namespace in which the aggregate command is run.r-   r/   s    r)   _cursor_namespacez%_AggregationCommand._cursor_namespaceL   r1   r+   c                     t         5The Collection used for the aggregate command cursor.r-   )r#   
cursor_docs     r)   _cursor_collectionz&_AggregationCommand._cursor_collectionQ   r1   r+   c                     t         )z:The database against which the aggregation command is run.r-   r/   s    r)   	_databasez_AggregationCommand._databaseV   r1   r+   c                      y)z=Check whether the server version in-use supports aggregation.N )	sock_infos    r)   _check_compatz!_AggregationCommand._check_compat[   s     	r+   c                 H    | j                   r| j                  |||||       y y N)r    )r#   resultsessionserverr=   slave_oks         r)   _process_resultz#_AggregationCommand._process_result`   s)    !!""H> "r+   c                 p    | j                   rt        j                  S | j                  j	                  |      S r@   )r   r   PRIMARYr   _read_preference_for)r#   rB   s     r)   get_read_preferencez'_AggregationCommand.get_read_preferencee   s,    !)))||0099r+   c                    | j                  |       t        d| j                  fd| j                  fg      }|j	                  | j
                         d|vrA|j                  dk\  r| j                  r|j                  dk\  r| j                  j                  }nd }d|vr(| j                  r| j                  j                  |      }nd }|j                  | j                  j                  ||| j                  |      | j                  j                  d||| j                   || j                  j"                  | j$                        }| j'                  |||||       d	|v r|d	   }	n d
|j)                  dg       | j*                  d}	| j-                  | j/                  |	      |	|j0                  | j2                  xs d
| j4                  || j6                        S )N	aggregater   readConcern      writeConcernT)parse_write_concern_errorread_concernwrite_concernr   rB   clientr'   r   r   rA   )id
firstBatchns)
batch_sizemax_await_time_msrB   r&   )r>   r   r0   r   updater   max_wire_versionr   r   rQ   _write_concern_forcommandr:   namerI   codec_optionsr!   rS   r   rE   getr3   r   r8   addressr   r"   r   )
r#   rB   rC   r=   rD   cmdrQ   rR   rA   r   s
             r)   
get_cursorz_AggregationCommand.get_cursorj   s   9% K!9!9:/1 2

4==! #%,,1**,,1<<44LL
 $)=)= LL;;GDM M ""NN$$W-LL&&&*%'oo>>(()) # + 	VWfiJ vH%F $jj26,,F !!##F+VY5F5F'',1"55d.D.D	 " F 	Fr+   )NN)__name__
__module____qualname____doc__r*   propertyr0   r3   r8   r:   staticmethodr>   rE   rI   rb   r<   r+   r)   r	   r	      s     GK%FN " " " " " " " "  >
:
>Fr+   r	   c                   T     e Zd Z fdZed        Zed        Zd Zed        Z xZ	S )_CollectionAggregationCommandc                     |j                  dd      }t        t        |   |i | || _        | j                  s| j
                  j                  dd        y y )N
use_cursorTr   )r   superrj   r*   _use_cursorr   )r#   argskwargsrl   	__class__s       r)   r*   z&_CollectionAggregationCommand.__init__   sT    ZZd3
+T;TLVL &MMh-  r+   c                 .    | j                   j                  S r@   r   r]   r/   s    r)   r0   z1_CollectionAggregationCommand._aggregation_target   s    ||   r+   c                 .    | j                   j                  S r@   )r   	full_namer/   s    r)   r3   z/_CollectionAggregationCommand._cursor_namespace   s    ||%%%r+   c                     | j                   S r5   r   )r#   r   s     r)   r8   z0_CollectionAggregationCommand._cursor_collection       ||r+   c                 .    | j                   j                  S r@   )r   databaser/   s    r)   r:   z'_CollectionAggregationCommand._database   s    ||$$$r+   )
rc   rd   re   r*   rg   r0   r3   r8   r:   __classcell__rq   s   @r)   rj   rj      sI    . ! ! & & % %r+   rj   c                        e Zd Z fdZ xZS ) _CollectionRawAggregationCommandc                     t        t        | 
  |i | | j                  r | j                  sd| j
                  d   d<   y y y )Nr   r   r   )rm   r~   r*   rn   r   r   )r#   ro   rp   rq   s      r)   r*   z)_CollectionRawAggregationCommand.__init__   sF    .>OO D$8$834DMM(#K0 %9r+   )rc   rd   re   r*   r{   r|   s   @r)   r~   r~      s    5 5r+   r~   c                   R    e Zd Zed        Zed        Zed        Zd Zed        Z	y)_DatabaseAggregationCommandc                      y)N   r<   r/   s    r)   r0   z/_DatabaseAggregationCommand._aggregation_target   s    r+   c                 4    | j                   j                  dS )Nz.$cmd.aggregaters   r/   s    r)   r3   z-_DatabaseAggregationCommand._cursor_namespace   s    &*ll&7&799r+   c                     | j                   S r@   rw   r/   s    r)   r:   z%_DatabaseAggregationCommand._database   rx   r+   c                 ~    |j                  d| j                        j                  dd      \  }}| j                  |   S )r6   rV   .r   )r_   r3   splitr:   )r#   r   _collnames       r)   r8   z._DatabaseAggregationCommand._cursor_collection   s:    
 jjt'='=>DDS!L8~~h''r+   c                 <    | j                   dk\  sd}t        |      y )N   z7Database.aggregate() is only supported on MongoDB 3.6+.)rZ   r   )r=   err_msgs     r)   r>   z)_DatabaseAggregationCommand._check_compat   s'     ))Q.OG$W-- /r+   N)
rc   rd   re   rg   r0   r3   r:   r8   rh   r>   r<   r+   r)   r   r      sU      : :  ( . .r+   r   N)rf   bson.sonr   pymongor   pymongo.collationr   pymongo.errorsr   pymongo.read_preferencesr   objectr	   rj   r~   r   r<   r+   r)   <module>r      sR    B   8 - 3OF& OFd%$7 %85'D 5."5 .r+   