if text.isdigit():
total = int(text)
+ elif len(text) == 0:
+ raise BadTTL
else:
- if not text[0].isdigit():
- raise BadTTL
total = 0
current = 0
+ need_digit = True
for c in text:
if c.isdigit():
current *= 10
current += int(c)
+ need_digit = False
else:
+ if need_digit:
+ raise BadTTL
c = c.lower()
if c == 'w':
total += current * 604800
else:
raise BadTTL("unknown unit '%s'" % c)
current = 0
+ need_digit = True
if not current == 0:
raise BadTTL("trailing integer")
if total < 0 or total > MAX_TTL:
def test_bind_style_no_unit(self):
with self.assertRaises(dns.ttl.BadTTL):
dns.ttl.from_text('1d5')
+
+ def test_bind_style_leading_unit(self):
+ with self.assertRaises(dns.ttl.BadTTL):
+ dns.ttl.from_text('s')
+
+ def test_bind_style_unit_without_digits(self):
+ with self.assertRaises(dns.ttl.BadTTL):
+ dns.ttl.from_text('1mw')
+
+ def test_empty(self):
+ with self.assertRaises(dns.ttl.BadTTL):
+ dns.ttl.from_text('')