
    [j$                    X   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*dS )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d0d            Zed1d            Zd2dZed3d!            Z	d4d%Z
d5d-ZdS )6_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.
    NtargetUnion[Database, Collection]cursor_classtype[CommandCursor]pipeliner   optionsMutableMapping[str, Any]explicit_sessionboolletOptional[Mapping[str, Any]]user_fields"Optional[MutableMapping[str, Any]]result_processor9Optional[Callable[[Mapping[str, Any], Connection], None]]commentr   returnNonec
                   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        	                    dd                     | _
        | j                            di            | j
        | j        s| j
        | j        d         d<   || _        || _        || _        || _        t!          |	                    dd                     | _        |	                    dd           | _        d | _        d S )NexplainzBThe explain option is not supported. Use Database.command instead.r    Fz$outz$mergeTr!   r%   r+   	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)
selfr   r   r    r!   r#   r%   r'   r)   r+   s
             W/var/www/app.qaans.com/backend/venv/lib/python3.11/site-packages/pymongo/aggregation.py__init__z_AggregationCommand.__init__.   s    $T   '
H==!$ 	(8B<//8x|3K3K#'D "9g666?&uc222 GEN!(GI "G**;==
 

 	  2... '0D'373CDM(#K0)!1'!14W[[d5S5STT")++.>"E"E:>    Union[str, int]c                    t           )z.The argument to pass to the aggregate command.NotImplementedErrorrF   s    rG   _aggregation_targetz'_AggregationCommand._aggregation_targetg   
     "!rI   strc                    t           )z4The namespace in which the aggregate command is run.rL   rN   s    rG   _cursor_namespacez%_AggregationCommand._cursor_namespacel   rP   rI   
cursor_docMapping[str, Any]r   c                    t           5The Collection used for the aggregate command cursor.rL   )rF   rT   s     rG   _cursor_collectionz&_AggregationCommand._cursor_collectionq   s    !!rI   r   c                    t           )z:The database against which the aggregation command is run.rL   rN   s    rG   	_databasez_AggregationCommand._databaseu   rP   rI   sessionOptional[ClientSession]!Union[_AggWritePref, _ServerMode]c                    | j         r| j         S | j                            |          }| j        r&|t          j        k    rt          |          x| _         }|S N)rE   r5   _read_preference_forr8   r   PRIMARYr   )rF   r\   prefs      rG   get_read_preferencez'_AggregationCommand.get_read_preferencez   s`     ! 	*))|0099 	@DN,B$B$B,9$,?,??D"TrI   serverr   connr   read_preferencer   CommandCursor[_DocumentType]c                   t          d| j        fd| j        fg          }|                    | j                   d|vr| j        r|j        dk    r| j        j        }nd }d|vr"| j        r| j        	                    |          }nd }|
                    | j        j        ||| j        j        d||| j        || j        j        | j                  }| j        r|                     ||           d|v r	|d         }	nd	|                    d
g           | j        d}	|                     |                     |	          |	|j        | j        pd	| j        || j        | j                            d                    }
|
                    |           |
S )N	aggregater    readConcern   writeConcernT)parse_write_concern_errorread_concernwrite_concernr3   r\   clientr'   r2   r   result)id
firstBatchnsr+   )
batch_sizemax_await_time_msr\   r#   r+   )r   rO   r7   updater:   r8   max_wire_versionr5   ro   _write_concern_forcommandr[   namecodec_optionsrC   rq   rA   rB   getrS   r?   rY   addressr=   rD   r@   _maybe_pin_connection)rF   r\   re   rf   rg   cmdro   rp   rr   r2   
cmd_cursors              rG   
get_cursorz_AggregationCommand.get_cursor   s    K!9:Z<XYZZ

4=!!! $$$ %)-)>!)C)C<4LLL
 $$)=$ L;;GDDMM M NL&&*%'o>()  
 
 ! 	1""64000 vH%FF $jj266, F ''##F++L',1"5!3M%%i00 ( 	
 	

 	((...rI   )NNNN)r   r   r   r   r    r   r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r   r,   r-   )r,   rJ   r,   rQ   )rT   rU   r,   r   r,   r   )r\   r]   r,   r^   )
r\   r]   re   r   rf   r   rg   r   r,   rh   )__name__
__module____qualname____doc__rH   propertyrO   rS   rY   r[   rd   r    rI   rG   r   r   &   s          ,0:>VZ7? 7? 7? 7? 7?r " " " X" " " " X"" " " " " " " X"	 	 	 	G G G G G GrI   r   c                  j    e Zd ZU ded<   edd            Zedd            Zdd	Zedd            ZdS )_CollectionAggregationCommandr   r5   r,   rQ   c                    | j         j        S r`   r5   r|   rN   s    rG   rO   z1_CollectionAggregationCommand._aggregation_target   s    |  rI   c                    | j         j        S r`   )r5   	full_namerN   s    rG   rS   z/_CollectionAggregationCommand._cursor_namespace   s    |%%rI   r2   rU   c                    | j         S rW   r5   )rF   r2   s     rG   rY   z0_CollectionAggregationCommand._cursor_collection   
    |rI   r   c                    | j         j        S r`   )r5   databaserN   s    rG   r[   z'_CollectionAggregationCommand._database   s    |$$rI   Nr   r2   rU   r,   r   r   )	r   r   r   __annotations__r   rO   rS   rY   r[   r   rI   rG   r   r      s         ! ! ! X! & & & X&    % % % X% % %rI   r   c                        e Zd Zd fdZ xZS ) _CollectionRawAggregationCommandargsr   kwargsr,   r-   c                l     t                      j        |i | | j        sd| j        d         d<   d S d S )Nr   r2   r1   )superrH   r8   r:   )rF   r   r   	__class__s      rG   rH   z)_CollectionRawAggregationCommand.__init__   sM    $)&))) # 	534DM(#K000	5 	5rI   )r   r   r   r   r,   r-   )r   r   r   rH   __classcell__)r   s   @rG   r   r      s=        5 5 5 5 5 5 5 5 5 5rI   r   c                  j    e Zd ZU ded<   edd            Zedd            Zedd            ZddZdS )_DatabaseAggregationCommandr   r5   r,   intc                    dS )N   r   rN   s    rG   rO   z/_DatabaseAggregationCommand._aggregation_target   s    qrI   rQ   c                     | j         j         dS )Nz.$cmd.aggregater   rN   s    rG   rS   z-_DatabaseAggregationCommand._cursor_namespace   s    ,#4444rI   c                    | j         S r`   r   rN   s    rG   r[   z%_DatabaseAggregationCommand._database   r   rI   r2   rU   r   c                    |                     d| j                                      dd          \  }}| j        |         S )rX   ru   .r   )r~   rS   splitr[   )rF   r2   _collnames       rG   rY   z._DatabaseAggregationCommand._cursor_collection   s;    
 jjt'=>>DDS!LL8~h''rI   N)r,   r   r   r   r   )	r   r   r   r   r   rO   rS   r[   rY   r   rI   rG   r   r      s            X 5 5 5 X5    X( ( ( ( ( (rI   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   rI   rG   <module>r      s   B A " " " " " " = = = = = = = = = = 6 6 6 6 6 6 6 6 6 6 6 6             8 8 8 8 8 8 - - - - - - B B B B B B B B 9444444------444444))))))''''''444444%%%%%%88888888f f f f f f f fR% % % % %$7 % % %(5 5 5 5 5'D 5 5 5( ( ( ( ("5 ( ( ( ( (rI   