async def session(): """Client session that can be used in tests.""" jar = CookieJar() jar.load(os.path.join(resource_path, "dummy_cookies.pickle")) sess = ClientSession(headers={"Connection": "keep-alive"}, cookie_jar=jar) yield sess await sess.close()
def function244(arg1826, function674, function1086): var2077 = (tempfile.mkdtemp() + '/aiohttp.test.cookie') var769 = CookieJar(loop=arg1826) var769.update_cookies(function1086) var769.save(file_path=var2077) var856 = CookieJar(loop=arg1826) var856.load(file_path=var2077) var2054 = SimpleCookie() for var3909 in var856: var2054[var3909.key] = var3909 os.unlink(var2077) assert (var2054 == function1086)
async def test_save_load(tmp_path, loop, cookies_to_send, cookies_to_receive) -> None: file_path = pathlib.Path(str(tmp_path)) / "aiohttp.test.cookie" # export cookie jar jar_save = CookieJar() jar_save.update_cookies(cookies_to_receive) jar_save.save(file_path=file_path) jar_load = CookieJar() jar_load.load(file_path=file_path) jar_test = SimpleCookie() for cookie in jar_load: jar_test[cookie.key] = cookie assert jar_test == cookies_to_receive
def test_save_load(loop, cookies_to_send, cookies_to_receive): file_path = tempfile.mkdtemp() + '/aiohttp.test.cookie' # export cookie jar jar_save = CookieJar(loop=loop) jar_save.update_cookies(cookies_to_receive) jar_save.save(file_path=file_path) jar_load = CookieJar(loop=loop) jar_load.load(file_path=file_path) jar_test = SimpleCookie() for cookie in jar_load: jar_test[cookie.key] = cookie os.unlink(file_path) assert jar_test == cookies_to_receive
def test_save_load(loop, cookies_to_send, cookies_to_receive) -> None: file_path = tempfile.mkdtemp() + '/aiohttp.test.cookie' # export cookie jar jar_save = CookieJar(loop=loop) jar_save.update_cookies(cookies_to_receive) jar_save.save(file_path=file_path) jar_load = CookieJar(loop=loop) jar_load.load(file_path=file_path) jar_test = SimpleCookie() for cookie in jar_load: jar_test[cookie.key] = cookie os.unlink(file_path) assert jar_test == cookies_to_receive
import json from aiohttp import ClientSession, CookieJar from asyncio import get_event_loop from appdirs import user_config_dir from os import path from urllib.parse import urljoin from jd4.log import logger _CHUNK_SIZE = 32768 _CONFIG_DIR = user_config_dir('jd4') _COOKIES_FILE = path.join(_CONFIG_DIR, 'cookies') _COOKIE_JAR = CookieJar(unsafe=True) try: _COOKIE_JAR.load(_COOKIES_FILE) except FileNotFoundError: pass class VJ4Error(Exception): def __init__(self, name, message, *args): super().__init__(name, message, *args) self.name = name async def json_response_to_dict(response): if response.content_type != 'application/json': raise Exception('invalid content type ' + response.content_type) response_dict = await response.json() if 'error' in response_dict: error = response_dict['error'] raise VJ4Error(error.get('name', 'unknown'), error.get('message', ''),
def _load_config(): try: with open(_CONFIG_FILE) as file: return yaml.load(file, Loader=yaml.RoundTripLoader) except FileNotFoundError: logger.error('Config file %s not found.', _CONFIG_FILE) exit(1) config = _load_config() cookie_jar = CookieJar(unsafe=True) try: cookie_jar.load(_COOKIES_FILE) except FileNotFoundError: pass async def save_config(): def do_save_config(): with open(_CONFIG_FILE, 'w') as file: yaml.dump(config, file, Dumper=yaml.RoundTripDumper) await get_event_loop().run_in_executor(None, do_save_config) _save_cookie_function = partial(cookie_jar.save, _COOKIES_FILE)