Convert some 'str' arguments to 'dns.name.Name'

It seems to be required by dnspython.
This commit is contained in:
jeltz 2021-12-22 09:30:51 +01:00
parent 9ab7ac4814
commit 220f268fef
Signed by untrusted user: jeltz
GPG key ID: 800882B66C0C3326

24
main.py
View file

@ -1,6 +1,8 @@
#!/usr/bin/env python3
from dns import name, rdata, rdataclass, rdatatype
import dns
from dns import rdata, rdataclass, rdatatype
from dns.zone import Zone
from dns.rdtypes.ANY import CNAME, MX, NS, SOA, TXT
from dns.rdtypes.IN import A, AAAA
@ -13,7 +15,7 @@ SOA_EXPIRE_TIME = 3600000
SOA_TIME_TO_LIVE = 10800
def format_rname(mail: str) -> name.Name:
def format_rname(mail: str) -> dns.name.Name:
"""
Given an email address in the standard string format `mail@example.tld`
return an email address in the format required by RFC 1035
@ -27,7 +29,7 @@ def format_rname(mail: str) -> name.Name:
"""
local, domain = mail.split("@")
rname = name.Name((local, *name.from_text(domain)))
rname = dns.name.Name((local, *dns.name.from_text(domain)))
return rname
@ -52,17 +54,25 @@ class IPv6Record(Record):
class CanonicalNameRecord(Record):
def __init__(self, name: str, address: str):
super().__init__(name, CNAME.CNAME(rdataclass.IN, rdatatype.CNAME, address))
super().__init__(
name,
CNAME.CNAME(rdataclass.IN, rdatatype.CNAME, dns.name.from_text(address)),
)
class MailExchangeRecord(Record):
def __init__(self, name: str, priority: int, exchange: str):
super().__init__(name, MX.MX(rdataclass.IN, rdatatype.MX, priority, exchange))
super().__init__(
name,
MX.MX(rdataclass.IN, rdatatype.MX, priority, dns.name.from_text(exchange)),
)
class NameServerRecord(Record):
def __init__(self, name: str, address: str):
super().__init__(name, NS.NS(rdataclass.IN, rdatatype.NS, address))
super().__init__(
name, NS.NS(rdataclass.IN, rdatatype.NS, dns.name.from_text(address))
)
class TextRecord(Record):
@ -87,7 +97,7 @@ class StartOfAuthorityRecord(Record):
SOA.SOA(
rdataclass.IN,
rdatatype.SOA,
address,
dns.name.from_text(address),
format_rname(rname),
serial,
refresh,