add ip addrs validation

This commit is contained in:
Dmitry Belyaev 2024-02-21 09:41:51 +03:00
parent 0509ba9d63
commit 31564c22d5
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
2 changed files with 11 additions and 1 deletions

View File

@ -1,7 +1,8 @@
import httpx
import asyncio
from abc import ABC, abstractmethod
from typing import NamedTuple
from typing import NamedTuple, Optional
from netaddr import valid_ipv4, valid_ipv6
class IPAddreses(NamedTuple):
@ -154,3 +155,11 @@ class BaseFilterProvider(ABC):
@abstractmethod
async def check_imp(self, source_provider, addr_v4, addr_v6): ...
def filter_ipv4(value: str) -> Optional[str]:
return value and valid_ipv4(value) and value or None
def filter_ipv6(value: str) -> Optional[str]:
return value and valid_ipv6(value) and value or None

View File

@ -2,3 +2,4 @@ httpx[http2]>=0.26,<1.0
asyncio>=3.4.3,<4
aiofiles>=23,<24
toml>=0.10,<1
netaddr>=1,<2