'Determine a response to a particular DNS query.
@param name: The name which is being queried and for which to lookup a
response.
@type name: L{bytes}
@param cls: The class which is being queried.  Only I{IN} is
implemented here and this value is presently disregarded.
@type cls: L{int}
@param type: The type of records being queried.  See the types defined
in L{twisted.names.dns}.
@type type: L{int}
@param timeout: All processing is done locally and a result is
available immediately, so the timeout value is ignored.
@return: A L{Deferred} that fires with a L{tuple} of three sets of
response records (to comprise the I{answer}, I{authority}, and
I{additional} sections of a DNS response) or with a L{Failure} if
there is a problem processing the query.'

def _lookup(self, name, cls, type, timeout=None):

    cnames = []
    results = []
    authority = []
    additional = []
    default_ttl = max(self.soa[1].minimum, self.soa[1].expire)
    domain_records = self.records.get(name.lower())
    if domain_records:
        for record in domain_records:
            if (record.ttl is not None):
                ttl = record.ttl
            else:
                ttl = default_ttl
            if ((record.TYPE == dns.NS) and (name.lower() != self.soa[0].lower())):
                authority.append(dns.RRHeader(name, record.TYPE, dns.IN, ttl, record, auth=False))
            elif ((record.TYPE == type) or (type == dns.ALL_RECORDS)):
                results.append(dns.RRHeader(name, record.TYPE, dns.IN, ttl, record, auth=True))
            if (record.TYPE == dns.CNAME):
                cnames.append(dns.RRHeader(name, record.TYPE, dns.IN, ttl, record, auth=True))
        if (not results):
            results = cnames
        additionalInformation = self._additionalRecords(results, authority, default_ttl)
        if cnames:
            results.extend(additionalInformation)
        else:
            additional.extend(additionalInformation)
        if ((not results) and (not authority)):
            authority.append(dns.RRHeader(self.soa[0], dns.SOA, dns.IN, ttl, self.soa[1], auth=True))
        return defer.succeed((results, authority, additional))
    elif dns._isSubdomainOf(name, self.soa[0]):
        return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
    else:
        return defer.fail(failure.Failure(error.DomainError(name)))
