diff options
author | Jan Cholasta <jcholast@redhat.com> | 2012-03-19 08:52:11 -0400 |
---|---|---|
committer | Martin Kosek <mkosek@redhat.com> | 2012-03-27 12:03:16 +0200 |
commit | 0024024897153d23ae446415612b7529ffb67fe2 (patch) | |
tree | 4d05305fb82530714c36cc76eaaaeedc0327d073 /ipapython | |
parent | 52aa008b8719f4ea678efa8957794bb6dcd13893 (diff) | |
download | freeipa-0024024897153d23ae446415612b7529ffb67fe2.tar.gz freeipa-0024024897153d23ae446415612b7529ffb67fe2.tar.xz freeipa-0024024897153d23ae446415612b7529ffb67fe2.zip |
Parse zone indices in IPv6 addresses in CheckedIPAddress.
If a zone index is present in an IPv6 address, it is ignored.
ticket 2138
Diffstat (limited to 'ipapython')
-rw-r--r-- | ipapython/ipautil.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/ipapython/ipautil.py b/ipapython/ipautil.py index d3bb38ab8..69c328934 100644 --- a/ipapython/ipautil.py +++ b/ipapython/ipautil.py @@ -97,7 +97,20 @@ class CheckedIPAddress(netaddr.IPAddress): pass else: try: - addr = netaddr.IPAddress(addr, flags=self.netaddr_ip_flags) + try: + addr = netaddr.IPAddress(addr, flags=self.netaddr_ip_flags) + except netaddr.AddrFormatError: + # netaddr.IPAddress doesn't handle zone indices in textual + # IPv6 addresses. Try removing zone index and parse the + # address again. + if not isinstance(addr, basestring): + raise + addr, sep, foo = addr.partition('%') + if sep != '%': + raise + addr = netaddr.IPAddress(addr, flags=self.netaddr_ip_flags) + if addr.version != 6: + raise except ValueError: net = netaddr.IPNetwork(addr, flags=self.netaddr_ip_flags) if not parse_netmask: |