[Python-Dev] PEP 3144 review.
Steven D'Aprano
steve at pearwood.info
Sun Sep 27 04:05:18 CEST 2009
On Sat, 26 Sep 2009 11:23:14 pm Barry Scott wrote:
> I've seen user interfaces accept 192.168.1.1/24 as a short cut
> to set the ipaddr and netmask on an interface.
>
> For that use being able to parse that string into an IP Address and
> a Net Mask is what they want.
I think you're at least the second person who has requested this
functionality, or something similar.
> If this is a common idiom having a utility function that returned
> an IPv4Address('192.168.1.1') and IPv4Network('192.168.0.0')
> would be useful.
>
> If someone really thinks that '192.168.1.1/16' is a network any
> good UI should detect it is invalid report that to the user.
Currently the ipaddr module accepts that without complaint:
>>> ipaddr.IPv4Network('192.168.1.1/16')
IPv4Network('192.168.1.1/16')
The current behaviour is confusing to me. For example:
>>> netw1 = ipaddr.IPv4Network('192.168.1.1/24')
>>> netw2 = ipaddr.IPv4Network('192.168.1.0/24')
>>> netw1 == netw2
False
>>> list(netw1) == list(netw2)
True
Two networks, containing exactly the same range of addresses, but they
don't compare equal. I'm not convinced that netw1 should even be
allowed, but if it is, surely it should be turned into canonical form
netw2? E.g. I would expect this:
>>> ipaddr.IPv4Network('192.168.1.1/24')
IPv4Network('192.168.1.0/24')
but that's not what it does.
--
Steven D'Aprano
More information about the Python-Dev
mailing list