
    &gW8                    t   S r SSKJr  SSKrSSKJr  SSKJrJrJrJ	r	J
r
Jr  SSKJr  SSKJrJr  SSKJr  SS	KJrJrJrJrJr  SS
KJrJrJrJr  SSKJrJ r   SSK!J"r"  \(       a@  SSK#J$r$  SSK%J&r&  SSK'J(r(  SSK)J*r*  SSK+J,r,  SSK-J.r.  SSK/J0r0J1r1  SSK2J3r3  SSK4J5r5J6r6  SSK7J8r8  Sr9SSSS.0r: " S S5      r;g)z2Communicate with one MongoDB server in a topology.    )annotationsN)datetime)TYPE_CHECKINGAnyCallableContextManagerOptionalUnion)_decode_all_selective)NotPrimaryErrorOperationFailure)_check_command_response)_COMMAND_LOGGER_SDAM_LOGGER_CommandStatusMessage
_debug_log_SDAMStatusMessage)_convert_exception_GetMore_OpMsg_Query)PinnedResponseResponse)_handle_reauth)Queue)ReferenceType)ObjectId)_EventListeners)_ServerMode)ServerDescription)MongoClient_MongoClientErrorHandler)Monitor)
ConnectionPool)_DocumentOutTcursor   )
firstBatch	nextBatchc                  >   \ rS rSr   S             SS jjrSS jrSSS jjrSS jrSS jr S       SS jjr	\
              SS	 j5       r S   SS
 jjr\SS j5       r\R                  SS j5       r\SS j5       r    SS jrSS jrSrg)Server=   Nc                    Xl         X l        X0l        X@l        USL=(       a    UR                  U l        XPl        SU l        U R
                  (       a  U" 5       U l        gg)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          _C:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\pymongo/synchronous/server.py__init__Server.__init__>   sR     /
'!-N)2N2N"==!8DL     c                    U R                   R                  R                  (       d  U R                  R	                  5         gg)zKStart monitoring, or restart after a fork.

Multiple calls have no effect.
N)r0   optsload_balancedr1   openr7   s    r>   rE   Server.openR   s*    
 zz,,MM  -rA   c                :    U R                   R                  U5        g)zClear the connection pool.N)r9   reset)r7   
service_ids     r>   rI   Server.resetZ   s    		
#rA   c                l   U R                   (       ao  U R                  c   eU R                  c   eU R                  R                  U R                  R                  U R
                  R                  U R                  445        [        R                  " [        R                  5      (       aW  [        [        [        R                  U R                  U R
                  R                  S   U R
                  R                  S   S9  U R                  R!                  5         U R"                  R!                  5         g)zHClear the connection pool and stop the monitor.

Reconnect with open().
Nr   r(   )message
topologyId
serverHost
serverPort)r4   r5   r6   putpublish_server_closedr/   addressr2   r   isEnabledForloggingDEBUGr   r   STOP_SERVERr1   closer0   rF   s    r>   rX   Server.close^   s    
 ==>>---<<+++LLNN88&&..0A0AB $$W]]33*66,,,,44Q7,,44Q7 	

rA   c                8    U R                   R                  5         g)zCheck the server's state soon.N)r1   request_checkrF   s    r>   r[   Server.request_checkx   s    ##%rA   c                D   UR                  X#5      u  pEUR                  R                  (       a_  UR                  R                  R                  (       d:  UR                  R                  R	                  UR
                  XAR                  5      nUR                  U5        XE4$ N)
as_commandclient
_encrypter_bypass_auto_encryptionencryptdbcodec_optionsupdate_command)r7   	operationconnapply_timeoutcmdrd   s         r>   operation_to_commandServer.operation_to_command|   s{     &&t;&&y/?/?/J/J/b/b""--55c#:#:C 	  %wrA   c                F   Uc   eUR                   n[        R                  " 5       nUR                  U5      n	UR                  =(       a    UR                  R
                  n
U R                  X!U	5      u  pU
(       a  SnO&UR                  X1U	5      nU R                  U5      u  pn[        R                  " [        R                  5      (       a  [        [        [        R                  UR                   R"                  U[%        ['        U5      5      UUUUR(                  UR*                  UR,                  S   UR,                  S   UR.                  S9  U(       aA  SU;  a  XS'   Uc   eUR1                  UUUUR,                  UR*                  UR.                  S9   U
(       a  UR3                  S5      nO#UR5                  WW5        UR3                  U5      nU	(       a	  [6        nSnOSnSnU" UUR8                  UR:                  UUS	9nU	(       aA  US   nUR<                  R?                  UUR@                  5        [C        UURD                  5        [        R                  " 5       U-
  nU	(       a  US   nO`URV                  S:X  a  U(       a  US   O0 nOAUR8                  URY                  5       S.SS.nURV                  S:X  a	  UUS   S'   OUUS   S'   [        R                  " [        R                  5      (       a  [        [        [        RZ                  UR                   R"                  UU[%        ['        U5      5      UUUUR(                  UR*                  UR,                  S   UR,                  S   UR.                  S9  U(       aC  Uc   eUR]                  UUURV                  UUR,                  UR*                  UR.                  US9  UR<                  nU(       aX  UR^                  (       aG  U	(       a@  UR^                  Ra                  URc                  5       5      n[e        UUR:                  U5      nURg                  UR@                  5      (       d  URh                  (       a  URk                  5         [I        U[l        5      (       a  UR
                  n
O([o        URh                  =(       a    UR8                  5      n
UR                  (       a  UR                  Rq                  U
5        [s        UU Rt                  R,                  UUUU	UU
S9nU$ [w        UU Rt                  R,                  UUU	US9nU$ ! [F         GaY  n[        R                  " 5       U-
  n[I        U[J        [L        45      (       a  URN                  nO[Q        U5      n[        R                  " [        R                  5      (       a  [        [        [        RR                  UR                   R"                  UU[%        ['        U5      5      UUUUR(                  UR*                  UR,                  S   UR,                  S   UR.                  [I        U[L        5      S
9  U(       aC  Uc   eURU                  UUURV                  UUR,                  UR*                  UR.                  US9  e SnAff = f)a  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: A Connection 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: A MongoClient instance.
Nr   r(   )rM   clientIdcommandcommandNamedatabaseName	requestIdoperationIddriverConnectionIdserverConnectionIdrO   rP   	serviceIdz$db)rJ   FT)legacy_responseuser_fields)rM   rn   
durationMSfailurerp   rq   rr   rs   rt   ru   rO   rP   rv   isServerSideError)rJ   database_nameexplain)idns)r'   okfindr'   r)   r*   )rM   rn   ry   replyrp   rq   rr   rs   rt   ru   rO   rP   rv   )datarS   rh   duration
request_idfrom_commanddocsmore_to_come)r   rS   r   r   r   r   )<enabled_for_commandsr   nowuse_commandconn_mgrr   rk   get_message_split_messager   rT   rU   rV   r   r   STARTED_topology_settingsr2   nextiterr~   server_connection_idrS   rJ   publish_command_startreceive_messagesend_message_CURSOR_DOC_FIELDS	cursor_idre   r`   _process_responsesessionr   max_wire_version	Exception
isinstancer   r   detailsr   FAILEDpublish_command_failurename	namespace	SUCCEEDEDpublish_command_successra   decryptraw_command_responser   _should_pin_cursorexhaust
pin_cursorr   boolupdate_exhaustr   r/   r   )r7   rh   rg   read_preferencer<   
unpack_resr`   publishstartuse_cmdr   rj   dbnr   rM   r   max_doc_sizer   rx   rw   r   firstexcr   rz   res	decryptedresponses                               r>   run_operationServer.run_operation   s   . $$$00''- ))Mi.@.@.M.M,,YgFJ++O7KG-1-@-@-I*Jl''66-5522?? cO $&#'77#'#<#<<<?<<?//  C E
(((++))?? , =	,,T2!!$5,,Z8 0"'""&##'' /'D Q  225):K:KL't/D/DEL <<>E) q'C^^y(!$q'rC$)OO9;N;N;PQYZ[C~~'.2Hl+-1Hk*''66-7722??# cO $&#'77#'#<#<<<?<<?//  (((--))??! . 	 !!f''"--55e6P6P6RS	,Y	8O8OQ\] $$Y%6%6779;L;LOO%((  %11  $I$5$5$I%//J!!""11,?%))11!%$)	H(   ))11!%$H q  $	||~-H#1ABC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$	s   B6T< <Z EZZ c                8    U R                   R                  U5      $ r^   )r9   checkout)r7   handlers     r>   r   Server.checkout^  s     yy!!'**rA   c                    U R                   $ r^   )r/   rF   s    r>   descriptionServer.descriptionc  s       rA   c                \    UR                   U R                  R                   :X  d   eXl        g r^   )rS   r/   )r7   r8   s     r>   r   r   g  s(    !))T->->-F-FFFF.rA   c                    U R                   $ r^   )r0   rF   s    r>   r9   Server.pooll  s    zzrA   c                4    [        U5      S:X  a  U$ Uu  p#X#S4$ )zoReturn request_id, data, max_doc_size.

:param message: (request_id, data, max_doc_size) or (request_id, data)
   r   )len)r7   rM   r   r   s       r>   r   Server._split_messagep  s*     w<1N  'JQ&&rA   c                R    SU R                   R                   SU R                  < S3$ )N< >)	__class____name__r/   rF   s    r>   __repr__Server.__repr__~  s)    4>>**+1T->->,ACCrA   )r/   r6   r5   r1   r0   r4   r2   )NNN)r8   r    r9   r%   r:   r#   r;   Optional[ObjectId]r<   Optional[_EventListeners]r=   zOptional[ReferenceType[Queue]]returnNone)r   r   r^   )rJ   r   r   r   )F)rg   Union[_Query, _GetMore]rh   r$   ri   r   r   ztuple[dict[str, Any], str])rh   r$   rg   r   r   r   r<   r   r   z!Callable[..., list[_DocumentOut]]r`   r!   r   r   )r   z"Optional[_MongoClientErrorHandler]r   zContextManager[Connection])r   r    )r8   r    r   r   )r   r%   )rM   z,Union[tuple[int, Any], tuple[int, Any, int]]r   ztuple[int, Any, int])r   str)r   
__module____qualname____firstlineno__r?   rE   rI   rX   r[   rk   r   r   r   propertyr   setterr9   r   r   __static_attributes__ rA   r>   r,   r,   =   sp    +//315$-$ $ 	$
 ($ -$ /$ 
$(!$4&
 [`08BSW	# RR +R %	R
 -R 6R R 
R Rj =A+9+	#+
 ! ! / /  'C'	'DrA   r,   )<__doc__
__future__r   rU   r   typingr   r   r   r   r	   r
   bsonr   pymongo.errorsr   r   pymongo.helpers_sharedr   pymongo.loggerr   r   r   r   r   pymongo.messager   r   r   r   pymongo.responser   r   pymongo.synchronous.helpersr   queuer   weakrefr   bson.objectidr   pymongo.monitoringr   pymongo.read_preferencesr   pymongo.server_descriptionr     pymongo.synchronous.mongo_clientr!   r"   pymongo.synchronous.monitorr#   pymongo.synchronous.poolr$   r%   pymongo.typingsr&   _IS_SYNCr   r,   r   rA   r>   <module>r      s    9 "    ' < :  I H 5 6%&24<V39,qq AB BD BDrA   