(self, sock_info, name, cmd, acknowledged, op_id,
                      bypass_doc_val, func, *args)
return result
Internal legacy write helper.
Internal legacy write helper.
Internal legacy write helper .
def _legacy_write(self, sock_info, name, cmd, acknowledged, op_id,
                      bypass_doc_val, func, *args):
        """Internal legacy write helper."""
        # Cannot have both unacknowledged write and bypass document validation.
        if (bypass_doc_val and not acknowledged and
                    sock_info.max_wire_version >= 4):
            raise OperationFailure("Cannot set bypass_document_validation with"
                                   " unacknowledged write concern")
        listeners = self.database.client._event_listeners
        publish = listeners.enabled_for_commands

        if publish:
            start = datetime.datetime.now()
        rqst_id, msg, max_size = func(*args)
        if publish:
            duration = datetime.datetime.now() - start
            listeners.publish_command_start(
                cmd, self.__database.name, rqst_id, sock_info.address, op_id)
            start = datetime.datetime.now()
        try:
            result = sock_info.legacy_write(
                rqst_id, msg, max_size, acknowledged)
        except Exception as exc:
            if publish:
                dur = (datetime.datetime.now() - start) + duration
                if isinstance(exc, OperationFailure):
                    details = exc.details
                    # Succeed if GLE was successful and this is a write error.
                    if details.get("ok") and "n" in details:
                        reply = message._convert_write_result(
                            name, cmd, details)
                        listeners.publish_command_success(
                            dur, reply, name, rqst_id, sock_info.address, op_id)
                        raise
                else:
                    details = message._convert_exception(exc)
                listeners.publish_command_failure(
                    dur, details, name, rqst_id, sock_info.address, op_id)
            raise
        if publish:
            if result is not None:
                reply = message._convert_write_result(name, cmd, result)
            else:
                # Comply with APM spec.
                reply = {'ok': 1}
            duration = (datetime.datetime.now() - start) + duration
            listeners.publish_command_success(
                duration, reply, name, rqst_id, sock_info.address, op_id)
        return result
def _legacy_write ( self , sock_info , name , cmd , acknowledged , op_id , bypass_doc_val , func , * args ) : # Cannot have both unacknowledged write and bypass document validation. if ( bypass_doc_val and not acknowledged and sock_info . max_wire_version >= 4 ) : raise OperationFailure ( "Cannot set bypass_document_validation with" " unacknowledged write concern" ) listeners = self . database . client . _event_listeners publish = listeners . enabled_for_commands if publish : start = datetime . datetime . now ( ) rqst_id , msg , max_size = func ( * args ) if publish : duration = datetime . datetime . now ( ) - start listeners . publish_command_start ( cmd , self . __database . name , rqst_id , sock_info . address , op_id ) start = datetime . datetime . now ( ) try : result = sock_info . legacy_write ( rqst_id , msg , max_size , acknowledged ) except Exception as exc : if publish : dur = ( datetime . datetime . now ( ) - start ) + duration if isinstance ( exc , OperationFailure ) : details = exc . details # Succeed if GLE was successful and this is a write error. if details . get ( "ok" ) and "n" in details : reply = message . _convert_write_result ( name , cmd , details ) listeners . publish_command_success ( dur , reply , name , rqst_id , sock_info . address , op_id ) raise else : details = message . _convert_exception ( exc ) listeners . publish_command_failure ( dur , details , name , rqst_id , sock_info . address , op_id ) raise if publish : if result is not None : reply = message . _convert_write_result ( name , cmd , result ) else : # Comply with APM spec. reply = { 'ok' : 1 } duration = ( datetime . datetime . now ( ) - start ) + duration listeners . publish_command_success ( duration , reply , name , rqst_id , sock_info . address , op_id ) return result