Message88711
> 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. |
|
Date |
User |
Action |
Args |
2009-06-02 05:20:05 | loewis | set | recipients:
+ loewis, gvanrossum, gregory.p.smith, Rhamphoryncus, pitrou, giampaolo.rodola, benjamin.peterson, ezio.melotti, mattsmart, shields, pmoody, pnasrat, r.david.murray, oubiwann, claymation |
2009-06-02 05:20:00 | loewis | link | issue3959 messages |
2009-06-02 05:19:51 | loewis | create | |
|