Perform an index query on a table

        This uses the older version of the DynamoDB API.
        See also: :meth:`~.query2`.

        Parameters
        ----------
        tablename : str
            Name of the table to query
        attributes : list
            If present, only fetch these attributes from the item
        consistent : bool, optional
            Perform a strongly consistent read of the data (default False)
        count : bool, optional
            If True, return a count of matched items instead of the items
            themselves (default False)
        index : str, optional
            The name of the index to query
        limit : int, optional
            Maximum number of items to return
        desc : bool, optional
            If True, return items in descending order (default False)
        return_capacity : {NONE, INDEXES, TOTAL}, optional
            INDEXES will return the consumed capacity for indexes, TOTAL will
            return the consumed capacity for the table and the indexes.
            (default NONE)
        filter : dict, optional
            Query arguments. Same format as **kwargs, but these arguments
            filter the results on the server before they are returned. They
            will NOT use an index, as that is what the **kwargs are for.
        filter_or : bool, optional
            If True, multiple filter args will be OR'd together. If False, they
            will be AND'd together. (default False)
        exclusive_start_key : dict, optional
            The ExclusiveStartKey to resume a previous query
        **kwargs : dict, optional
            Query arguments (examples below)

        Examples
        --------
        You may pass in constraints using the Django-style '__' syntax. For
        example:

        .. code-block:: python

            connection.query('mytable', foo__eq=5)
            connection.query('mytable', foo__eq=5, bar__lt=22)
            connection.query('mytable', foo__eq=5, bar__between=(1, 10))

def query(self, tablename, attributes=None, consistent=False, count=False,
              index=None, limit=None, desc=False, return_capacity=None,
              filter=None, filter_or=False, exclusive_start_key=None, **kwargs):
        """
        Perform an index query on a table

        This uses the older version of the DynamoDB API.
        See also: :meth:`~.query2`.

        Parameters
        ----------
        tablename : str
            Name of the table to query
        attributes : list
            If present, only fetch these attributes from the item
        consistent : bool, optional
            Perform a strongly consistent read of the data (default False)
        count : bool, optional
            If True, return a count of matched items instead of the items
            themselves (default False)
        index : str, optional
            The name of the index to query
        limit : int, optional
            Maximum number of items to return
        desc : bool, optional
            If True, return items in descending order (default False)
        return_capacity : {NONE, INDEXES, TOTAL}, optional
            INDEXES will return the consumed capacity for indexes, TOTAL will
            return the consumed capacity for the table and the indexes.
            (default NONE)
        filter : dict, optional
            Query arguments. Same format as **kwargs, but these arguments
            filter the results on the server before they are returned. They
            will NOT use an index, as that is what the **kwargs are for.
        filter_or : bool, optional
            If True, multiple filter args will be OR'd together. If False, they
            will be AND'd together. (default False)
        exclusive_start_key : dict, optional
            The ExclusiveStartKey to resume a previous query
        **kwargs : dict, optional
            Query arguments (examples below)

        Examples
        --------
        You may pass in constraints using the Django-style '__' syntax. For
        example:

        .. code-block:: python

            connection.query('mytable', foo__eq=5)
            connection.query('mytable', foo__eq=5, bar__lt=22)
            connection.query('mytable', foo__eq=5, bar__between=(1, 10))

        """
        keywords = {
            'TableName': tablename,
            'ReturnConsumedCapacity': self._default_capacity(return_capacity),
            'ConsistentRead': consistent,
            'ScanIndexForward': not desc,
            'KeyConditions': encode_query_kwargs(self.dynamizer, kwargs),
        }
        if attributes is not None:
            keywords['AttributesToGet'] = attributes
        if index is not None:
            keywords['IndexName'] = index
        if filter is not None:
            if len(filter) > 1:
                keywords['ConditionalOperator'] = 'OR' if filter_or else 'AND'
            keywords['QueryFilter'] = encode_query_kwargs(self.dynamizer,
                                                          filter)
        if exclusive_start_key is not None:
            keywords['ExclusiveStartKey'] = \
                self.dynamizer.maybe_encode_keys(exclusive_start_key)
        if not isinstance(limit, Limit):
            limit = Limit(limit)
        if count:
            keywords['Select'] = COUNT
            return self._count('query', limit, keywords)
        else:
            return ResultSet(self, limit, 'query', **keywords)