Ejemplo n.º 1
0
    def __check_response_to_last_error(self, response):
        """Check a response to a lastError message for errors.

        `response` is a byte string representing a response to the message.
        If it represents an error response we raise OperationFailure.

        Return the response as a document.
        """
        response = helpers._unpack_response(response)

        assert response["number_returned"] == 1
        error = response["data"][0]

        helpers._check_command_response(error, self.disconnect)

        error_msg = error.get("err", "")
        if error_msg is None:
            return error
        if error_msg.startswith("not master"):
            self.disconnect()
            raise AutoReconnect(error_msg)

        if "code" in error:
            if error["code"] in [11000, 11001, 12582]:
                raise DuplicateKeyError(error["err"])
            else:
                raise OperationFailure(error["err"], error["code"])
        else:
            raise OperationFailure(error["err"])
Ejemplo n.º 2
0
 def mod_callback(result):
      if not isinstance(result, Exception):
          if check:
              msg = "command %s failed: %%s" % repr(command).replace("%", "%%")
              helpers._check_command_response(result, self.connection.disconnect,
                                 msg, allowable_errors)
       
          callback(result)
      else:
          callback(result)
Ejemplo n.º 3
0
 def __simple_command(self, sock_info, dbname, spec):
     """Send a command to the server.
     """
     rqst_id, msg, _ = message.query(0, dbname + '.$cmd', 0, -1, spec)
     sock_info.sock.sendall(msg)
     response = self.__recv_msg(1, rqst_id, sock_info)
     response = helpers._unpack_response(response)['data'][0]
     msg = "command %r failed: %%s" % spec
     helpers._check_command_response(response, None, msg)
     return response
Ejemplo n.º 4
0
    def __check_response_to_last_error(self, response):
        """Check a response to a lastError message for errors.

        `response` is a byte string representing a response to the message.
        If it represents an error response we raise OperationFailure.

        Return the response as a document.
        """
        response = helpers._unpack_response(response)

        assert response["number_returned"] == 1
        error = response["data"][0]

        response = helpers._check_command_response(error, self.disconnect)

        # TODO unify logic with database.error method
        if error.get("err", 0) is None:
            return error
        if error["err"] == "not master":
            self.disconnect()
            return AutoReconnect("not master")

        if "code" in error:
            if error["code"] in [11000, 11001, 12582]:
                return DuplicateKeyError(error["err"])
            else:
                return OperationFailure(error["err"], error["code"])
        else:
            return OperationFailure(error["err"])

        return response
Ejemplo n.º 5
0
    def __check_response_to_last_error(self, response):
        """Check a response to a lastError message for errors.

        `response` is a byte string representing a response to the message.
        If it represents an error response we raise OperationFailure.

        Return the response as a document.
        """
        response = helpers._unpack_response(response)

        assert response["number_returned"] == 1
        error = response["data"][0]

        response = helpers._check_command_response(error, self.disconnect)

        # TODO unify logic with database.error method
        if error.get("err", 0) is None:
            return error
        if error["err"] == "not master":
            self.disconnect()
            return AutoReconnect("not master")

        if "code" in error:
            if error["code"] in [11000, 11001, 12582]:
                return DuplicateKeyError(error["err"])
            else:
                return OperationFailure(error["err"], error["code"])
        else:
            return OperationFailure(error["err"])

        return response
Ejemplo n.º 6
0
 def mod_callback(result):
 
      if not isinstance(result,Exception):
          if check:
              msg = "command %r failed: %%s" % command
              check_result = helpers._check_command_response(result, self.connection.disconnect,
                                         msg, allowable_errors)
       
          callback(check_result)
      else:
          callback(result)
Ejemplo n.º 7
0
            def mod_callback(result):

                if not isinstance(result, Exception):
                    if check:
                        msg = "command %r failed: %%s" % command
                        check_result = helpers._check_command_response(
                            result, self.connection.disconnect, msg,
                            allowable_errors)

                    callback(check_result)
                else:
                    callback(result)