Beispiel #1
0
def save_cookie(cookies: RequestsCookieJar) -> None:
    # Ensure the cookie file exists
    if not os.path.isfile(COOKIE_FILE):
        touch(COOKIE_FILE)

    with open(COOKIE_FILE, "wb") as f:
        return pickle.dump(cookies, f)
Beispiel #2
0
def save_cookies_to_txt(cookies: List[Any], filename: str) -> None:
    # Ensure the cookie file exists
    if not os.path.isfile(filename):
        touch(filename)

    cjar = MozillaCookieJar(filename)
    for cookie in cookies:
        cjar.set_cookie(cookie)
    cjar.save(ignore_discard=False)
Beispiel #3
0
def load_cookie() -> List[Optional[Any]]:
    # Ensure the cookie file exists
    if not os.path.isfile(COOKIE_FILE):
        touch(COOKIE_FILE)

    with open(COOKIE_FILE, "rb") as f:
        try:
            return pickle.load(f)
        except EOFError:
            return []
Beispiel #4
0
def test_touch_yes(mock_isfile, mock_path_touch):
    mock_isfile.return_value = False
    touch("boo")
    mock_path_touch.assert_called_once()
Beispiel #5
0
def test_touch(mock_isfile, mock_path_touch):
    mock_isfile.return_value = True
    touch("boo")
    mock_path_touch.assert_not_called()