From: Brian Wellington Date: Fri, 26 Jun 2020 22:42:09 +0000 (-0700) Subject: Simplify code. X-Git-Tag: v2.0.0rc2~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=53e2a45f641ac72ec9cf476116ead69292828c4a;p=thirdparty%2Fdnspython.git Simplify code. There's no need to attach an attribute to the _TextReader/_WireReader classes; the code has access to the message. --- diff --git a/dns/message.py b/dns/message.py index 5aa3f52f..03d3f4ca 100644 --- a/dns/message.py +++ b/dns/message.py @@ -609,7 +609,7 @@ class Message: # What the caller picked is fine. return value - def _parse_rr_header(self, reader, section, rdclass, rdtype): + def _parse_rr_header(self, section, rdclass, rdtype): if dns.rdataclass.is_metaclass(rdclass): raise dns.exception.FormError return (rdclass, rdtype, None, False) @@ -678,8 +678,7 @@ class _WireReader: self.wire[self.current:self.current + 4]) self.current += 4 (rdclass, rdtype, _, _) = \ - self.message._parse_rr_header(self, section_number, - rdclass, rdtype) + self.message._parse_rr_header(section_number, rdclass, rdtype) self.message.find_rrset(section, qname, rdclass, rdtype, create=True, force_unique=True) @@ -753,7 +752,7 @@ class _WireReader: self.message.had_tsig = True else: (rdclass, rdtype, deleting, empty) = \ - self.message._parse_rr_header(self, section_number, + self.message._parse_rr_header(section_number, rdclass, rdtype) if empty: if rdlen > 0: @@ -991,7 +990,7 @@ class _TextReader: # Type rdtype = dns.rdatatype.from_text(token.value) (rdclass, rdtype, _, _) = \ - self.message._parse_rr_header(self, section_number, rdclass, rdtype) + self.message._parse_rr_header(section_number, rdclass, rdtype) self.message.find_rrset(section, name, rdclass, rdtype, create=True, force_unique=True) self.tok.get_eol() @@ -1035,7 +1034,7 @@ class _TextReader: # Type rdtype = dns.rdatatype.from_text(token.value) (rdclass, rdtype, deleting, empty) = \ - self.message._parse_rr_header(self, section_number, rdclass, rdtype) + self.message._parse_rr_header(section_number, rdclass, rdtype) token = self.tok.get() if empty and not token.is_eol_or_eof(): raise dns.exception.SyntaxError diff --git a/dns/update.py b/dns/update.py index e21a283e..9166ee5b 100644 --- a/dns/update.py +++ b/dns/update.py @@ -300,21 +300,20 @@ class UpdateMessage(dns.message.Message): # Updates are always one_rr_per_rrset return True - def _parse_rr_header(self, reader, section, rdclass, rdtype): + def _parse_rr_header(self, section, rdclass, rdtype): deleting = None empty = False if section == UpdateSection.ZONE: if dns.rdataclass.is_metaclass(rdclass) or \ rdtype != dns.rdatatype.SOA or \ - getattr(reader, 'zone_rdclass', None): + self.question: raise dns.exception.FormError - reader.zone_rdclass = rdclass else: - if not getattr(reader, 'zone_rdclass', None): + if not self.question: raise dns.exception.FormError if rdclass in (dns.rdataclass.ANY, dns.rdataclass.NONE): deleting = rdclass - rdclass = reader.zone_rdclass + rdclass = self.question[0].rdclass empty = (deleting == dns.rdataclass.ANY or section == UpdateSection.PREREQ) return (rdclass, rdtype, deleting, empty)