<commit_before>""" DNS wrapper that takes the user options into consideration
when performing queries"""

import struct
import logging
import datetime
from dateutil import relativedelta

import dns
import dns.resolver
import dns.reversename


class DNSInterface(object):
    """Interface for various dns related actions"""

    def __init__(self):
        self.log = logging.getLogger("pad-logger")
        self._resolver = dns.resolver.Resolver()
        self.restrictions = {}
        self.test_qnames = []
        self.retest = datetime.datetime.now()
        self._test_interval = None
        self.dns_available = True
        self.test = False
        self._resolver.edns = 0
        self._resolver.rotate = False

    @property
    def port(self):
        return self._resolver.port

    @port.setter
    def port(self, port):
        self._resolver.port = port

    @property
    def rotate_nameservers(self):
        return self._resolver.rotate

    @rotate_nameservers.setter
    def rotate_nameservers(self, rotate):
        self._resolver.rotate = rotate == "rotate"

    @property
    def edns(self):
        return bool(self._resolver.payload)

    @edns.setter
    def edns(self, value):
        if value.startswith("no"):
            self._resolver.payload = 512
        else:
            self._resolver.payload = int(value.split("=", 1)[1])

    @property
    def test_interval(self):
        return self._test_interval

    @test_interval.setter
    def test_interval(self, value):
        "Set the test_interval as relative delta object"
        if value.endswith("s"):
            self._test_interval = relativedelta(seconds=int(value[:-1]))
        elif value.endswith("m"):
            self._test_interval = relativedelta(minutes=int(value[:-1]))
        elif value.endswith("h"):
            self._test_interval = relativedelta(hours=int(value[:-1]))
        elif value.endswith("d"):
            self._test_interval = relativedelta(days=int(value[:-1]))
        elif value.endswith("w"):
            self._test_interval = relativedelta(weeks=int(value[:-1]))
        else:
            self._test_interval = relativedelta(seconds=int(value))

    @property
    def nameservers(self):
        "get the nameservers from the resolver"
        return self._resolver.nameservers

    @nameservers.setter
    def namerservers(self, nameservers):
        "set the nameservers for the resolver"
        self._resolver.nameservers = nameservers<commit_msg>Refs #40 switch dateutil.relativedelta with datetime.timedelta<commit_after>""" DNS wrapper that takes the user options into consideration
when performing queries"""

import struct
import logging
import datetime

import dns
import dns.resolver
import dns.reversename


class DNSInterface(object):
    """Interface for various dns related actions"""

    def __init__(self):
        self.log = logging.getLogger("pad-logger")
        self._resolver = dns.resolver.Resolver()
        self.restrictions = {}
        self.test_qnames = []
        self.retest = datetime.datetime.now()
        self._test_interval = None
        self.dns_available = True
        self.test = False
        self._resolver.edns = 0
        self._resolver.rotate = False

    @property
    def port(self):
        return self._resolver.port

    @port.setter
    def port(self, port):
        self._resolver.port = port

    @property
    def rotate_nameservers(self):
        return self._resolver.rotate

    @rotate_nameservers.setter
    def rotate_nameservers(self, rotate):
        self._resolver.rotate = rotate == "rotate"

    @property
    def edns(self):
        return bool(self._resolver.payload)

    @edns.setter
    def edns(self, value):
        if value.startswith("no"):
            self._resolver.payload = 512
        else:
            self._resolver.payload = int(value.split("=", 1)[1])

    @property
    def test_interval(self):
        return self._test_interval

    @test_interval.setter
    def test_interval(self, value):
        "Set the test_interval as relative delta object"
        if value.endswith("s"):
            self._test_interval = datetime.timedelta(seconds=int(value[:-1]))
        elif value.endswith("m"):
            self._test_interval = datetime.timedelta(minutes=int(value[:-1]))
        elif value.endswith("h"):
            self._test_interval = datetime.timedelta(hours=int(value[:-1]))
        elif value.endswith("d"):
            self._test_interval = datetime.timedelta(days=int(value[:-1]))
        elif value.endswith("w"):
            self._test_interval = datetime.timedelta(weeks=int(value[:-1]))
        else:
            self._test_interval = relativedelta(seconds=int(value))

    @property
    def nameservers(self):
        "get the nameservers from the resolver"
        return self._resolver.nameservers

    @nameservers.setter
    def namerservers(self, nameservers):
        "set the nameservers for the resolver"
        self._resolver.nameservers = nameservers
{'fraction_non_alphanumeric': 0.10600281068058623, 'fraction_numerical': 0.004818309576390283, 'mean_word_length': 2.6659308314937453, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1737039', 'n_tokens_mistral': 1513, 'n_tokens_neox': 1461, 'n_words': 318}