summaryrefslogtreecommitdiff
path: root/dns
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2020-07-21 10:40:51 -0700
committerBob Halley <halley@dnspython.org>2020-07-21 10:40:51 -0700
commit49d81afcc17f5d44c571a9e8724e83b009fe898b (patch)
tree48a12d6517c21e44594990951d67221c13e41be8 /dns
parent8c63cfd484a70097312acc368f7b10d80cd5ce87 (diff)
downloaddnspython-49d81afcc17f5d44c571a9e8724e83b009fe898b.tar.gz
set min ttl to max_ttl instead of special case -1
Diffstat (limited to 'dns')
-rw-r--r--dns/message.py9
-rw-r--r--dns/ttl.py3
2 files changed, 7 insertions, 5 deletions
diff --git a/dns/message.py b/dns/message.py
index 87484f5..fd9ddb5 100644
--- a/dns/message.py
+++ b/dns/message.py
@@ -35,6 +35,7 @@ import dns.rdataclass
import dns.rdatatype
import dns.rrset
import dns.renderer
+import dns.ttl
import dns.tsig
import dns.rdtypes.ANY.OPT
import dns.rdtypes.ANY.TSIG
@@ -735,14 +736,14 @@ class QueryMessage(Message):
raise dns.exception.FormError
question = self.question[0]
qname = question.name
- min_ttl = -1
+ min_ttl = dns.ttl.MAX_TTL
rrset = None
count = 0
while count < MAX_CHAIN:
try:
rrset = self.find_rrset(self.answer, qname, question.rdclass,
question.rdtype)
- if min_ttl == -1 or rrset.ttl < min_ttl:
+ if rrset.ttl < min_ttl:
min_ttl = rrset.ttl
break
except KeyError:
@@ -751,7 +752,7 @@ class QueryMessage(Message):
crrset = self.find_rrset(self.answer, qname,
question.rdclass,
dns.rdatatype.CNAME)
- if min_ttl == -1 or crrset.ttl < min_ttl:
+ if crrset.ttl < min_ttl:
min_ttl = crrset.ttl
for rd in crrset:
qname = rd.target
@@ -775,7 +776,7 @@ class QueryMessage(Message):
srrset = self.find_rrset(self.authority, auname,
question.rdclass,
dns.rdatatype.SOA)
- if min_ttl == -1 or srrset.ttl < min_ttl:
+ if srrset.ttl < min_ttl:
min_ttl = srrset.ttl
if srrset[0].minimum < min_ttl:
min_ttl = srrset[0].minimum
diff --git a/dns/ttl.py b/dns/ttl.py
index 55ae5e1..6c67d38 100644
--- a/dns/ttl.py
+++ b/dns/ttl.py
@@ -19,6 +19,7 @@
import dns.exception
+MAX_TTL = 2147483647
class BadTTL(dns.exception.SyntaxError):
"""DNS TTL value is not well-formed."""
@@ -64,6 +65,6 @@ def from_text(text):
current = 0
if not current == 0:
raise BadTTL("trailing integer")
- if total < 0 or total > 2147483647:
+ if total < 0 or total > MAX_TTL:
raise BadTTL("TTL should be between 0 and 2^31 - 1 (inclusive)")
return total