Example #1
0
    def __send_message(self, message):
        """Send a query or getmore message and handles the response.
        """
        db = self.__collection.database()
        kwargs = {"_sock": self.__socket,
                  "_must_use_master": self.__must_use_master}
        if self.__connection_id is not None:
            kwargs["_connection_to_use"] = self.__connection_id

        response = db.connection()._send_message_with_response(message,
                                                               **kwargs)

        if isinstance(response, types.TupleType):
            (connection_id, response) = response
        else:
            connection_id = None

        self.__connection_id = connection_id

        try:
            response = helpers._unpack_response(response, self.__id)
        except AutoReconnect:
            db.connection()._reset()
            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()
Example #2
0
    def _parse_response(self, response):
        # logging.info('got data %r' % response)
        callback = self.__callback
        request_id = self.__request_id
        self.__request_id = None
        self.__callback = None
        self.__pool.cache(self)

        try:
            response = helpers._unpack_response(response, request_id)  # TODO: pass tz_awar
        except Exception, e:
            logging.error("error %s" % e)
            callback(None, e)
            return
Example #3
0
    def _parse_response(self, response):
        # logging.info('got data %r' % response)
        callback = self.__callback
        request_id = self.__request_id
        self.__request_id = None
        self.__callback = None
        self.__pool.cache(self)

        try:
            response = helpers._unpack_response(
                response, request_id)  # TODO: pass tz_awar
        except Exception, e:
            logging.error('error %s' % e)
            callback(None, e)
            return
Example #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.
        """
        response = helpers._unpack_response(response)

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

        # TODO unify logic with database.error method
        if error.get("err", 0) is None:
            return
        if error["err"] == "not master":
            self._reset()
        raise OperationFailure(error["err"])
Example #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.
        """
        response = helpers._unpack_response(response)

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

        # TODO unify logic with database.error method
        if error.get("err", 0) is None:
            return
        if error["err"] == "not master":
            self._reset()
        raise OperationFailure(error["err"])
Example #6
0
    def _parse_response(self, response):
        callback = self.__callback
        request_id = self.__request_id
        self.__request_id = None
        self.__callback = None
        if not self.__job_queue:
            # skip adding to the cache because there is something else
            # that needs to be called on this connection for this request
            # (ie: we authenticated, but still have to send the real req)
            self.__pool.cache(self)

        try:
            response = helpers._unpack_response(response, request_id) # TODO: pass tz_awar
        except Exception, e:
            logging.debug('error %s' % e)
            callback(None, e)
            return
Example #7
0
 def _parse_response(self, response):
     # logging.info('got data %r' % response)
     callback = self.__callback
     self.__callback = None
     if not self.__deferred_message:
         # skip adding to the cache because there is something else 
         # that needs to be called on this connection for this request
         # (ie: we authenticted, but still have to send the real req)
         self.__pool.cache(self)
     
     try:
         # TODO: pass tz_aware and as_class
         response = helpers._unpack_response(response)
     except Exception, e:
         logging.error('error %s' % e)
         callback(None, e)
         return
Example #8
0
    def _parse_response(self, response):
        callback = self.__callback
        request_id = self.__request_id
        self.__request_id = None
        self.__callback = None
        if not self.__job_queue:
            # skip adding to the cache because there is something else
            # that needs to be called on this connection for this request
            # (ie: we authenticated, but still have to send the real req)
            self.__pool.cache(self)

        try:
            response = helpers._unpack_response(
                response, request_id)  # TODO: pass tz_awar
        except Exception, e:
            logging.debug('error %s' % e)
            callback(None, e)
            return
Example #9
0
    def __send_message(self, message):
        """Send a query or getmore message and handles the response.
        """
        db = self.__collection.database()
        kwargs = {
            "_sock": self.__socket,
            "_must_use_master": self.__must_use_master
        }
        if self.__connection_id is not None:
            kwargs["_connection_to_use"] = self.__connection_id

        response = db.connection()._send_message_with_response(
            message, **kwargs)

        if isinstance(response, types.TupleType):
            (connection_id, response) = response
        else:
            connection_id = None

        self.__connection_id = connection_id

        try:
            response = helpers._unpack_response(response, self.__id)
        except AutoReconnect:
            db.connection()._reset()
            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()