Message88717
> Consider applications that need to validate addresses (or networks,
> but not both) supplied as user input:
>
> address = ipaddr.IP(input)
>
> 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")
Support for this can be added (its too late for Python 3.1). User
input validation is a good use case. For now I suggest the simpler
code:
if '/' in input:
raise TypeError("Expecting IP address")
address = ipaddr.IP(input)
Or for a more pedantic test prior to calling ipaddr.IP.
if re.match('^[0-9a-fA-F:.]+$', input):
raise TypeError("Invalid characters in IP address")
Please file a feature request on bugs.python.org for this one if you
haven't already. We could add optional parameter(s) to ipaddr.IP to
enable only accepting host addresses or network addresses in the
future. |
|
Date |
User |
Action |
Args |
2009-06-02 06:12:47 | gregory.p.smith | set | recipients:
+ gregory.p.smith, gvanrossum, loewis, Rhamphoryncus, pitrou, giampaolo.rodola, benjamin.peterson, ezio.melotti, mattsmart, shields, pmoody, pnasrat, r.david.murray, oubiwann, claymation |
2009-06-02 06:12:34 | gregory.p.smith | link | issue3959 messages |
2009-06-02 06:12:25 | gregory.p.smith | create | |
|