diff options
author | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-02-09 18:11:35 +0100 |
---|---|---|
committer | Heiner Lohaus <hlohaus@users.noreply.github.com> | 2024-02-09 18:11:35 +0100 |
commit | af204c31cb047436f4e1c36199e15692eb271f20 (patch) | |
tree | 809b00081d39e259b1523457840ddf512d05c1a0 /g4f/cookies.py | |
parent | Update OpenaiChat.py (diff) | |
download | gpt4free-af204c31cb047436f4e1c36199e15692eb271f20.tar gpt4free-af204c31cb047436f4e1c36199e15692eb271f20.tar.gz gpt4free-af204c31cb047436f4e1c36199e15692eb271f20.tar.bz2 gpt4free-af204c31cb047436f4e1c36199e15692eb271f20.tar.lz gpt4free-af204c31cb047436f4e1c36199e15692eb271f20.tar.xz gpt4free-af204c31cb047436f4e1c36199e15692eb271f20.tar.zst gpt4free-af204c31cb047436f4e1c36199e15692eb271f20.zip |
Diffstat (limited to '')
-rw-r--r-- | g4f/cookies.py | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/g4f/cookies.py b/g4f/cookies.py index b5c869e7..af0e6192 100644 --- a/g4f/cookies.py +++ b/g4f/cookies.py @@ -27,7 +27,7 @@ _cookies: Dict[str, Cookies] = {} if has_browser_cookie3 and os.environ.get('DBUS_SESSION_BUS_ADDRESS') == "/dev/null": _LinuxPasswordManager.get_password = lambda a, b: b"secret" -def get_cookies(domain_name: str = '', raise_requirements_error: bool = True) -> Dict[str, str]: +def get_cookies(domain_name: str = '', raise_requirements_error: bool = True, single_browser: bool = False) -> Dict[str, str]: """ Load cookies for a given domain from all supported browsers and cache the results. @@ -40,7 +40,7 @@ def get_cookies(domain_name: str = '', raise_requirements_error: bool = True) -> if domain_name in _cookies: return _cookies[domain_name] - cookies = load_cookies_from_browsers(domain_name, raise_requirements_error) + cookies = load_cookies_from_browsers(domain_name, raise_requirements_error, single_browser) _cookies[domain_name] = cookies return cookies @@ -50,7 +50,7 @@ def set_cookies(domain_name: str, cookies: Cookies = None) -> None: elif domain_name in _cookies: _cookies.pop(domain_name) -def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool = True) -> Cookies: +def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool = True, single_browser: bool = False) -> Cookies: """ Helper function to load cookies from various browsers. @@ -73,6 +73,8 @@ def load_cookies_from_browsers(domain_name: str, raise_requirements_error: bool for cookie in cookie_jar: if cookie.name not in cookies: cookies[cookie.name] = cookie.value + if single_browser and len(cookie_jar): + break except BrowserCookieError: pass except Exception as e: |