From: Martin Date: Sat, 2 Jul 2016 01:00:14 +0000 (+0200) Subject: Fix grange.from_text() X-Git-Tag: v1.15.0~40^2~13 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9fa94d066dd6600d85f53ead4210a324f4a9372d;p=thirdparty%2Fdnspython.git 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: '' --- 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)