[issue3959] Add Google's ipaddr.py to the stdlib
Martin v. Löwis
report at bugs.python.org
Tue Jun 2 07:20:02 CEST 2009
Martin v. Löwis <martin at v.loewis.de> added the comment:
> Consider applications that need to validate addresses (or networks,
> but not both) supplied as user input:
>
> address = ipaddr.IP(input)
If that is a frequent need, it would be reasonable to add an API
address = ipaddr.IP(input, allow_mask=False)
which would raise an exception if a mask was specified (as an
old-style bit mask, or in CIDR form).
> if isinstance(address, ipaddr.IPv4):
> if address.prefixlen != 32:
> raise TypeError("Expecting IP address, not network")
> elif isinstance(address, ipaddr.IPv6):
> if address.prefixlen != 128:
> raise TypeError("Expecting IP address, not network")
With the current API, you don't need to write it in such a quirky
way. Instead
if address.numhosts != 1:
raise TypeError("Expecting IP address, not network")
would do as well.
> Given its myriad quirks
Well, you deliberately make it appear more quirky than it actually is.
----------
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3959>
_______________________________________
More information about the Python-bugs-list
mailing list