]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Simplify code.
authorBrian Wellington <bwelling@xbill.org>
Fri, 26 Jun 2020 22:42:09 +0000 (15:42 -0700)
committerBrian Wellington <bwelling@xbill.org>
Fri, 26 Jun 2020 22:42:09 +0000 (15:42 -0700)
There's no need to attach an attribute to the _TextReader/_WireReader
classes; the code has access to the message.

dns/message.py
dns/update.py

index 5aa3f52fabbf31a86ef9fdbc82f60bd89b8ce2ef..03d3f4ca0584b43eff8a4dcbdc229eed9326baba 100644 (file)
@@ -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
index e21a283e3ed60465d1fa6d85bc8ece092d6795d7..9166ee5bd907c02e60e1b7b04fa144f4960a2543 100644 (file)
@@ -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)