timmerk / ipaddr-py

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

Addition/Subtraction should be possible for IP Addresses and ints #57

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
>>> ipaddr.IPv4Address('10.10.3.126') + 2
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unsupported operand type(s) for +: 'IPv4Address' and 'int'

What is the expected output? What do you see instead?
>>> ipaddr.IPv4Address('10.10.3.64') + 1
IPv4Address('10.10.3.65')
>>> ipaddr.IPv4Address('10.10.3.126') + 1
IPv4Address('10.10.3.127')
>>> ipaddr.IPv4Address('10.10.3.126') + 2
IPv4Address('10.10.3.128')
>>> ipaddr.IPv4Address('10.10.3.65') - 1
IPv4Address('10.10.3.64')
>>> ipaddr.IPv4Address('10.10.3.65') - 2
IPv4Address('10.10.3.63')

What version of the product are you using? On what operating system?
>>> ipaddr.__version__
'2.1.1'

Please provide any additional information below.

I don't see a reason why addition/subtraction should be unsupported for 
IPV4Address (or IPv6Address) and int.

IP Addresses are "iterable" so addition should be something that works, 
also the opposite direction seems to me is well specified...

Original issue reported on code.google.com by michael....@gamigo.com on 5 Mar 2010 at 11:22

GoogleCodeExporter commented 9 years ago
I'm definitely in favour of this also.  When managing networks, it's quite 
common to
have an IP address that's network+1 or broadcast-1 as the router..  And since 
I'm
surely not the only person using this library to help manage subnets and IP
allocations, this is an important feature.

Original comment by Robert.M...@gmail.com on 3 Apr 2010 at 9:18

GoogleCodeExporter commented 9 years ago
fixed in r158

Original comment by pmo...@google.com on 4 Apr 2010 at 8:59