]> git.mxchange.org Git - fba.git/blobdiff - fba/helpers/domain.py
Continued:
[fba.git] / fba / helpers / domain.py
index 00bf9384aee437d3d9b2fc715fa0ba0968584369..39fbb7797acee74c7c5207ed0b3b60c507276b2f 100644 (file)
@@ -16,6 +16,7 @@
 
 import logging
 
+from functools import lru_cache
 from urllib.parse import urlparse
 
 import validators
@@ -50,14 +51,19 @@ def raise_on(domain: str):
 
     logger.debug("EXIT!")
 
+@lru_cache
 def is_in_url(domain: str, url: str) -> bool:
     logger.debug("domain='%s',url='%s' - CALLED!", domain, url)
     raise_on(domain)
 
-    if not isinstance(url, str):
+    if blacklist.is_blacklisted(domain):
+        raise ValueError(f"domain='{domain}' is blacklisted but function was invoked")
+    elif not isinstance(url, str):
         raise ValueError(f"Parameter url[]='{type(url)}' is not of type 'str'")
     elif url == "":
         raise ValueError("Parameter 'url' is empty")
+    elif not validators.url(url):
+        raise ValueError(f"Parameter url='{url}' is not a valid URL")
 
     punycode = domain.encode("idna").decode("utf-8")
 
@@ -69,6 +75,7 @@ def is_in_url(domain: str, url: str) -> bool:
     logger.debug("is_found='%s' - EXIT!", is_found)
     return is_found
 
+@lru_cache
 def is_wanted(domain: str) -> bool:
     logger.debug("domain='%s' - CALLED!", domain)