
    hG"                         d 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 ddlmZmZ ddlmZ d	d
d
diZ G d de      Zy)z2Communicate with one MongoDB server in a topology.    )datetime)_decode_all_selective)NotPrimaryErrorOperationFailure)_check_command_response)_convert_exception_OpMsg)PinnedResponseResponse)SERVER_TYPEcursor   )
firstBatch	nextBatchc                       e Zd Z	 ddZd ZddZd Zd Zd ZddZ	e
d	        Zej                  d
        Ze
d        Zd Z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          L/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/pymongo/server.py__init__zServer.__init__   s\     /
'!-N)2N2N"==!8DL     c                 z    | j                   j                  j                  s| j                  j	                          yy)z[Start monitoring, or restart after a fork.

        Multiple calls have no effect.
        N)r   optsload_balancedr   openr   s    r#   r)   zServer.open,   s*    
 zz,,MM  -r%   c                 :    | j                   j                  |       y)zClear the connection pool.N)r   reset)r   
service_ids     r#   r,   zServer.reset4   s    		
#r%   c                 &   | j                   rQ| j                  j                  | j                  j                  | j
                  j                  | j                  ff       | j                  j                          | j                  j                          y)zXClear the connection pool and stop the monitor.

        Reconnect with open().
        N)r   r   putr   publish_server_closedr   addressr   r   closer   r,   r*   s    r#   r2   zServer.close8   sk    
 ==LLNN88&&..0A0AB 	

r%   c                 8    | j                   j                          y)zCheck the server's state soon.N)r   request_checkr*   s    r#   r4   zServer.request_checkG   s    ##%r%   c           
         d}|j                   }|rt        j                         }|j                  |      }	|j                  xr |j                  j
                  }
|
rd}n(|j                  |||	      }| j                  |      \  }}}|rR|j                  |      \  }}|j                  ||||j                  |j                         t        j                         }	 |
r|j                  d      }n#|j                         |j                  |      }|	r	t        }d}nd}d} |||j                  |j                   ||      }|	rA|d   }|j"                  j%                  ||j&                         t)        ||j*                         |rt        j                         z
  }|	r|d   }nY|j:                  dk(  r
|r|d   ni }n@|j                  |j=                         dd	d
}|j:                  dk(  r	||d   d<   n||d   d<   |j?                  |||j:                  ||j                  |j                         |j"                  }|rN|j@                  rB|	r@|j@                  jC                  |jE                               }tG        ||j                   |      }|jI                  |j&                        s|jJ                  r|jM                          t/        |tN              r|j
                  }
n#tQ        |jJ                  xr |j                        }
|j                  r|j                  jS                  |
       tU        || jV                  j                  ||||	||
      }|S tY        || jV                  j                  |||	|      }|S # t,        $ r}|rzt        j                         z
  }t/        |t0        t2        f      r|j4                  }nt7        |      }|j9                  |||j:                  ||j                  |j                          d}~ww xY w)aB  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.

        :Parameters:
          - `operation`: A _Query or _GetMore object.
          - `set_secondary_okay`: Pass to operation.get_message.
          - `all_credentials`: dict, maps auth source to MongoCredential.
          - `listeners`: Instance of _EventListeners or None.
          - `unpack_res`: A callable that decodes the wire protocol response.
        Nr   )r-   FT)legacy_responseuser_fieldsexplain)idnsr   )r   okfindr   r   r   )datar1   socket_infoduration
request_idfrom_commanddocsmore_to_come)r=   r1   r?   r@   rA   rB   )-enabled_for_commandsr   nowuse_commandsock_mgrrC   get_message_split_message
as_commandpublish_command_startr1   r-   receive_messagesend_message_CURSOR_DOC_FIELDS	cursor_idcodec_optionsclient_process_responsesessionr   max_wire_version	Exception
isinstancer   r   detailsr   publish_command_failurename	namespacepublish_command_success
_encrypterdecryptraw_command_responser   _should_pin_cursorexhaust
pin_cursorr	   boolupdate_exhaustr
   r   r   )r   	sock_info	operationset_secondary_okayr!   
unpack_resr?   publishstartuse_cmdrC   r@   messager=   max_doc_sizecmddbnreplyr7   r6   rB   firstexcfailureresrQ   	decryptedresponses                               r#   run_operationzServer.run_operationK   s    00LLNE''	2 ))Mi.@.@.M.MJ++,>	7SG-1-@-@-I*Jl ++I6HC++S*i&7&7IDXDX ,  LLNE(	!11$7&&t\:!11*= 0"'""&##'' /'D Q  225):K:KL'y/I/IJ$ ||~-H 1g9,!%d1g2(-y?R?R?T!U]^_>>V+26CM,/15CM+.--!!$// .  !!f''"--55e6P6P6RS	,Y	8O8OQ\]$$Y%6%679;L;L  "%(  %11  $I$5$5$I%//J!!""11,?%))11%!%$)	H(   ))11!%$H ]  	#<<>E1cO5E#FG!kkG05G11NN%%(33 2  	s   B*M? ?	P
A=PP
c                 :    | j                   j                  ||      S N)r   
get_socket)r   all_credentialshandlers      r#   ry   zServer.get_socket   s    yy##OW==r%   c                     | j                   S rx   )r   r*   s    r#   descriptionzServer.description   s       r%   c                 \    |j                   | j                  j                   k(  sJ || _        y rx   )r1   r   )r   r   s     r#   r}   zServer.description   s*    !))T->->-F-FFFF.r%   c                     | j                   S rx   )r   r*   s    r#   r   zServer.pool   s    zzr%   c                 6    t        |      dk(  r|S |\  }}||dfS )zReturn request_id, data, max_doc_size.

        :Parameters:
          - `message`: (request_id, data, max_doc_size) or (request_id, data)
           r   )len)r   rk   r@   r=   s       r#   rI   zServer._split_message   s.     w<1N  'JtQ&&r%   c                 P    d| j                   j                  d| j                  dS )N< >)	__class____name__r   r*   s    r#   __repr__zServer.__repr__   s     NN33T5F5FGGr%   )NNNrx   )r   
__module____qualname__r$   r)   r,   r2   r4   rv   ry   propertyr}   setterr   rI   r    r%   r#   r   r      sw    Z^$!$&IV> ! ! / /  'Hr%   r   N)__doc__r   bsonr   pymongo.errorsr   r   pymongo.helpersr   pymongo.messager   r	   pymongo.responser
   r   pymongo.server_typer   rN   objectr   r   r%   r#   <module>r      s?    9  & < 3 6 5 +qq AB WHV WHr%   