'Helper function to add a multi-query to previously enumerated queries.
Args:
identifier: property being filtered by this condition
condition: filter condition (e.g. !=,in)
value: value being bound
enumerated_queries: in/out list of already bound queries -> expanded list
with the full enumeration required to satisfy the condition query
Raises:
BadArgumentError if the filter is invalid (namely non-list with IN)'

def __AddMultiQuery(self, identifier, condition, value, enumerated_queries):

    if ((condition.lower() in ('!=', 'in')) and self._keys_only):
        raise datastore_errors.BadQueryError('Keys    only    queries    do    not    support    IN    or    !=    filters.')
    def CloneQueries(queries, n):
        'Do    a    full    copy    of    the    queries    and    append    to    the    end    of    the    queries.\n\n                        Does    an    in-place    replication    of    the    input    list    and    sorts    the    result    to\n                        put    copies    next    to    one-another.\n\n                        Args:\n                                queries:    list    of    all    filters    to    clone\n                                n:    number    of    copies    to    make\n\n                        Returns:\n                                Number    of    iterations    needed    to    fill    the    structure\n                        '
        if (not enumerated_queries):
            for _ in xrange(n):
                queries.append({})
            return 1
        else:
            old_size = len(queries)
            tmp_queries = []
            for _ in xrange((n - 1)):
                [tmp_queries.append(filter_map.copy()) for filter_map in queries]
            queries.extend(tmp_queries)
            queries.sort()
            return old_size
    if (condition == '!='):
        if ((len(enumerated_queries) * 2) > self.MAX_ALLOWABLE_QUERIES):
            raise datastore_errors.BadArgumentError('Cannot    satisfy    query    --    too    many    IN/!=    values.')
        num_iterations = CloneQueries(enumerated_queries, 2)
        for i in xrange(num_iterations):
            enumerated_queries[(2 * i)][('%s    <' % identifier)] = value
            enumerated_queries[((2 * i) + 1)][('%s    >' % identifier)] = value
    elif (condition.lower() == 'in'):
        if (not isinstance(value, list)):
            raise datastore_errors.BadArgumentError('List    expected    for    "IN"    filter')
        in_list_size = len(value)
        if ((len(enumerated_queries) * in_list_size) > self.MAX_ALLOWABLE_QUERIES):
            raise datastore_errors.BadArgumentError('Cannot    satisfy    query    --    too    many    IN/!=    values.')
        if (in_list_size == 0):
            num_iterations = CloneQueries(enumerated_queries, 1)
            for clone_num in xrange(num_iterations):
                enumerated_queries[clone_num][_EMPTY_LIST_PROPERTY_NAME] = True
            return
        num_iterations = CloneQueries(enumerated_queries, in_list_size)
        for clone_num in xrange(num_iterations):
            for value_num in xrange(len(value)):
                list_val = value[value_num]
                query_num = ((in_list_size * clone_num) + value_num)
                filt = ('%s    =' % identifier)
                enumerated_queries[query_num][filt] = list_val
