

def __send_message(self, message):
    'Send a query or getmore message and handles the response.\n\n        If message is ``None`` this is an exhaust cursor, which reads\n        the next result batch off the exhaust socket instead of\n        sending getMore messages to the server.\n        '
    client = self.__collection.database.connection
    if message:
        kwargs = {
            '_must_use_master': self.__must_use_master,
        }
        kwargs['read_preference'] = self.__read_preference
        kwargs['tag_sets'] = self.__tag_sets
        kwargs['secondary_acceptable_latency_ms'] = self.__secondary_acceptable_latency_ms
        kwargs['exhaust'] = self.__exhaust
        if (self.__connection_id is not None):
            kwargs['_connection_to_use'] = self.__connection_id
        kwargs.update(self.__kwargs)
        try:
            res = client._send_message_with_response(message, **kwargs)
            (self.__connection_id, (response, sock, pool)) = res
            if self.__exhaust:
                self.__exhaust_mgr = _SocketManager(sock, pool)
        except AutoReconnect:
            self.__killed = True
            raise
    else:
        response = client._exhaust_next(self.__exhaust_mgr.sock)
    try:
        response = helpers._unpack_response(response, self.__id, self.__as_class, self.__tz_aware, self.__uuid_subtype, self.__compile_re)
    except CursorNotFound:
        self.__killed = True
        if (self.__query_flags & _QUERY_OPTIONS['tailable_cursor']):
            return
        raise
    except AutoReconnect:
        self.__killed = True
        client.disconnect()
        raise
    self.__id = response['cursor_id']
    if (not (self.__query_flags & _QUERY_OPTIONS['tailable_cursor'])):
        assert (response['starting_from'] == self.__retrieved), ('Result batch started from %s, expected %s' % (response['starting_from'], self.__retrieved))
    self.__retrieved += response['number_returned']
    self.__data = deque(response['data'])
    if (self.__limit and self.__id and (self.__limit <= self.__retrieved)):
        self.__die()
    if (self.__exhaust and (self.__id == 0)):
        self.__exhaust_mgr.close()

dataset/ETHPy150Open blynch/CloudMemeBackend/pymongo/cursor.py Cursor.__send_message/original