1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-14 10:53:30 +02:00

Simplify extract_network_from_ip

This commit is contained in:
Florent Daigniere 2021-10-16 09:45:10 +02:00
parent 3bda8368e4
commit de276a6822

View File

@ -74,12 +74,10 @@ limiter = limiter.LimitWraperFactory()
def extract_network_from_ip(ip):
n = ipaddress.ip_network(ip)
if isinstance(n, ipaddress.IPv4Network):
if n.version == 4:
return str(n.supernet(prefixlen_diff=(32-int(app.config["AUTH_RATELIMIT_IP_V4_MASK"]))).network_address)
elif isinstance(n, ipaddress.IPv6Network):
else:
return str(n.supernet(prefixlen_diff=(128-int(app.config["AUTH_RATELIMIT_IP_V6_MASK"]))).network_address)
else: # not sure what to do with it
return ip
# Application translation
babel = flask_babel.Babel()