Small performance boost on ip validation with caching

This commit is contained in:
Karim shoair 2025-01-24 21:19:29 +02:00
parent e1fc678719
commit b5a248707e

View file

@ -62,10 +62,12 @@ class Proxy:
}
@lru_cache(128, typed=True)
def valid_ipv4(ip: str) -> bool:
return bool(re.match(r'^(?:[0-9]{1,3}\.){3}[0-9]{1,3}$', ip))
@lru_cache(128, typed=True)
def valid_ipv6(ip: str) -> bool:
return bool(re.match(r'^(([0-9a-fA-F]{0,4}:){1,7}[0-9a-fA-F]{0,4})$', ip))