Пример #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]

        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
Пример #2
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"])
Пример #3
0
 def mod_callback(response):
     if isinstance(response,Exception):
         self.__error = response
     
     else:
         if isinstance(response, tuple):
             (connection_id, response) = response
         else:
             connection_id = None
         
         self.__connection_id = connection_id
         
         try:
             response = helpers._unpack_response(response, self.__id,
                                                 self.__as_class,
                                                 self.__tz_aware)
         except AutoReconnect:
             db.connection.disconnect()
             raise
         
         self.__id = response["cursor_id"]
         
         # starting from doesn't get set on getmore's for tailable cursors
         if not self.__tailable:
             assert response["starting_from"] == self.__retrieved
         
         self.__retrieved += response["number_returned"]
         self.__data = response["data"]
         
         if self.__limit and self.__id and self.__limit <= self.__retrieved:
             self.__die()
     
     
     callback(response)
Пример #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
Пример #5
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
Пример #6
0
        def mod_callback(response):

            if isinstance(response, Exception):
                self.__error = response

            else:
                if isinstance(response, tuple):
                    (connection_id, response) = response
                else:
                    connection_id = None

                self.__connection_id = connection_id

                try:
                    response = helpers._unpack_response(
                        response, self.__id, self.__as_class, self.__tz_aware)
                except AutoReconnect:
                    db.connection.disconnect()
                    raise

                self.__id = response["cursor_id"]

                # starting from doesn't get set on getmore's for tailable cursors
                if not self.__tailable:
                    assert response["starting_from"] == self.__retrieved

                self.__retrieved += response["number_returned"]
                self.__data = response["data"]

                die_now = (self.__id == 0) or (len(
                    self.__data) == 0) or (self.__limit and self.__id and
                                           self.__limit <= self.__retrieved)

                if die_now:
                    self.__die()

            callback()