timmerk / ipaddr-py

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

IPv4Network __getitem__ does not return update network ips when IPv4Network.ip is changed #101

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
To reproduce the problem
>>> from ipaddr import IPv4Network, IPv4Address
>>> n = IPv4Network("192.168.1.134/24")
>>> n[0]
IPv4Address('192.168.1.0')
>>> n.ip = IPv4Address("10.10.1.34")
>>> n.ip
IPv4Address('10.10.1.34')
>>> n[0]
IPv4Address('192.168.1.0')

I would expect that after changing the ip of an IPv4Network instance the 
network would also be updated. This behaviour is "somewhat" true when changing 
the netmask.

As you can see from the example below:
>>> from ipaddr import IPv4Network, IPv4Address
>>> n = IPv4Network("192.168.34.45/24")
>>> n.netmask = IPv4Address("255.255.0.0")
>>> n[0]
IPv4Address('192.168.0.0')

When __getitem__ is used initially it returns the correct result. Any 
subsequent call though produces faulty results

>>> n.netmask = IPv4Address("255.255.255.0")
>>> n[0]
IPv4Address('192.168.0.0')

Platform: Debian wheezy
Version: 2.1.10-1

Original issue reported on code.google.com by pantelis...@gmail.com on 14 Feb 2013 at 3:29