TTL or the specified TTL. If the set contains no rdatas, set the TTL
to the specified TTL.
- *ttl*, an ``int``.
+ *ttl*, an ``int`` or ``str``.
"""
-
+ ttl = dns.ttl.make(ttl)
if len(self) == 0:
self.ttl = ttl
elif ttl < self.ttl:
if total < 0 or total > MAX_TTL:
raise BadTTL("TTL should be between 0 and 2^31 - 1 (inclusive)")
return total
+
+
+def make(value):
+ if isinstance(value, int):
+ return value
+ elif isinstance(value, str):
+ return dns.ttl.from_text(value)
+ else:
+ raise ValueError('cannot convert value to TTL')
import dns.rdtypes.ANY.RRSIG
import dns.rdtypes.util
import dns.tokenizer
+import dns.ttl
import dns.wire
import tests.stxt_module
dns.rdata.from_text(dns.rdataclass.IN, dns.rdatatype.MX,
r'\# 4 000aC000')
+ def test_rdataset_ttl_conversion(self):
+ rds1 = dns.rdataset.from_text('in', 'a', 300, '10.0.0.1')
+ self.assertEqual(rds1.ttl, 300)
+ rds2 = dns.rdataset.from_text('in', 'a', '5m', '10.0.0.1')
+ self.assertEqual(rds2.ttl, 300)
+ with self.assertRaises(ValueError):
+ dns.rdataset.from_text('in', 'a', 1.6, '10.0.0.1')
+ with self.assertRaises(dns.ttl.BadTTL):
+ dns.rdataset.from_text('in', 'a', '10.0.0.1', '10.0.0.2')
+
+
if __name__ == '__main__':
unittest.main()