timmerk / python-iptools

Automatically exported from code.google.com/p/python-iptools
BSD 2-Clause "Simplified" License
0 stars 0 forks source link

IpRangeList method does not work for IP range tuples #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Using an IP range with iptools.IpRangeList
2.
3.

What is the expected output? What do you see instead?

Well, I use __iter__ so it would be the IP addresses that are in that
range. I get an exception instead. Here is the output as shown in pythons
interactive mode. Same thing happens with 2.6.

>>> INTERNAL_IPS = iptools.IpRangeList('1.2.3.4',
('192.168.1.20','192.168.1.60'), '192.168.0.12/24')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File
"/usr/lib/python2.4/site-packages/iptools-0.2-py2.4.egg/iptools/__init__.py",
line 490, in __init__
    self.ips = tuple(map(IpRange, args))
  File
"/usr/lib/python2.4/site-packages/iptools-0.2-py2.4.egg/iptools/__init__.py",
line 376, in __init__
    if validate_cidr(start):
  File
"/usr/lib/python2.4/site-packages/iptools-0.2-py2.4.egg/iptools/__init__.py",
line 156, in validate_cidr
    if _CIDR_RE.match(s):
TypeError: expected string or buffer

The example on the page also fails:

http://code.google.com/p/python-iptools/wiki/DjangoSettings

What version of the product are you using? On what operating system?

I'm not sure but I think you mean iptools, and that's version 0.2. I'm
using python 2.4.3 and python 2.6.1 on CentOS 5 x86.

Please provide any additional information below.

I hope thats enough. I do have a request, perhaps see if this can be part
of the standard python library? It would be nice.

Thanks!

Original issue reported on code.google.com by cimmeri...@gmail.com on 2 Jan 2010 at 4:48

GoogleCodeExporter commented 9 years ago
Hello, not sure if you all are familiar with contextual diffs. But I basically 
put a
check in CIDR. If it's a tuple, it's not a CIDR IP. Well it could be, but that 
would
be silly. Then I don't know why your end = start(1), start = start(0) didn't 
work,
but I just set it at the same time and commented out the previous code.

--- /usr/lib/python2.4/site-packages/iptools-0.2-py2.4.egg/iptools/__init__.py 
2010-01-02 17:19:59.000000000 -0600
+++ __init__.py 2010-01-02 17:22:40.000000000 -0600
@@ -153,6 +153,10 @@
     Returns:
         True if str is a valid CIDR address, False otherwise
     """
+    # Quick check: If it's a tuple, toodles.
+    if isinstance(s, tuple):
+        return False
+
     if _CIDR_RE.match(s):
         ip, mask = s.split('/')
         if validate_ip(ip):
@@ -378,10 +382,12 @@
             start, end = cidr2block(start)

         elif end is None:
+            # This should work but it didn't. So I just set them both, once.
             if isinstance(start, tuple):
+                start, end = start
                 # tuple range
-                end = start(1)
-                start = start(0)
+                #end = start(1)
+                #start = start(0)
             else:
                 # degenerate range
                 end = start

Original comment by cimmeri...@gmail.com on 2 Jan 2010 at 11:28

GoogleCodeExporter commented 9 years ago
Apparently I never tested the tuple constructor. :(

Fixed in r15.

Original comment by casadebender on 4 Jan 2010 at 3:52