
    =h$                    >   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 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&  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)SON)common)validate_collation_or_none)ConfigurationError)ReadPreference_AggWritePref)ClientSession)
Collection)CommandCursor)Database)
Connection)_ServerMode)Server)_DocumentType	_Pipelinec                      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_explicit_session_user_fields_result_processorr   
_collation_max_await_time_ms_write_preference)
selftargetcursor_classr   r    explicit_sessionr!   user_fieldsresult_processorr"   s
             c/var/www/html/phonemate/phone_mate_backend/venv/lib/python3.12/site-packages/pymongo/aggregation.py__init__z_AggregationCommand.__init__.   so    $T  ''
H=!$8B</8x|3K#'D ""9g6?&&uc2 GEN!(GI "GG**;=

 	  2. '0D0D373C3CDMM(#K0)!1'!14W[[d5ST")++.>"E:>    c                    t         )z.The argument to pass to the aggregate command.NotImplementedErrorr8   s    r>   _aggregation_targetz'_AggregationCommand._aggregation_targetg   
     "!r@   c                    t         )z4The namespace in which the aggregate command is run.rB   rD   s    r>   _cursor_namespacez%_AggregationCommand._cursor_namespacel   rF   r@   c                    t         5The Collection used for the aggregate command cursor.rB   )r8   
cursor_docs     r>   _cursor_collectionz&_AggregationCommand._cursor_collectionq   s    !!r@   c                    t         )z:The database against which the aggregation command is run.rB   rD   s    r>   	_databasez_AggregationCommand._databaseu   rF   r@   c                    | j                   r| j                   S | j                  j                  |      }| j                  r%|t        j
                  k7  rt        |      x| _         }|S N)r7   r'   _read_preference_forr*   r   PRIMARYr   )r8   sessionprefs      r>   get_read_preferencez'_AggregationCommand.get_read_preferencez   sZ     !!)))||009DN,B,B$B,9$,??D"Tr@   c                   t        d| j                  fd| j                  fg      }|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	| j0                  || j2                  | j                  j%                  d            }
|
j5                  |       |
S )N	aggregater   readConcern   writeConcernT)parse_write_concern_errorread_concernwrite_concernr%   rT   clientr<   r$   r   result)id
firstBatchnsr"   )
batch_sizemax_await_time_msrT   r;   r"   )r   rE   r)   updater,   r*   max_wire_versionr'   r]   _write_concern_forcommandrO   namecodec_optionsr5   r_   r3   r4   getrH   r1   rM   addressr/   r6   r2   _maybe_pin_connection)r8   rT   serverconnread_preferencecmdr]   r^   r`   r$   
cmd_cursors              r>   
get_cursorz_AggregationCommand.get_cursor   s    K!9!9:Z<XYZ

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!33MM%%i0 ( 	

 	((.r@   )NNNN)r9   zUnion[Database, Collection]r:   ztype[CommandCursor]r   r   r    zMutableMapping[str, Any]r;   boolr!   zOptional[Mapping[str, Any]]r<   z"Optional[MutableMapping[str, Any]]r=   z9Optional[Callable[[Mapping[str, Any], Connection], None]]r"   r   returnNone)rv   zUnion[str, int]rv   str)rL   Mapping[str, Any]rv   r   rv   r   )rT   Optional[ClientSession]rv   z!Union[_AggWritePref, _ServerMode])
rT   r|   ro   r   rp   r   rq   r   rv   zCommandCursor[_DocumentType])__name__
__module____qualname____doc__r?   propertyrE   rH   rM   rO   rV   rt    r@   r>   r   r   &   s    ,0:>VZ7?+7? *7? 	7?
 *7? 7? )7? 87? T7? 7? 
7?r " " " "" " "	.		*	G(G G 	G
 %G 
&G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)_CollectionAggregationCommandr   r'   c                .    | j                   j                  S rQ   r'   rj   rD   s    r>   rE   z1_CollectionAggregationCommand._aggregation_target   s    ||   r@   c                .    | j                   j                  S rQ   )r'   	full_namerD   s    r>   rH   z/_CollectionAggregationCommand._cursor_namespace   s    ||%%%r@   c                    | j                   S rJ   r'   )r8   r$   s     r>   rM   z0_CollectionAggregationCommand._cursor_collection       ||r@   c                .    | j                   j                  S rQ   )r'   databaserD   s    r>   rO   z'_CollectionAggregationCommand._database   s    ||$$$r@   Nrx   r$   rz   rv   r   r{   )	r}   r~   r   __annotations__r   rE   rH   rM   rO   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,   )r8   argskwargs	__class__s      r>   r?   z)_CollectionRawAggregationCommand.__init__   s8    $)&) ##34DMM(#K0 $r@   )r   r   r   r   rv   rw   )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)_DatabaseAggregationCommandr   r'   c                     y)N   r   rD   s    r>   rE   z/_DatabaseAggregationCommand._aggregation_target   s    r@   c                4    | j                   j                   dS )Nz.$cmd.aggregater   rD   s    r>   rH   z-_DatabaseAggregationCommand._cursor_namespace   s    ,,##$O44r@   c                    | j                   S rQ   r   rD   s    r>   rO   z%_DatabaseAggregationCommand._database   r   r@   c                ~    |j                  d| j                        j                  dd      \  }}| j                  |   S )rK   rc   .r   )rl   rH   splitrO   )r8   r$   _collnames       r>   rM   z._DatabaseAggregationCommand._cursor_collection   s:    
 jjt'='=>DDS!L8~~h''r@   N)rv   intrx   r{   r   )	r}   r~   r   r   r   rE   rH   rO   rM   r   r@   r>   r   r      sG      5 5  (r@   r   N)+r   
__future__r   collections.abcr   r   r   typingr   r   r	   r
   bson.sonr   pymongor   pymongo.collationr   pymongo.errorsr   pymongo.read_preferencesr   r   pymongo.client_sessionr   pymongo.collectionr   pymongo.command_cursorr   pymongo.databaser   pymongo.poolr   r   pymongo.serverr   pymongo.typingsr   r   r   r   r   r   r   r@   r>   <module>r      sx    B " = = 6 6   8 - B4-4)'4%8f fR%$7 %(5'D 5("5 (r@   