templates: add ip_in_networks test
This commit is contained in:
parent
79a21c20cb
commit
2a3bd36d3b
@ -7,4 +7,5 @@ app = MyQuartApp(__name__)
|
|||||||
__import__('capport.api.setup')
|
__import__('capport.api.setup')
|
||||||
__import__('capport.api.proxy_fix')
|
__import__('capport.api.proxy_fix')
|
||||||
__import__('capport.api.lang')
|
__import__('capport.api.lang')
|
||||||
|
__import__('capport.api.template_filters')
|
||||||
__import__('capport.api.views')
|
__import__('capport.api.views')
|
||||||
|
16
src/capport/api/template_filters.py
Normal file
16
src/capport/api/template_filters.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import ipaddress
|
||||||
|
import typing
|
||||||
|
|
||||||
|
from .app import app
|
||||||
|
|
||||||
|
|
||||||
|
@app.add_template_test
|
||||||
|
def ip_in_networks(ip_s: str, networks: typing.Iterable[str]) -> bool:
|
||||||
|
ip = ipaddress.ip_address(ip_s)
|
||||||
|
for network in networks:
|
||||||
|
net = ipaddress.ip_network(network)
|
||||||
|
if ip in net:
|
||||||
|
return True
|
||||||
|
return False
|
Loading…
Reference in New Issue
Block a user