From 9fa94d066dd6600d85f53ead4210a324f4a9372d Mon Sep 17 00:00:00 2001 From: Martin Date: Sat, 2 Jul 2016 03:00:14 +0200 Subject: [PATCH] Fix grange.from_text() Would be possible to use regexp instead? Fixing this error from tests: ====================================================================== ERROR: testFailFromText2 (test_grange.GRangeTestCase) ---------------------------------------------------------------------- Traceback (most recent call last): File "~/dnspython/tests/test_grange.py", line 81, in testFailFromText2 self.assertRaises(dns.exception.SyntaxError, bad) File "/usr/lib64/python2.7/unittest/case.py", line 511, in assertRaises callableObj(*args, **kwargs) File "~/dnspython/tests/test_grange.py", line 80, in bad dns.grange.from_text('%s-%d/%d' % (start, stop, step)) File "~/dnspython/dns/grange.py", line 39, in from_text start = int(cur) ValueError: invalid literal for int() with base 10: '' --- dns/grange.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/dns/grange.py b/dns/grange.py index 01a3257b..9ce9f67a 100644 --- a/dns/grange.py +++ b/dns/grange.py @@ -34,6 +34,10 @@ def from_text(text): state = 0 # state 0 1 2 3 4 # x - y / z + + if text and text[0] == '-': + raise dns.exception.SyntaxError("Start cannot be a negative number") + for c in text: if c == '-' and state == 0: start = int(cur) @@ -49,7 +53,7 @@ def from_text(text): raise dns.exception.SyntaxError("Could not parse %s" % (c)) if state in (1, 3): - raise dns.exception.SyntaxError + raise dns.exception.SyntaxError() if state == 2: stop = int(cur) -- 2.47.3