
    hi                         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
 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)NotMasterErrorOperationFailure)_check_command_response)_convert_exception)ResponseExhaustResponse)SERVER_TYPEcursor   )
firstBatch	nextBatchc                       e Zd Z	 	 ddZd Z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          Q/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/pymongo/server.py__init__zServer.__init__   s\     /
'!-N)2N2N"==!8DL     c                 8    | j                   j                          y)z[Start monitoring, or restart after a fork.

        Multiple calls have no effect.
        N)r   openr   s    r"   r&   zServer.open,   s    
 	r$   c                 8    | j                   j                          y)zClear the connection pool.N)r   resetr'   s    r"   r)   zServer.reset3   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"   r.   zServer.close7   sj    
 ==LLdnnBB#0088$:K:KLN O

r$   c                 8    | j                   j                          y)zCheck the server's state soon.N)r   request_checkr'   s    r"   r0   zServer.request_checkB   s    ##%r$   c           
         d}|j                   }|rt        j                         }	|j                   }
|
r;|j	                  ||      }|j                  |||      }| j                  |      \  }}}nd}d}|rF|j                  |      \  }}|j                  ||||j                         t        j                         }		 |
r$|j                         |j                  |      }n|j                  d      }|r	t        }d}nd}d} |||j                  |j                  ||      }|rA|d   }|j                  j!                  ||j"                         t%        ||j&                         |rt        j                         	z
  }|r|d   }nY|j6                  dk(  r
|r|d   ni }n@|j                  |j9                         ddd	}|j6                  d
k(  r	||d   d<   n||d   d<   |j;                  |||j6                  ||j                         |j                  }|rN|j<                  rB|r@|j<                  j?                  |jA                               }tC        ||j                  |      }|r3tE        || jF                  j                  || jH                  ||||      }|S tK        || jF                  j                  ||||      }|S # t(        $ rv}|rnt        j                         	z
  }t+        |t,        t.        f      r|j0                  }nt3        |      }|j5                  |||j6                  ||j                          d}~ww xY w)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.

        :Parameters:
          - `operation`: A _Query or _GetMore object.
          - `set_slave_okay`: Pass to operation.get_message.
          - `all_credentials`: dict, maps auth source to MongoCredential.
          - `listeners`: Instance of _EventListeners or None.
          - `exhaust`: If True, then this is an exhaust cursor operation.
          - `unpack_res`: A callable that decodes the wire protocol response.
        NFr   T)legacy_responseuser_fieldsexplain)idnsr   )r   okfindr   r   r   )datar-   socket_infor   duration
request_idfrom_commanddocs)r9   r-   r;   r<   r=   r>   )&enabled_for_commandsr   nowexhaust_mgruse_commandget_message_split_message
as_commandpublish_command_startr-   send_messagereceive_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   r
   r   r   r	   )r   	sock_info	operationset_slave_okayr    exhaust
unpack_resr;   publishstartrG   use_cmdmessager<   r9   max_doc_sizecmddbnreplyr3   r2   r>   firstexcfailureresrL   	decryptedresponses                                r"   run_operation_with_responsez"Server.run_operation_with_responseF   sL   , 00LLNE$000++Iw?G++	74G-1-@-@-I*JlGJ ++I6HC++S*i&7&79LLNE 	&&t\:!11*=!11$7 0"'""&eY%8%8'55.=*57D Q  225):K:KL'y/I/IJ ||~-H 1g9,!%d1g2(-(1(;(;(="?  >>V+26CM,/15CM+.--#y~~z!!#
 !!f''"--55..02	,y66E &))11%ZZ!%$H$   ))11!%$H y  
	#<<>E1cN4D#EF!kkG05G11gy~~	 1 13 
	s   <B*K 	M 
A1L;;M c                 :    | j                   j                  ||      S N)r   
get_socket)r   all_credentialscheckouts      r"   rp   zServer.get_socket   s    yy##OX>>r$   c                     | j                   S ro   )r   r'   s    r"   descriptionzServer.description   s       r$   c                 \    |j                   | j                  j                   k(  sJ || _        y ro   )r-   r   )r   r   s     r"   rt   zServer.description   s*    !))T->->-F-FFFF.r$   c                     | j                   S ro   )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   rb   r<   r9   s       r"   rD   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$   )NNN)F)r   
__module____qualname__r#   r&   r)   r.   r0   rm   rp   propertyrt   setterr   rD   r    r$   r"   r   r      sz    FJ(,$	&~@? ! ! / /  'Hr$   r   N)__doc__r   bsonr   pymongo.errorsr   r   pymongo.helpersr   pymongo.messager   pymongo.responser	   r
   pymongo.server_typer   rI   objectr   r   r$   r"   <module>r      s?    9  & ; 3 . 6 +qq AB FHV FHr$   