<commit_before>"""
DNS lookup methods for dnstest.py

"""


import DNS


def resolve_name(query, to_server, to_port=53):
    """
    Resolves a single name against the given server
    """

    # first try an A record
    s = DNS.Request(name=query, server=to_server, qtype='A', port=to_port)
    a = s.req()
    if len(a.answers) > 0:
        return {'answer': a.answers[0]}

    # if that didnt work, try a CNAME
    s = DNS.Request(name=query, server=to_server, qtype='CNAME', port=to_port)
    a = s.req()
    if len(a.answers) > 0:
        return {'answer': a.answers[0]}
    return {'status': a.header['status']}


def lookup_reverse(name, to_server, to_port=53):
    "convenience routine for doing a reverse lookup of an address"
    a = name.split('.')
    a.reverse()
    b = '.'.join(a) + '.in-addr.arpa'

    s = DNS.Request(name=b, server=to_server, qtype='PTR', port=to_port)
    a = s.req()
    if len(a.answers) > 0:
        return {'answer': a.answers[0]}
    return {'status': a.header['status']}
<commit_msg>refactor dnstest_dns as a class<commit_after>"""
DNS lookup methods for dnstest.py

"""


import DNS


class DNStestDNS:


    def resolve_name(query, to_server, to_port=53):
        """
        Resolves a single name against the given server
        """

        # first try an A record
        s = DNS.Request(name=query, server=to_server, qtype='A', port=to_port)
        a = s.req()
        if len(a.answers) > 0:
            return {'answer': a.answers[0]}

        # if that didnt work, try a CNAME
        s = DNS.Request(name=query, server=to_server, qtype='CNAME', port=to_port)
        a = s.req()
        if len(a.answers) > 0:
            return {'answer': a.answers[0]}
        return {'status': a.header['status']}


    def lookup_reverse(self, name, to_server, to_port=53):
        """
        convenience routine for doing a reverse lookup of an address
        """
        a = name.split('.')
        a.reverse()
        b = '.'.join(a) + '.in-addr.arpa'

        s = DNS.Request(name=b, server=to_server, qtype='PTR', port=to_port)
        a = s.req()
        if len(a.answers) > 0:
            return {'answer': a.answers[0]}
        return {'status': a.header['status']}

{'fraction_non_alphanumeric': 0.15238954012623984, 'fraction_numerical': 0.009017132551848512, 'mean_word_length': 2.522222222222222, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '862279', 'n_tokens_mistral': 815, 'n_tokens_neox': 770, 'n_words': 201}