This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author gregory.p.smith
Recipients Rhamphoryncus, benjamin.peterson, claymation, ezio.melotti, giampaolo.rodola, gregory.p.smith, gvanrossum, loewis, mattsmart, oubiwann, pitrou, pmoody, pnasrat, r.david.murray, shields
Date 2009-06-02.06:11:59
SpamBayes Score 0.0244331
Marked as misclassified No
Message-id <>
In-reply-to <>
> 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

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 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
Date User Action Args
2009-06-02 06:12:47gregory.p.smithsetrecipients: + 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:34gregory.p.smithlinkissue3959 messages
2009-06-02 06:12:25gregory.p.smithcreate