
    nhq7                    j   d Z ddlmZ ddlZddlmZ ddlmZmZmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZmZmZmZmZ ddlmZmZmZmZ ddl m!Z!m"Z" er@ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 dZ9ddddiZ: G d d      Z;y)z2Communicate with one MongoDB server in a topology.    )annotationsN)datetime)TYPE_CHECKINGAnyAsyncContextManagerCallableOptionalUnion)_decode_all_selective)_handle_reauth)NotPrimaryErrorOperationFailure)_check_command_response)_COMMAND_LOGGER_SDAM_LOGGER_CommandStatusMessage
_debug_log_SDAMStatusMessage)_convert_exception_GetMore_OpMsg_Query)PinnedResponseResponse)Queue)ReferenceType)ObjectId)AsyncMongoClient_MongoClientErrorHandler)Monitor)AsyncConnectionPool)_EventListeners)_ServerMode)ServerDescription)_DocumentOutFcursor   )
firstBatch	nextBatchc                     e Zd Z	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 ddZddZdddZddZddZ	 d	 	 	 	 	 	 	 ddZe		 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z
	 d	 	 	 dd	Zedd
       Zej                  dd       Zedd       Z	 	 	 	 ddZddZy)ServerNc                    || _         || _        || _        || _        |duxr |j                  | _        || _        d| _        | j
                  r |       | _        yy)zRepresent one MongoDB server.N)_description_pool_monitor_topology_idenabled_for_server_publish	_listener_events)selfserver_descriptionpoolmonitortopology_id	listenerseventss          /var/www/html/SchoolMeal/SchoolMeal/pds_admin_SchoolMeal/Backend/venv/lib/python3.12/site-packages/pymongo/asynchronous/server.py__init__zServer.__init__>   s\     /
'!-N)2N2N"==!8DL     c                   K   | j                   j                  j                  s| j                  j	                          yyw)z[Start monitoring, or restart after a fork.

        Multiple calls have no effect.
        N)r/   optsload_balancedr0   openr6   s    r=   rC   zServer.openR   s.     
 zz,,MM  -s   =?c                V   K   | j                   j                  |       d{    y7 w)zClear the connection pool.N)r8   reset)r6   
service_ids     r=   rF   zServer.resetZ   s     iiooj)))s   )')c                  K   | j                   rm| j                  J | j                  J | j                  j                  | j                  j                  | j
                  j                  | j                  ff       t        j                  t        j                        rZt        t        t        j                  | j                  | j
                  j                  d   | j
                  j                  d          | j                  j!                          d{    | j"                  j!                          d{    y7 '7 w)zXClear the connection pool and stop the monitor.

        Reconnect with open().
        Nr   r(   )message
topologyId
serverHost
serverPort)r3   r4   r5   putpublish_server_closedr.   addressr1   r   isEnabledForloggingDEBUGr   r   STOP_SERVERr0   closer/   rD   s    r=   rT   zServer.close^   s     
 ==>>---<<+++LLNN88&&..0A0AB $$W]]3*66,,,,44Q7,,44Q7 mm!!###jj    	$ s$   DED>!E8E 9E Ec                8    | j                   j                          y)zCheck the server's state soon.N)r0   request_checkrD   s    r=   rV   zServer.request_checkx   s    ##%r?   c                T  K   |j                  ||      \  }}|j                  j                  rc|j                  j                  j                  sC|j                  j                  j	                  |j
                  ||j                         d {   }|j                  |       ||fS 7 wN)
as_commandclient
_encrypter_bypass_auto_encryptionencryptdbcodec_optionsupdate_command)r6   	operationconnapply_timeoutcmdr^   s         r=   operation_to_commandzServer.operation_to_command|   s      &&t];R&&y/?/?/J/J/b/b!((33;;c9#:#: C 	  %Bws   B
B(B&B(c                  K   |J |j                   }t        j                         }|j                  |      }	|j                  xr |j                  j
                  }
| j                  |||	       d{   \  }}|
rd}n(|j                  |||	      }| j                  |      \  }}}t        j                  t        j                        rt        t        t        j                  |j                   j"                  |t%        t'        |            ||||j(                  |j*                  |j,                  d   |j,                  d   |j.                         |rBd|vr||d<   |J |j1                  ||||j,                  |j*                  |j.                         	 |
r|j3                  d       d{   }n3|j5                         d{    |j3                  |       d{   }|	r	t6        }d}nd}d} |||j8                  |j:                  ||	      }|	rI|d   }|j<                  j?                  ||j@                         d{    tC        ||jD                         t        j                         |z
  }|	r|d   }nY|jV                  dk(  r
|r|d   ni }n@|j8                  |jY                         ddd}|jV                  dk(  r	||d   d<   n||d   d<   t        j                  t        j                        rt        t        t        jZ                  |j                   j"                  ||t%        t'        |            ||||j(                  |j*                  |j,                  d   |j,                  d   |j.                         |rE|J |j]                  |||jV                  ||j,                  |j*                  |j.                  |       |j<                  }|rV|j^                  rJ|	rH|j^                  ja                  |jc                                d{   }te        ||j:                  |      }|jg                  |j@                        s|jh                  r|jk                          tI        |tl              r|j
                  }
n#to        |jh                  xr |j8                        }
|j                  r|j                  jq                  |
       ts        || jt                  j,                  ||||	||
      }|S tw        || jt                  j,                  |||	|      }|S 7 7 t7 \7 F7 # tF        $ rM}t        j                         |z
  }tI        |tJ        tL        f      r|jN                  }ntQ        |      }t        j                  t        j                        rt        t        t        jR                  |j                   j"                  ||t%        t'        |            ||||j(                  |j*                  |j,                  d   |j,                  d   |j.                  tI        |tL              
       |rE|J |jU                  |||jV                  ||j,                  |j*                  |j.                  |        d}~ww xY w7 sw)aH  Run a _Query or _GetMore operation and return a Response object.

        This method is used only to run _Query/_GetMore operations from
        cursors.
        Can raise ConnectionFailure, OperationFailure, etc.

        :param conn: An AsyncConnection instance.
        :param operation: A _Query or _GetMore object.
        :param read_preference: The read preference to use.
        :param listeners: Instance of _EventListeners or None.
        :param unpack_res: A callable that decodes the wire protocol response.
        :param client: An AsyncMongoClient instance.
        Nr   r(   )rI   clientIdcommandcommandNamedatabaseName	requestIdoperationIddriverConnectionIdserverConnectionIdrK   rL   	serviceIdz$db)rG   FT)legacy_responseuser_fields)rI   rg   
durationMSfailureri   rj   rk   rl   rm   rn   rK   rL   ro   isServerSideError)rG   database_nameexplain)idns)r'   okfindr'   r)   r*   )rI   rg   rr   replyri   rj   rk   rl   rm   rn   rK   rL   ro   )datarO   rb   duration
request_idfrom_commanddocsmore_to_come)r|   rO   r}   r~   r   r   )<enabled_for_commandsr   nowuse_commandconn_mgrr   re   get_message_split_messager   rP   rQ   rR   r   r   STARTED_topology_settingsr1   nextiterrw   server_connection_idrO   rG   publish_command_startreceive_messagesend_message_CURSOR_DOC_FIELDS	cursor_idr_   rZ   _process_responsesessionr   max_wire_version	Exception
isinstancer   r   detailsr   FAILEDpublish_command_failurename	namespace	SUCCEEDEDpublish_command_successr[   decryptraw_command_responser   _should_pin_cursorexhaust
pin_cursorr   boolupdate_exhaustr   r.   r   )r6   rb   ra   read_preferencer;   
unpack_resrZ   publishstartuse_cmdr   rd   dbnr~   rI   r|   max_doc_sizer{   rq   rp   r   firstexcr}   rs   res	decryptedresponses                               r=   run_operationzServer.run_operation   s    . $$$00''- ))Mi.@.@.M.M229dGLLSJ++OT7KG-1-@-@-I*Jl''6-5522?? cO $&#'77#'#<#<<<?<<?//  C E
(((++))?? , =	"22488''l;;;"22:>> 0"'""&##'' /'D Q&&88	@Q@QRRR't/D/DEL <<>E) q'C^^y(!$q'rC$)OO9;N;N;PQYZ[C~~'.2Hl+-1Hk*''6-7722??# cO $&#'77#'#<#<<<?<<?//  (((--))??! . 	 !!f''"("3"3";";E<V<V<X"YY	,Y	8O8OQ\] $$Y%6%679;L;LOO%(  %11  $I$5$5$I%//J!!""11,?%))11!%$)	H(   ))11!%$H m MN 9;>$ S $	||~-H#1ABC(+,S1++GMM:#188#66CC'# $T#Y!$( *'+ww'+'@'@#||A#||A"oo&06F&G"  ,,,11NNLL--#"% 2 	 I$	h Zs   A0Z
2T3D#Z
T- -T!.T- T$	T- !T'"A$T- T*T- !F3Z
ZD
Z
!T- $T- 'T- *T- -
Z7EY??ZZ
c                @   K   | j                   j                  |      S wrX   )r8   checkout)r6   handlers     r=   r   zServer.checkout^  s      yy!!'**s   c                    | j                   S rX   )r.   rD   s    r=   descriptionzServer.descriptionc  s       r?   c                \    |j                   | j                  j                   k(  sJ || _        y rX   )rO   r.   )r6   r7   s     r=   r   zServer.descriptiong  s*    !))T->->-F-FFFF.r?   c                    | j                   S rX   )r/   rD   s    r=   r8   zServer.pooll  s    zzr?   c                6    t        |      dk(  r|S |\  }}||dfS )zReturn request_id, data, max_doc_size.

        :param message: (request_id, data, max_doc_size) or (request_id, data)
           r   )len)r6   rI   r~   r|   s       r=   r   zServer._split_messagep  s.     w<1N  'JtQ&&r?   c                P    d| j                   j                   d| j                  dS )N< >)	__class____name__r.   rD   s    r=   __repr__zServer.__repr__~  s)    4>>**+1T->->,ACCr?   )NNN)r7   r%   r8   r"   r9   r    r:   Optional[ObjectId]r;   Optional[_EventListeners]r<   zOptional[ReferenceType[Queue]]returnNone)r   r   rX   )rG   r   r   r   )F)ra   Union[_Query, _GetMore]rb   r!   rc   r   r   ztuple[dict[str, Any], str])rb   r!   ra   r   r   r$   r;   r   r   z!Callable[..., list[_DocumentOut]]rZ   r   r   r   )r   z"Optional[_MongoClientErrorHandler]r   z$AsyncContextManager[AsyncConnection])r   r%   )r7   r%   r   r   )r   r"   )rI   z,Union[tuple[int, Any], tuple[int, Any, int]]r   ztuple[int, Any, int])r   str)r   
__module____qualname__r>   rC   rF   rT   rV   re   r   r   r   propertyr   setterr8   r   r    r?   r=   r,   r,   =   sp    +//315$-$ $ 	$
 ($ -$ /$ 
$(!*!4&
 `e08GX\	# RR +R %	R
 -R 6R !R 
R Rj =A+9+	-+
 ! ! / /  'C'	'Dr?   r,   )<__doc__
__future__r   rQ   r   typingr   r   r   r   r	   r
   bsonr   pymongo.asynchronous.helpersr   pymongo.errorsr   r   pymongo.helpers_sharedr   pymongo.loggerr   r   r   r   r   pymongo.messager   r   r   r   pymongo.responser   r   queuer   weakrefr   bson.objectidr   !pymongo.asynchronous.mongo_clientr   r   pymongo.asynchronous.monitorr    pymongo.asynchronous.poolr!   r"   pymongo.monitoringr#   pymongo.read_preferencesr$   pymongo.server_descriptionr%   pymongo.typingsr&   _IS_SYNCr   r,   r   r?   r=   <module>r      s    9 "    ' 7 < :  I H 5%&\4?24<,qq AB BD BDr?   