Martin v. Löwis <mar...@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 <rep...@bugs.python.org> <http://bugs.python.org/issue3959> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com