def load_jar(self, content): filename = os.path.join(self.dir, 'cookies') with open(filename, 'x') as f: f.write(content) jar = GoCookieJar() jar.load(filename=filename) return jar
def test_roundtrip(self): jar = self.load_jar(cookie_content) filename2 = os.path.join(self.dir, 'cookies2') jar.save(filename=filename2) jar = GoCookieJar() jar.load(filename=filename2) self.assert_jar_queries(jar, cookie_content_queries)
def cookies_for_controller(self, controller_name): f = pathlib.Path(self.path) / 'cookies' / (controller_name + '.json') if not f.exists(): f = pathlib.Path('~/.go-cookies').expanduser() # TODO if neither cookie file exists, where should # we create the cookies? jar = GoCookieJar(str(f)) jar.load() return jar
async def connect(self, **kwargs): """Connect to an arbitrary Juju model. kwargs are passed through to Connection.connect() """ kwargs.setdefault('loop', self.loop) kwargs.setdefault('max_frame_size', self.max_frame_size) kwargs.setdefault('bakery_client', self.bakery_client) if 'macaroons' in kwargs: if not kwargs['bakery_client']: kwargs['bakery_client'] = httpbakery.Client() if not kwargs['bakery_client'].cookies: kwargs['bakery_client'].cookies = GoCookieJar() jar = kwargs['bakery_client'].cookies for macaroon in kwargs.pop('macaroons'): jar.set_cookie(go_to_py_cookie(macaroon)) self._connection = await Connection.connect(**kwargs)