Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8536371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T10:38:51+00:00 2026-06-11T10:38:51+00:00

Specifically, what happens in the _lookup call under the authority.FileAuthority class, and how does

  • 0

Specifically, what happens in the _lookup call under the authority.FileAuthority class, and how does it return results? This is one of the undocumented areas of Names.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T10:38:52+00:00Added an answer on June 11, 2026 at 10:38 am

    The following is a commented version of the FileAuthority._lookup call in the authority.py file of Twisted Names 11.1 . This method is responsible for synchronously searching over DNS information that has been indexed from BIND zonefiles, Python zonefiles, etc.

    def _lookup(self, name, cls, type, timeout = None):
        """Return a list of results.
        name: Queried host name.
        cls: An enum of the query class. See dns.py:
    
            IN, CS, CH, HS = range(1, 5)
    
            QUERY_CLASSES = {
                IN: 'IN',
                CS: 'CS',
                CH: 'CH',
                HS: 'HS',
                ANY: 'ANY'
            }
    
        type: The type of record to search for (or ANY/255 for any and all). 
              See dns.py:
    
            (A, NS, MD, MF, CNAME, SOA, MB, MG, MR, NULL, WKS, PTR, HINFO, MINFO, MX, TXT,
             RP, AFSDB) = range(1, 19)
            AAAA = 28
            SRV = 33
            NAPTR = 35
            A6 = 38
            DNAME = 39
            SPF = 99
    
            QUERY_TYPES = {
                A: 'A',
                NS: 'NS',
                MD: 'MD',
                MF: 'MF',
                CNAME: 'CNAME',
                SOA: 'SOA',
                MB: 'MB',
                MG: 'MG',
                MR: 'MR',
                NULL: 'NULL',
                WKS: 'WKS',
                PTR: 'PTR',
                HINFO: 'HINFO',
                MINFO: 'MINFO',
                MX: 'MX',
                TXT: 'TXT',
                RP: 'RP',
                AFSDB: 'AFSDB',
    
                # 19 through 27?  Eh, I'll get to 'em.
    
                AAAA: 'AAAA',
                SRV: 'SRV',
                NAPTR: 'NAPTR',
                A6: 'A6',
                DNAME: 'DNAME',
                SPF: 'SPF'
            }
    
        timeout: The retention time for this record, in seconds.
        """
        cnames = []
        results = []
        authority = []
        additional = []
        default_ttl = max(self.soa[1].minimum, self.soa[1].expire)
    
        # Do records search. Get a list of classes like Record_A and Record_MX 
        # back. These are defined in dns.py .
        domain_records = self.records.get(name.lower())
    
        # Structure the results so as to present them the way that DNS records 
        # usually come back.
    
        if domain_records:
            # Loop through all of the results.
            for record in domain_records:
                if record.ttl is not None:
                    ttl = record.ttl
                else:
                    ttl = default_ttl
    
                # If we're looking at a [subdomain?] NS record, note it.
                if record.TYPE == dns.NS and name.lower() != self.soa[0].lower():
                    # NS record belong to a child zone: this is a referral.  As
                    # NS records are authoritative in the child zone, ours here
                    # are not.  RFC 2181, section 6.1.
                    authority.append(
                        dns.RRHeader(name, record.TYPE, dns.IN, ttl, record, auth=False)
                    )
    
                # Was the record what was requested, or did we want everything?
                elif record.TYPE == type or type == dns.ALL_RECORDS:
                    results.append(
                        dns.RRHeader(name, record.TYPE, dns.IN, ttl, record, auth=True)
                    )
    
                # If we're looking at a CNAME record, note it.
                if record.TYPE == dns.CNAME:
                    cnames.append(
                        dns.RRHeader(name, record.TYPE, dns.IN, ttl, record, auth=True)
                    )
    
            # If no requested records were found, use the CNAME records (if any).
            if not results:
                results = cnames
    
            # Go through any NS, CNAME, or MX records found, and find the IPs 
            # for those hosts.
            #
            # NOTE: The "additional" list doesn't appear to be populated.
            for record in results + authority:
                section = {dns.NS: additional, dns.CNAME: results, dns.MX: additional}.get(record.type)
                if section is not None:
                    n = str(record.payload.name)
                    for rec in self.records.get(n.lower(), ()):
                        if rec.TYPE == dns.A:
                            section.append(
                                dns.RRHeader(n, dns.A, dns.IN, rec.ttl or default_ttl, rec, auth=True)
                            )
    
            # Not found. Return an SOA record with the name that was requested 
            # (the normal response that you'll see at the console).
            if not results and not authority:
                # Empty response. Include SOA record to allow clients to cache
                # this response.  RFC 1034, sections 3.7 and 4.3.4, and RFC 2181
                # section 7.1.
                authority.append(
                    dns.RRHeader(self.soa[0], dns.SOA, dns.IN, ttl, self.soa[1], auth=True)
                    )
    
            # We return a tuple of individual result lists. Each of the records 
            # is an instance of RRHeader, which wraps the Record_* classes in 
            # dns.py for returning as a result (Resource Record). 
            #
            # The first item in the tuple refers to the "ANSWER SECTION" in the 
            # DiG output, and the third item refers to the "ADDITIONAL 
            # SECTION". As "authority" was an empty list in the example, no 
            # output relates to it. It will have NS records if any are present, 
            # or contain an SOA record for what was requested if nothing was 
            # found.
            # 
            #;; QUESTION SECTION:
            #;example-domain.com.            IN      ANY
            #
            #;; ANSWER SECTION:
            #example-domain.com.     3600    IN      SOA     ns1.example-domain.com. root.example-domain.com. 2003010601 3600 3600 3600 3600
            #example-domain.com.     3600    IN      A       127.9.9.9
            #example-domain.com.     3600    IN      NS      ns1.example-domain.com.
            #example-domain.com.     3600    IN      MX      0 mail.example-domain.com.
            #
            #;; ADDITIONAL SECTION:
            #mail.example-domain.com. 3600   IN      A       123.0.16.43
    
            return defer.succeed((results, authority, additional))
        else:
            if name.lower().endswith(self.soa[0].lower()):
                # We are the authority and we didn't find it.  Goodbye.
                return defer.fail(failure.Failure(dns.AuthoritativeDomainError(name)))
            return defer.fail(failure.Failure(dns.DomainError(name)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In OpenGL (specifically ES 2.0 in this case), what happens if I pass 2
I'm at a loss! It's one of those pesky bugs that happens only under
Specifically: I have a Schedule model where a person cans schedule one event per
Specifically, Python is unable to find SQL Alchemy. Running easy_install does not help, as
I was wondering specifically about whether ItemCreated or ItemBound happens first but I can't
If a finally block throws an exception, what exactly happens? Specifically, what happens if
Update: this question is specifically about protecting (encipher / obfuscate) the content client side
I would like to know what happens under the hood with regards to C++
How can I access a user's call log while developing with Trigger.io? Specifically, I
I'm trying to understand how the Java class loader works, specifically the defineClass(String,byte[],int,int) method.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.