]> git.mxchange.org Git - fba.git/blobdiff - fba/helpers/cookies.py
Continued:
[fba.git] / fba / helpers / cookies.py
index b40b68bd74bb60c1ec76715dd1e3156405dd07bc..c01294193ac1593e0b7171e3c2881381b7e1367b 100644 (file)
@@ -16,7 +16,7 @@
 
 import logging
 
-import validators
+from fba.helpers import domain as domain_helper
 
 logging.basicConfig(level=logging.INFO)
 logger = logging.getLogger(__name__)
@@ -25,20 +25,9 @@ logger = logging.getLogger(__name__)
 _cookies = {}
 
 def store (domain: str, cookies: dict):
-    logger.debug(f"domain='{domain}',cookies()={len(cookies)} - CALLED!")
-    if not isinstance(domain, str):
-        raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
-    elif domain == "":
-        raise ValueError("Parameter 'domain' is empty")
-    elif domain.lower() != domain:
-        raise ValueError(f"Parameter domain='{domain}' must be all lower-case")
-    elif not validators.domain(domain.split("/")[0]):
-        raise ValueError(f"domain='{domain}' is not a valid domain")
-    elif domain.endswith(".arpa"):
-        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
-    elif domain.endswith(".tld"):
-        raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
-    elif not isinstance(cookies, dict):
+    logger.debug("domain='%s',cookies()=%d - CALLED!", domain, len(cookies))
+    domain_helper.raise_on(domain)
+    if not isinstance(cookies, dict):
         raise ValueError(f"Parameter cookies[]='{type(cookies)}' is not 'dict'")
 
     _cookies[domain] = cookies
@@ -47,19 +36,8 @@ def store (domain: str, cookies: dict):
 
 def get_all(domain: str) -> dict:
     logger.debug("domain(%d)='%s' - CALLED!", len(domain), domain)
-    if not isinstance(domain, str):
-        raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
-    elif domain == "":
-        raise ValueError("Parameter 'domain' is empty")
-    elif domain.lower() != domain:
-        raise ValueError(f"Parameter domain='{domain}' must be all lower-case")
-    elif not validators.domain(domain.split("/")[0]):
-        raise ValueError(f"domain='{domain}' is not a valid domain")
-    elif domain.endswith(".arpa"):
-        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
-    elif domain.endswith(".tld"):
-        raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
-    elif not has(domain):
+    domain_helper.raise_on(domain)
+    if not has(domain):
         raise Exception(f"domain='{domain}' has no cookies stored, maybe invoke store() first?")
 
     logger.debug(f"_cookies[{domain}]()={len(_cookies[domain])} - EXIT!")
@@ -67,12 +45,7 @@ def get_all(domain: str) -> dict:
 
 def has (domain: str) -> bool:
     logger.debug("domain(%d)='%s' - CALLED!", len(domain), domain)
-    if not isinstance(domain, str):
-        raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
-    elif domain == "":
-        raise ValueError("Parameter 'domain' is empty")
-    elif domain.lower() != domain:
-        raise ValueError(f"Parameter domain='{domain}' must be all lower-case")
+    domain_helper.raise_on(domain)
 
     has_cookies = domain in _cookies
 
@@ -81,18 +54,7 @@ def has (domain: str) -> bool:
 
 def clear (domain: str):
     logger.debug("domain(%d)='%s' - CALLED!", len(domain), domain)
-    if not isinstance(domain, str):
-        raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
-    elif domain == "":
-        raise ValueError("Parameter 'domain' is empty")
-    elif domain.lower() != domain:
-        raise ValueError(f"Parameter domain='{domain}' must be all lower-case")
-    elif not validators.domain(domain.split("/")[0]):
-        raise ValueError(f"domain='{domain}' is not a valid domain")
-    elif domain.endswith(".arpa"):
-        raise ValueError(f"domain='{domain}' is a domain for reversed IP addresses, please don't crawl them!")
-    elif domain.endswith(".tld"):
-        raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
+    domain_helper.raise_on(domain)
 
     if has(domain):
         logger.debug(f"Removing cookies for domain='{domain}' ...")