From 2a3075d0fb73026404a77b2f544f2f0f8b9a34aa Mon Sep 17 00:00:00 2001 From: Roland Szabo Date: Sun, 1 Feb 2015 17:30:35 +0100 Subject: [PATCH] Catch exception in anonymize function --- isso/utils/__init__.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/isso/utils/__init__.py b/isso/utils/__init__.py index 924e9a1..a7cafd5 100644 --- a/isso/utils/__init__.py +++ b/isso/utils/__init__.py @@ -29,10 +29,13 @@ def anonymize(remote_addr): ipv4 = ipaddress.IPv4Address(remote_addr) return u''.join(ipv4.exploded.rsplit('.', 1)[0]) + '.' + '0' except ipaddress.AddressValueError: - ipv6 = ipaddress.IPv6Address(remote_addr) - if ipv6.ipv4_mapped is not None: - return anonymize(ipv6.ipv4_mapped) - return u'' + ipv6.exploded.rsplit(':', 5)[0] + ':' + ':'.join(['0000']*5) + try: + ipv6 = ipaddress.IPv6Address(remote_addr) + if ipv6.ipv4_mapped is not None: + return anonymize(ipv6.ipv4_mapped) + return u'' + ipv6.exploded.rsplit(':', 5)[0] + ':' + ':'.join(['0000']*5) + except ipaddress.AddressValueError: + return u'0.0.0.0' class Bloomfilter: