]> git.mxchange.org Git - fba.git/blobdiff - fba/helpers/cookies.py
Continued:
[fba.git] / fba / helpers / cookies.py
index 09d8034106e57818414e223cc41738f2db00eb69..a42ce2febe6e5f730973c4c6311ae5eac4e58c9b 100644 (file)
 # You should have received a copy of the GNU Affero General Public License
 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
 
+import logging
+
 import validators
 
+logging.basicConfig(level=logging.INFO)
+logger = logging.getLogger(__name__)
+
 # Cookies stor
 _cookies = {}
 
 def store (domain: str, cookies: dict):
-    # DEBUG: print(f"DEBUG: domain='{domain}',cookies()={len(cookies)} - CALLED!")
+    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 == "":
@@ -38,10 +43,10 @@ def store (domain: str, cookies: dict):
 
     _cookies[domain] = cookies
 
-    # DEBUG: print(f"DEBUG: EXIT!")
+    logger.debug(f"EXIT!")
 
 def get_all(domain: str) -> dict:
-    # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
+    logger.debug(f"domain='{domain}' - CALLED!")
     if not isinstance(domain, str):
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
@@ -57,11 +62,11 @@ def get_all(domain: str) -> dict:
     elif not has(domain):
         raise Exception(f"domain='{domain}' has no cookies stored, maybe invoke store() first?")
 
-    # DEBUG: print(f"DEBUG: _cookies[{domain}]()={len(_cookies[domain])} - EXIT!")
+    logger.debug(f"_cookies[{domain}]()={len(_cookies[domain])} - EXIT!")
     return _cookies[domain]
 
 def has (domain: str) -> bool:
-    # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
+    logger.debug(f"domain='{domain}' - CALLED!")
     if not isinstance(domain, str):
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
@@ -71,11 +76,11 @@ def has (domain: str) -> bool:
 
     has_cookies = domain in _cookies
 
-    # DEBUG: print(f"DEBUG: has_cookies='{has_cookies}' - EXIT!")
+    logger.debug(f"has_cookies='{has_cookies}' - EXIT!")
     return has_cookies
 
 def clear (domain: str):
-    # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
+    logger.debug(f"domain='{domain}' - CALLED!")
     if not isinstance(domain, str):
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
@@ -90,7 +95,7 @@ def clear (domain: str):
         raise ValueError(f"domain='{domain}' is a fake domain, please don't crawl them!")
 
     if has(domain):
-        # DEBUG: print(f"DEBUG: Removing cookies for domain='{domain}' ...")
+        logger.debug(f"Removing cookies for domain='{domain}' ...")
         del _cookies[domain]
 
-    # DEBUG: print(f"DEBUG: EXIT!")
+    logger.debug(f"EXIT!")