test_cookielib.py 文件源码

python
阅读 25 收藏 0 点赞 0 评论 0

项目:oil 作者: oilshell 项目源码 文件源码
def test_netscape_misc(self):
        # Some additional Netscape cookies tests.
        from cookielib import CookieJar
        from urllib2 import Request

        c = CookieJar()
        headers = []
        req = Request("http://foo.bar.acme.com/foo")

        # Netscape allows a host part that contains dots
        headers.append("Set-Cookie: Customer=WILE_E_COYOTE; domain=.acme.com")
        res = FakeResponse(headers, "http://www.acme.com/foo")
        c.extract_cookies(res, req)

        # and that the domain is the same as the host without adding a leading
        # dot to the domain.  Should not quote even if strange chars are used
        # in the cookie value.
        headers.append("Set-Cookie: PART_NUMBER=3,4; domain=foo.bar.acme.com")
        res = FakeResponse(headers, "http://www.acme.com/foo")
        c.extract_cookies(res, req)

        req = Request("http://foo.bar.acme.com/foo")
        c.add_cookie_header(req)
        self.assertTrue(
            "PART_NUMBER=3,4" in req.get_header("Cookie") and
            "Customer=WILE_E_COYOTE" in req.get_header("Cookie"))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号