o
    'h%                     @  s  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rld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 dZ&G dd de&Z'G dd de'Z(G dd de&Z)dS )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)AsyncClientSession)AsyncCollection)AsyncCommandCursor)AsyncDatabase)AsyncConnection)Server)_ServerMode)_DocumentType	_PipelineFc                   @  sl   e Zd ZdZ				d5d6ddZed7ddZed8ddZd9d"d#Zed:d%d&Z	d;d*d+Z
d<d3d4ZdS )=_AggregationCommanda  The internal abstract base class for aggregation cursors.

    Should not be called directly by application developers. Use
    :meth:`pymongo.asynchronous.collection.AsyncCollection.aggregate`, or
    :meth:`pymongo.asynchronous.database.AsyncDatabase.aggregate` instead.
    Ntarget%Union[AsyncDatabase, AsyncCollection]cursor_classtype[AsyncCommandCursor]pipeliner   optionsMutableMapping[str, Any]explicit_sessionboolletOptional[Mapping[str, Any]]user_fields"Optional[MutableMapping[str, Any]]result_processor>Optional[Callable[[Mapping[str, Any], AsyncConnection], None]]commentr   returnNonec
           
      C  s  d|v rt d|| _td|}|| _d| _|r(d|d v s%d|d v r(d| _td	| |d ur<td
| ||d
< |	d urD|	|d< || _td| j	dd | _
| jdi  | j
d urj| jsj| j
| jd d< || _|| _|| _|| _t|	dd | _|	dd | _d | _d S )NexplainzGThe explain option is not supported. Use AsyncDatabase.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(    rC   \/var/www/html/olx_land/venv/lib/python3.10/site-packages/pymongo/asynchronous/aggregation.py__init__/   s<   
z_AggregationCommand.__init__Union[str, int]c                 C     t )z.The argument to pass to the aggregate command.NotImplementedErrorrB   rC   rC   rD   _aggregation_targeth      z'_AggregationCommand._aggregation_targetstrc                 C  rG   )z4The namespace in which the aggregate command is run.rH   rJ   rC   rC   rD   _cursor_namespacem   rL   z%_AggregationCommand._cursor_namespace
cursor_docMapping[str, Any]r   c                 C  rG   :The AsyncCollection used for the aggregate command cursor.rH   )rB   rO   rC   rC   rD   _cursor_collectionr      z&_AggregationCommand._cursor_collectionr   c                 C  rG   )z:The database against which the aggregation command is run.rH   rJ   rC   rC   rD   	_databasev   rL   z_AggregationCommand._databasesessionOptional[AsyncClientSession]!Union[_AggWritePref, _ServerMode]c                 C  s:   | j r| j S | j|}| jr|tjkrt| | _ }|S N)rA   r1   _read_preference_forr4   r   PRIMARYr   )rB   rV   prefrC   rC   rD   get_read_preference{   s   z'_AggregationCommand.get_read_preferenceserverr   connr   read_preferencer   !AsyncCommandCursor[_DocumentType]c                   s  | j | jd}|| 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jd||| j|| j
j| jdI d H }| jrU| || d|v r^|d }	nd|d	g | jd
}	| j| |	|	|j| jpvd| j|| j| jdd}
|
|I d H  |
S )N)	aggregater   readConcern   writeConcernT)parse_write_concern_errorread_concernwrite_concernr/   rV   clientr$   r.   r   result)id
firstBatchnsr(   )
batch_sizemax_await_time_msrV   r    r(   )rK   r3   updater6   r4   max_wire_versionr1   rg   _write_concern_forcommandrU   namecodec_optionsr?   ri   r=   r>   getrN   r;   rS   addressr9   r@   r<   _maybe_pin_connection)rB   rV   r^   r_   r`   cmdrg   rh   rj   r.   
cmd_cursorrC   rC   rD   
get_cursor   sZ   





z_AggregationCommand.get_cursor)NNNN)r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r   r)   r*   )r)   rF   r)   rM   )rO   rP   r)   r   r)   r   )rV   rW   r)   rX   )
rV   rW   r^   r   r_   r   r`   r   r)   ra   )__name__
__module____qualname____doc__rE   propertyrK   rN   rS   rU   r]   r{   rC   rC   rC   rD   r   '   s     9


r   c                   @  sJ   e Zd ZU ded< edddZedddZdddZedddZdS )_CollectionAggregationCommandr   r1   r)   rM   c                 C     | j jS rY   r1   rt   rJ   rC   rC   rD   rK         z1_CollectionAggregationCommand._aggregation_targetc                 C  r   rY   )r1   	full_namerJ   rC   rC   rD   rN      r   z/_CollectionAggregationCommand._cursor_namespacer.   rP   c                 C     | j S rQ   r1   )rB   r.   rC   rC   rD   rS         z0_CollectionAggregationCommand._cursor_collectionr   c                 C  r   rY   )r1   databaserJ   rC   rC   rD   rU      r   z'_CollectionAggregationCommand._databaseNr|   r.   rP   r)   r   r}   )	r~   r   r   __annotations__r   rK   rN   rS   rU   rC   rC   rC   rD   r      s   
 
r   c                      s   e Zd Zd fddZ  ZS )	 _CollectionRawAggregationCommandargsr   kwargsr)   r*   c                   s.   t  j|i | | jsd| jd d< d S d S )Nr   r.   r-   )superrE   r4   r6   )rB   r   r   	__class__rC   rD   rE      s   z)_CollectionRawAggregationCommand.__init__)r   r   r   r   r)   r*   )r~   r   r   rE   __classcell__rC   rC   r   rD   r      s    r   c                   @  sJ   e Zd ZU ded< edddZeddd	Zedd
dZdddZdS )_DatabaseAggregationCommandr   r1   r)   intc                 C  s   dS )N   rC   rJ   rC   rC   rD   rK      rT   z/_DatabaseAggregationCommand._aggregation_targetrM   c                 C  s   | j j dS )Nz.$cmd.aggregater   rJ   rC   rC   rD   rN      s   z-_DatabaseAggregationCommand._cursor_namespacec                 C  r   rY   r   rJ   rC   rC   rD   rU      r   z%_DatabaseAggregationCommand._databaser.   rP   r   c                 C  s$   | d| jdd\}}| j| S )rR   rm   .r   )rv   rN   splitrU   )rB   r.   _collnamerC   rC   rD   rS      s   
z._DatabaseAggregationCommand._cursor_collectionN)r)   r   r|   r}   r   )	r~   r   r   r   r   rK   rN   rU   rS   rC   rC   rC   rD   r      s   
 r   N)*r   
__future__r   collections.abcr   r   r   typingr   r   r   r	   pymongor
   pymongo.collationr   pymongo.errorsr   pymongo.read_preferencesr   r   #pymongo.asynchronous.client_sessionr   pymongo.asynchronous.collectionr   #pymongo.asynchronous.command_cursorr   pymongo.asynchronous.databaser   pymongo.asynchronous.poolr   pymongo.asynchronous.serverr   r   pymongo.typingsr   r   _IS_SYNCr   r   r   r   rC   rC   rC   rD   <module>   s.    )	