def get_query_object(generator, query_type='xotl.ql.core.QueryObject',
    frame_type=None, **kwargs):
    """Get the query object from a query expression.

    """
    from xoutil.objects import import_object
    from xotl.ql.revenge import Uncompyled
    uncompiled = Uncompyled(generator)
    gi_frame = generator.gi_frame
    QueryObjectType = import_object(query_type)
    FrameType = import_object(frame_type or QueryObjectType.frame_type)
    return QueryObjectType(uncompiled.qst, FrameType(gi_frame.f_locals,
        gi_frame.f_globals), expression=generator, **kwargs)
