Example #1
0
    def test_cookiejar(self):
        c1 = create_cookie('foo', 'bar')
        c2 = create_cookie('foo', 'bar')
        self.assertFalse(c1 == c2)

        c = create_cookie('foo', 'bar', domain='.dumpz.org')
        self.assertEquals(c.domain, '.dumpz.org')

        cj = CookieJar()
        cj.set_cookie(create_cookie('foo', 'bar', domain='foo.com'))
        cj.set_cookie(create_cookie('foo', 'bar', domain='bar.com'))
        self.assertEqual(len(cj), 2)
Example #2
0
    def test_cookiejar(self):
        cookie1 = create_cookie('foo', 'bar', self.server.address)
        cookie2 = create_cookie('foo', 'bar', self.server.address)
        self.assertFalse(cookie1 == cookie2)

        cookie0 = create_cookie('foo', 'bar', domain='.dumpz.org')
        self.assertEqual(cookie0.domain, '.dumpz.org')

        jar = CookieJar()
        jar.set_cookie(create_cookie('foo', 'bar', domain='foo.com'))
        jar.set_cookie(create_cookie('foo', 'bar', domain='bar.com'))
        self.assertEqual(len(jar), 2)
Example #3
0
 def test_pickle_serialization(self):
     cookie = create_cookie('foo', 'bar')
     mgr = CookieManager.from_cookie_list([cookie])
     dump = pickle.dumps(mgr)
     mgr2 = pickle.loads(dump)
     self.assertEqual(list(mgr.cookiejar)[0].value,
                      list(mgr2.cookiejar)[0].value)
Example #4
0
File: curl.py Project: Scaurus/grab
    def extract_cookiejar(self):
        """
        Extract cookies that pycurl instance knows.

        Returns `CookieJar` object.
        """

        # Example of line:
        # www.google.com\tFALSE\t/accounts/\tFALSE\t0\tGoogleAccountsLocale_session\ten
        # Fields:
        # * domain
        # * whether or not all machines under that domain can read the cookie's information.
        # * path
        # * Secure Flag: whether or not a secure connection (HTTPS) is required to read the cookie.
        # * exp. timestamp
        # * name
        # * value
        cookiejar = CookieJar()
        for line in self.curl.getinfo(pycurl.INFO_COOKIELIST):
            values = line.split('\t')
            # old
            #cookies[values[-2]] = values[-1]
            # new
            cookie = create_cookie(
                name=values[5],
                value=values[6],
                domain=values[0],
                path=values[2],
                secure=values[3] == "TRUE",
                expires=int(values[4]) if values[4] else None,
            )
            cookiejar.set_cookie(cookie)
        return cookiejar
Example #5
0
    def test_from_cookie_list(self):
        cookie = create_cookie("foo", "bar", self.server.address)
        mgr = CookieManager.from_cookie_list([cookie])
        test_cookie = [x for x in mgr.cookiejar if x.name == "foo"][0]
        self.assertEqual(cookie.name, test_cookie.name)

        mgr = CookieManager.from_cookie_list([])
        self.assertEqual(0, len(list(mgr.cookiejar)))
Example #6
0
    def test_from_cookie_list(self):
        cookie = create_cookie('foo', 'bar')
        mgr = CookieManager.from_cookie_list([cookie])
        test_cookie = [x for x in mgr.cookiejar if x.name == 'foo'][0]
        self.assertEqual(cookie.name, test_cookie.name)

        mgr = CookieManager.from_cookie_list([])
        self.assertEqual(0, len(list(mgr.cookiejar)))
Example #7
0
 def test_get_item(self):
     cookie = create_cookie("foo", "bar", self.server.address)
     mgr = CookieManager.from_cookie_list([cookie])
     self.assertEqual("bar", mgr["foo"])
     self.assertRaises(KeyError, lambda: mgr["zzz"])
Example #8
0
 def test_get_item(self):
     cookie = create_cookie('foo', 'bar')
     mgr = CookieManager.from_cookie_list([cookie])
     self.assertEqual('bar', mgr['foo'])
     self.assertRaises(KeyError, lambda: mgr['zzz'])
Example #9
0
 def test_cookie(self):
     create_cookie('foo', 'bar')
     self.assertRaises(TypeError, create_cookie,
                       'foo', 'bar', x='y')
Example #10
0
 def test_cookie(self):
     create_cookie('foo', 'bar', self.server.address)
     self.assertRaises(GrabMisuseError, create_cookie,
                       'foo', 'bar', self.server.address, x='y')
Example #11
0
 def test_get_item(self):
     cookie = create_cookie('foo', 'bar', self.server.address)
     mgr = CookieManager.from_cookie_list([cookie])
     self.assertEqual('bar', mgr['foo'])
     self.assertRaises(KeyError, lambda: mgr['zzz'])