@utils.positional(<NUM_LIT:1>)<EOL>def _gql(query_string, query_class=Query):
from .google_imports import gql  <EOL>gql_qry = gql.GQL(query_string)<EOL>kind = gql_qry.kind()<EOL>if kind is None:<EOL><INDENT>modelclass = model.Expando<EOL><DEDENT>else:<EOL><INDENT>modelclass = model.Model._lookup_model(<EOL>kind,<EOL>tasklets.get_context()._conn.adapter.default_model)<EOL>kind = modelclass._get_kind()<EOL><DEDENT>ancestor = None<EOL>flt = gql_qry.filters()<EOL>filters = list(modelclass._default_filters())<EOL>for name_op in sorted(flt):<EOL><INDENT>name, op = name_op<EOL>values = flt[name_op]<EOL>op = op.lower()<EOL>if op == '<STR_LIT>' and name == gql.GQL._GQL__ANCESTOR:<EOL><INDENT>if len(values) != <NUM_LIT:1>:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>[(func, args)] = values<EOL>ancestor = _args_to_val(func, args)<EOL>continue<EOL><DEDENT>if op not in _OPS:<EOL><INDENT>raise NotImplementedError('<STR_LIT>' % op)<EOL><DEDENT>for (func, args) in values:<EOL><INDENT>val = _args_to_val(func, args)<EOL>prop = _get_prop_from_modelclass(modelclass, name)<EOL>if prop._name != name:<EOL><INDENT>raise RuntimeError('<STR_LIT>'<EOL>'<STR_LIT>' %<EOL>(modelclass.__name__, name, prop._name))<EOL><DEDENT>if isinstance(val, ParameterizedThing):<EOL><INDENT>node = ParameterNode(prop, op, val)<EOL><DEDENT>elif op == '<STR_LIT>':<EOL><INDENT>node = prop._IN(val)<EOL><DEDENT>else:<EOL><INDENT>node = prop._comparison(op, val)<EOL><DEDENT>filters.append(node)<EOL><DEDENT><DEDENT>if filters:<EOL><INDENT>filters = ConjunctionNode(*filters)<EOL><DEDENT>else:<EOL><INDENT>filters = None<EOL><DEDENT>orders = _orderings_to_orders(gql_qry.orderings(), modelclass)<EOL>offset = gql_qry.offset()<EOL>limit = gql_qry.limit()<EOL>if limit < <NUM_LIT:0>:<EOL><INDENT>limit = None<EOL><DEDENT>keys_only = gql_qry._keys_only<EOL>if not keys_only:<EOL><INDENT>keys_only = None<EOL><DEDENT>options = QueryOptions(offset=offset, limit=limit, keys_only=keys_only)<EOL>projection = gql_qry.projection()<EOL>if gql_qry.is_distinct():<EOL><INDENT>group_by = projection<EOL><DEDENT>else:<EOL><INDENT>group_by = None<EOL><DEDENT>qry = query_class(kind=kind,<EOL>ancestor=ancestor,<EOL>filters=filters,<EOL>orders=orders,<EOL>default_options=options,<EOL>projection=projection,<EOL>group_by=group_by)<EOL>return qry<EOL>
Parse a GQL query string (internal version).

    Args:
      query_string: Full GQL query, e.g. 'SELECT * FROM Kind WHERE prop = 1'.
      query_class: Optional class to use, default Query.

    Returns:
      An instance of query_class.