]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Fix grange.from_text()
authorMartin <martin.basti@gmail.com>
Sat, 2 Jul 2016 01:00:14 +0000 (03:00 +0200)
committerMartin <martin.basti@gmail.com>
Sat, 2 Jul 2016 01:00:14 +0000 (03:00 +0200)
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

index 01a3257b79d357b94c20bc677e5bbed5cf14e690..9ce9f67a09607dcde28571947929576cf94ecdc1 100644 (file)
@@ -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)