
    FCfu$                    2   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$  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)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
             S/var/www/highfloat_scraper/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r7   s    r=   _aggregation_targetz'_AggregationCommand._aggregation_targetf   
     "!r?   c                    t         )z4The namespace in which the aggregate command is run.rA   rC   s    r=   _cursor_namespacez%_AggregationCommand._cursor_namespacek   rE   r?   c                    t         5The Collection used for the aggregate command cursor.rA   )r7   
cursor_docs     r=   _cursor_collectionz&_AggregationCommand._cursor_collectionp   s    !!r?   c                    t         )z:The database against which the aggregation command is run.rA   rC   s    r=   	_databasez_AggregationCommand._databaset   rE   r?   c                    | j                   r| j                   S | j                  j                  |      }| j                  r%|t        j
                  k7  rt        |      x| _         }|S N)r6   r&   _read_preference_forr)   r   PRIMARYr   )r7   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.                  || j0                  | j                  j#                  d            }
|
j3                  |       |
S )N)	aggregater   readConcern   writeConcernT)parse_write_concern_errorread_concernwrite_concernr$   rS   clientr;   r#   r   result)id
firstBatchnsr!   )
batch_sizemax_await_time_msrS   r:   r!   )rD   r(   updater+   r)   max_wire_versionr&   r\   _write_concern_forcommandrN   namecodec_optionsr4   r^   r2   r3   getrG   r0   rL   addressr.   r5   r1   _maybe_pin_connection)r7   rS   serverconnread_preferencecmdr\   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!33MM%%i0 ( 	

 	((.r?   )NNNN)r8   zUnion[Database, Collection]r9   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)ru   zUnion[str, int]ru   str)rK   Mapping[str, Any]ru   r   ru   r   )rS   Optional[ClientSession]ru   z!Union[_AggWritePref, _ServerMode])
rS   r{   rn   r   ro   r   rp   r   ru   zCommandCursor[_DocumentType])__name__
__module____qualname____doc__r>   propertyrD   rG   rL   rN   rU   rs    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 rP   r&   ri   rC   s    r=   rD   z1_CollectionAggregationCommand._aggregation_target   s    ||   r?   c                .    | j                   j                  S rP   )r&   	full_namerC   s    r=   rG   z/_CollectionAggregationCommand._cursor_namespace   s    ||%%%r?   c                    | j                   S rI   r&   )r7   r#   s     r=   rL   z0_CollectionAggregationCommand._cursor_collection       ||r?   c                .    | j                   j                  S rP   )r&   databaserC   s    r=   rN   z'_CollectionAggregationCommand._database   s    ||$$$r?   Nrw   r#   ry   ru   r   rz   )	r|   r}   r~   __annotations__r   rD   rG   rL   rN   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+   )r7   argskwargs	__class__s      r=   r>   z)_CollectionRawAggregationCommand.__init__   s8    $)&) ##34DMM(#K0 $r?   )r   r   r   r   ru   rv   )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   rC   s    r=   rD   z/_DatabaseAggregationCommand._aggregation_target   s    r?   c                4    | j                   j                   dS )Nz.$cmd.aggregater   rC   s    r=   rG   z-_DatabaseAggregationCommand._cursor_namespace   s    ,,##$O44r?   c                    | j                   S rP   r   rC   s    r=   rN   z%_DatabaseAggregationCommand._database   r   r?   c                ~    |j                  d| j                        j                  dd      \  }}| j                  |   S )rJ   rb   .r   )rk   rG   splitrN   )r7   r#   _collnames       r=   rL   z._DatabaseAggregationCommand._cursor_collection   s:    
 jjt'='=>DDS!L8~~h''r?   N)ru   intrw   rz   r   )	r|   r}   r~   r   r   rD   rG   rN   rL   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   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      su    B " = = 6 6  8 - B4-4)'4%8e eP%$7 %(5'D 5("5 (r?   