timmerk / ipaddr-py

Automatically exported from code.google.com/p/ipaddr-py
0 stars 0 forks source link

__getitem__ does not accept slices #12

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
In [1]: import ipaddr

In [2]: ip = ipaddr.IP("172.16.1.0/24")

In [3]: ip[1:-2]

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)

/Users/pnasrat/Development/ipaddr-py-read-only/<ipython console> in <module>()

/Users/pnasrat/Development/ipaddr-py-read-only/ipaddr.pyc in
__getitem__(self, n)
    196   def __getitem__(self, n):
    197     if n >= 0:
--> 198       if self.network + n > self.broadcast:
    199         raise IndexError
    200       return self._StrFromIpInt(self.network + n)

TypeError: unsupported operand type(s) for +: 'long' and 'slice'

What is the expected output? 

A lis of IPs in the range 172.16.1.1 to 172.16.1.254 - as in [x for x in
ip] with network/broadcast skipped

What do you see instead?

TypeError: unsupported operand type(s) for +: 'long' and 'slice'

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

svn HEAD (r39)

Original issue reported on code.google.com by pnas...@gmail.com on 3 Jan 2009 at 5:54

GoogleCodeExporter commented 9 years ago
I believe ip[1:-2] should get you [IPv4('172.16.1.1/32') ... 
IPv4('172.16.1.253/32')]

http://codereview.appspot.com/11870/show

Original comment by pmo...@google.com on 6 Jan 2009 at 5:10

GoogleCodeExporter commented 9 years ago
to quote GvR.

"If the value returned might be too long to be comfortably stored in a
list, you probably shouldn't support slice syntax at all."

the problem is mostly when dealing with ipv6, eg, 
ipaddr.IPNetwork('::1/64')[:-1] 
takes a _long_ time to return.

Original comment by pmo...@google.com on 30 Aug 2009 at 1:02