o Sb]"@szdZddlmZddlmZddlmZmZddlmZddl m Z m Z ddl m Z mZdd d d iZGd d d eZd S)z2Communicate with one MongoDB server in a topology.)datetime)_decode_all_selective)NotPrimaryErrorOperationFailure)_check_command_response)_convert_exception_OpMsg)PinnedResponseResponsecursor) firstBatch nextBatchc@seZdZ dddZddZdddZdd Zd d Zd d ZdddZ e ddZ e j ddZ e ddZ ddZddZdS)ServerNcCsJ||_||_||_||_|duo|j|_||_d|_|jr#||_dSdS)zRepresent one MongoDB server.N) _description_pool_monitor _topology_idZenabled_for_server_publish _listener_events)selfserver_descriptionpoolZmonitorZ topology_id listenerseventsr5/tmp/pip-target-onvjaxws/lib/python/pymongo/server.py__init__s zServer.__init__cCs|jjjs |jdSdS)z[Start monitoring, or restart after a fork. Multiple calls have no effect. N)roptsZ load_balancedropenrrrrr +s z Server.opencCs|j|dS)zClear the connection pool.N)rreset)r service_idrrrr"3sz Server.resetcCsX|jr |jdus J|jdusJ|j|jj|jj|jff|j |j dS)zXClear the connection pool and stop the monitor. Reconnect with open(). N) rrrputZpublish_server_closedraddressrrcloserZreset_without_pauser!rrrr&7s  z Server.closecCs|jdS)zCheck the server's state soon.N)r request_checkr!rrrr'HszServer.request_checkc Csd}|j}|r t}||} |jo|jj} | rd} n|||| } || \} } }|rD||\}}|j ||| |j |j dt}z?| rM| d}n | | || | }| r_t}d}nd}d}|||j|j||d}| r|d}|j||jt||jWn2ty}z&|rt|}t|ttfr|j}nt|}|j|||j| |j |j dd}~ww|rt|}| r|d}n+|jdkr|r|dni}n|j|dd d }|jd kr||d d <n||d d<|j|||j| |j |j d|j}|r|j r| r|j !|"}t#||j|}|$|js%|j%rV|&t|t'r3|j} n t(|j%o:|j} |jrF|j)| t*||j+j ||| | || d}|St,||j+j || | |d}|S)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: - `sock_info`: A SocketInfo instance. - `operation`: A _Query or _GetMore object. - `set_secondary_okay`: Pass to operation.get_message. - `listeners`: Instance of _EventListeners or None. - `unpack_res`: A callable that decodes the wire protocol response. Nr)r#FT)legacy_response user_fieldsexplain)idnsr )r okfindr r r)datar%Z socket_infoduration request_id from_commanddocs more_to_come)r/r%r0r1r2r3)-Zenabled_for_commandsrnowZ use_commandZsock_mgrr4Z get_message_split_messageZ as_commandZpublish_command_startr%r#Zreceive_message send_message_CURSOR_DOC_FIELDSZ cursor_idZ codec_optionsclientZ_process_responsesessionrZmax_wire_version Exception isinstancerrdetailsrZpublish_command_failurename namespaceZpublish_command_successZ _encrypterZdecryptZraw_command_responserZ_should_pin_cursorZexhaustZ pin_cursorrboolZupdate_exhaustr rr )rZ sock_infoZ operationZread_preferencerZ unpack_resr0publishstartZuse_cmdr4r1messager/Z max_doc_sizecmdZdbnZreplyr)r(r3firstexcZfailureresr9Z decryptedresponserrr run_operationLs               zServer.run_operationcCs |j|SN)r get_socket)rhandlerrrrrKs zServer.get_socketcC|jSrJ)rr!rrr descriptionzServer.descriptioncCs|j|jjks J||_dSrJ)r%r)rrrrrrNs cCrMrJ)rr!rrrrrOz Server.poolcCs"t|dkr|S|\}}||dfS)zReturn request_id, data, max_doc_size. :Parameters: - `message`: (request_id, data, max_doc_size) or (request_id, data) r)len)rrCr1r/rrrr6s  zServer._split_messagecCsd|jj|jfS)Nz<%s %r>) __class____name__rr!rrr__repr__szServer.__repr__)NNNrJ)rS __module__ __qualname__rr r"r&r'rIrKpropertyrNsetterrr6rTrrrrrs$       rN)__doc__rZbsonrZpymongo.errorsrrZpymongo.helpersrZpymongo.messagerrZpymongo.responser r r8objectrrrrrs