From 220f268feffc6fe2ba17cb66bb48ad0df6ab41c1 Mon Sep 17 00:00:00 2001 From: Jeltz Date: Wed, 22 Dec 2021 09:30:51 +0100 Subject: [PATCH] Convert some 'str' arguments to 'dns.name.Name' It seems to be required by dnspython. --- main.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/main.py b/main.py index 47f0145..cb6208e 100755 --- a/main.py +++ b/main.py @@ -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, -- 2.45.2