Catch exception in anonymize function
This commit is contained in:
parent
26b889d381
commit
2a3075d0fb
@ -29,10 +29,13 @@ def anonymize(remote_addr):
|
|||||||
ipv4 = ipaddress.IPv4Address(remote_addr)
|
ipv4 = ipaddress.IPv4Address(remote_addr)
|
||||||
return u''.join(ipv4.exploded.rsplit('.', 1)[0]) + '.' + '0'
|
return u''.join(ipv4.exploded.rsplit('.', 1)[0]) + '.' + '0'
|
||||||
except ipaddress.AddressValueError:
|
except ipaddress.AddressValueError:
|
||||||
|
try:
|
||||||
ipv6 = ipaddress.IPv6Address(remote_addr)
|
ipv6 = ipaddress.IPv6Address(remote_addr)
|
||||||
if ipv6.ipv4_mapped is not None:
|
if ipv6.ipv4_mapped is not None:
|
||||||
return anonymize(ipv6.ipv4_mapped)
|
return anonymize(ipv6.ipv4_mapped)
|
||||||
return u'' + ipv6.exploded.rsplit(':', 5)[0] + ':' + ':'.join(['0000']*5)
|
return u'' + ipv6.exploded.rsplit(':', 5)[0] + ':' + ':'.join(['0000']*5)
|
||||||
|
except ipaddress.AddressValueError:
|
||||||
|
return u'0.0.0.0'
|
||||||
|
|
||||||
|
|
||||||
class Bloomfilter:
|
class Bloomfilter:
|
||||||
|
Loading…
Reference in New Issue
Block a user