Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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 []
Ejemplo n.º 4
0
def test_touch_yes(mock_isfile, mock_path_touch):
    mock_isfile.return_value = False
    touch("boo")
    mock_path_touch.assert_called_once()
Ejemplo n.º 5
0
def test_touch(mock_isfile, mock_path_touch):
    mock_isfile.return_value = True
    touch("boo")
    mock_path_touch.assert_not_called()