def build_zone_qsets(zone):
    """The point of this filter is to first find the root of a dns zone
    specified by zone and then build a query to return all records in this
    zone.
    """
    try:
        root_domain = Domain.objects.get(name=zone)
        # This might not actually be the root of a zone, but functionally we
        # don't really care.
    except __HOLE__:
        raise BadDirective("'{0}' part of a valid zone.".format(zone))

    if not root_domain.soa:
        raise BadDirective("'{0}' part of a valid zone.".format(zone))

    def _get_zone_domains(domain):
        domains = [domain]
        for sub_domain in domain.domain_set.filter(soa=domain.soa):
            domains += _get_zone_domains(sub_domain)
        return domains

    domains = _get_zone_domains(root_domain)

    if root_domain.is_reverse:
        domains = [Q(reverse_domain=domain) for domain in domains]
    else:
        domains = [Q(domain=domain) for domain in domains]

    zone_query = reduce(operator.or_, domains, Q())

    result = []
    for name, Klass in searchables:
        if hasattr(Klass, 'domain') and not root_domain.is_reverse:
            result.append(zone_query)
        elif hasattr(Klass, 'reverse_domain') and root_domain.is_reverse:
            result.append(zone_query)
        elif name == 'SOA':
            result.append(Q(pk=root_domain.soa.pk))
        else:
            result.append(None)
    return result
dataset/ETHPy150Open rtucker-mozilla/mozilla_inventory/core/search/compiler/invfilter.py/build_zone_qsets