当前位置: 首页>>代码示例>>Python>>正文


Python cookiejar.Cookie方法代码示例

本文整理汇总了Python中http.cookiejar.Cookie方法的典型用法代码示例。如果您正苦于以下问题:Python cookiejar.Cookie方法的具体用法?Python cookiejar.Cookie怎么用?Python cookiejar.Cookie使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.cookiejar的用法示例。


在下文中一共展示了cookiejar.Cookie方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_cookie_dict

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def test_cookie_dict():
    c = RetsHttpClient('login_url', 'username', 'password')
    c._session = mock.MagicMock()
    jar = RequestsCookieJar()
    c1 = Cookie(1, 'name1', 'value1', 80, 80, 'domain', 'domain_specified', 'domain_initial_dot', 'path',
                'path_specified', True, True, False, 'comment', 'comment_url', 'rest')
    c2 = Cookie(1, 'name2', 'value2', 80, 80, 'domain', 'domain_specified', 'domain_initial_dot', 'path',
                'path_specified', True, True, False, 'comment', 'comment_url', 'rest')
    c3 = Cookie(1, 'name1', 'value1', 80, 80, 'domain', 'domain_specified3', 'domain_initial_dot3', 'path3',
                'path_specified3', True, True, False, 'comment', 'comment_url', 'rest')

    jar.set_cookie(c1)
    jar.set_cookie(c2)
    jar.set_cookie(c3)
    c._session.cookies = jar

    assert c.cookie_dict == {'name1': 'value1', 'name2': 'value2'} 
开发者ID:opendoor-labs,项目名称:rets,代码行数:19,代码来源:http_client_test.py

示例2: test_request_loader_does_not_fail_with_invalid_token

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def test_request_loader_does_not_fail_with_invalid_token(client):
    c = Cookie(
        version=0,
        name="remember_token",
        value="None",
        port=None,
        port_specified=False,
        domain="www.example.com",
        domain_specified=False,
        domain_initial_dot=False,
        path="/",
        path_specified=True,
        secure=False,
        expires=None,
        discard=True,
        comment=None,
        comment_url=None,
        rest={"HttpOnly": None},
        rfc2109=False,
    )

    client.cookie_jar.set_cookie(c)
    response = client.get("/")
    assert b"BadSignature" not in response.data 
开发者ID:Flask-Middleware,项目名称:flask-security,代码行数:26,代码来源:test_common.py

示例3: make_cookie

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def make_cookie(self, name, value):
        return Cookie(
            version=0,
            name=name,
            value=value,
            port=None,
            port_specified=False,
            domain="music.163.com",
            domain_specified=True,
            domain_initial_dot=False,
            path="/",
            path_specified=True,
            secure=False,
            expires=None,
            discard=False,
            comment=None,
            comment_url=None,
            rest={},
        ) 
开发者ID:darknessomi,项目名称:musicbox,代码行数:21,代码来源:api.py

示例4: get_url_headers

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def get_url_headers(url, forced=False):
    from . import scrapertools
    
    domain = urlparse.urlparse(url)[1]
    sub_dom = scrapertools.find_single_match(domain, '\.(.*?\.\w+)')
    if sub_dom and not 'google' in url:
        domain = sub_dom
    domain_cookies = cj._cookies.get("." + domain, {}).get("/", {})

    if "|" in url or not "cf_clearance" in domain_cookies:
        if not forced:
            return url

    headers = dict()
    headers["User-Agent"] = default_headers["User-Agent"]
    headers["Cookie"] = "; ".join(["%s=%s" % (c.name, c.value) for c in list(domain_cookies.values())])

    return url + "|" + "&".join(["%s=%s" % (h, urllib.quote(headers[h])) for h in headers]) 
开发者ID:alfa-addon,项目名称:addon,代码行数:20,代码来源:httptools.py

示例5: _getCookies

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def _getCookies(headers):
    cj = CookieJar()
    cookies = headers.split(',')
    for cookie in cookies:
        attrs = cookie.split(';')
        cookieNameValue = name = attrs[0].strip().split('=')
        pathNameValue = name = attrs[1].strip().split('=')
        ck = Cookie(version=1, name=cookieNameValue[0],
                              value=cookieNameValue[1],
                              port=443,
                              port_specified=False,
                              domain=swaDomain,
                              domain_specified=True,
                              domain_initial_dot=False,
                              path=pathNameValue[1],
                              path_specified=True,
                              secure=True,
                              expires=None,
                              discard=True,
                              comment=None,
                              comment_url=None,
                              rest={'HttpOnly': None},
                              rfc2109=False)
        cj.set_cookie(ck)
    return cj 
开发者ID:springyleap,项目名称:southwest-autocheckin,代码行数:27,代码来源:SwaClient.py

示例6: save_cookiestxt

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def save_cookiestxt(fp, cookies):
    """Write 'cookies' in Netscape cookies.txt format to 'fp'"""
    fp.write("# Netscape HTTP Cookie File\n\n")

    for cookie in cookies:
        if cookie.value is None:
            name = ""
            value = cookie.name
        else:
            name = cookie.name
            value = cookie.value

        fp.write("\t".join((
            cookie.domain,
            "TRUE" if cookie.domain.startswith(".") else "FALSE",
            cookie.path,
            "TRUE" if cookie.secure else "FALSE",
            "0" if cookie.expires is None else str(cookie.expires),
            name,
            value,
        )) + "\n") 
开发者ID:mikf,项目名称:gallery-dl,代码行数:23,代码来源:util.py

示例7: test_anticsrf_without_samesite

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def test_anticsrf_without_samesite(self):
        cookie = Cookie(name='CSRFTOKEN',
                        comment=None,
                        comment_url=None,
                        discard=False,
                        domain='mozilla.com',
                        domain_initial_dot=False,
                        domain_specified='mozilla.com',
                        expires=None,
                        path='/',
                        path_specified='/',
                        port=443,
                        port_specified=443,
                        rfc2109=False,
                        rest={'HttpOnly': True},
                        secure=True,
                        version=1,
                        value='bar')
        self.reqs['session'].cookies.set_cookie(cookie)

        result = cookies(self.reqs)

        self.assertEquals('cookies-anticsrf-without-samesite-flag', result['result'])
        self.assertFalse(result['pass'])
        self.assertFalse(result['sameSite']) 
开发者ID:mozilla,项目名称:http-observatory,代码行数:27,代码来源:test_headers.py

示例8: test_samesite_invalid

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def test_samesite_invalid(self):
        cookie = Cookie(name='SESSIONID',
                        comment=None,
                        comment_url=None,
                        discard=False,
                        domain='mozilla.com',
                        domain_initial_dot=False,
                        domain_specified='mozilla.com',
                        expires=None,
                        path='/',
                        path_specified='/',
                        port=443,
                        port_specified=443,
                        rfc2109=False,
                        rest={'HttpOnly': True, 'SameSite': 'Invalid'},
                        secure=True,
                        version=1,
                        value='bar')
        self.reqs['session'].cookies.set_cookie(cookie)

        result = cookies(self.reqs)

        self.assertEquals('cookies-samesite-flag-invalid', result['result'])
        self.assertFalse(result['pass'])
        self.assertIsNone(result['sameSite']) 
开发者ID:mozilla,项目名称:http-observatory,代码行数:27,代码来源:test_headers.py

示例9: test_no_secure

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def test_no_secure(self):
        cookie = Cookie(name='foo',
                        comment=None,
                        comment_url=None,
                        discard=False,
                        domain='mozilla.com',
                        domain_initial_dot=False,
                        domain_specified='mozilla.com',
                        expires=None,
                        path='/',
                        path_specified='/',
                        port=443,
                        port_specified=443,
                        rfc2109=False,
                        rest={},
                        secure=False,
                        version=1,
                        value='bar')
        self.reqs['session'].cookies.set_cookie(cookie)

        result = cookies(self.reqs)

        self.assertEquals('cookies-without-secure-flag', result['result'])
        self.assertFalse(result['pass'])
        self.assertFalse(result['sameSite']) 
开发者ID:mozilla,项目名称:http-observatory,代码行数:27,代码来源:test_headers.py

示例10: init_session_cookie

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def init_session_cookie(name, value, **kwargs):
    return Cookie(version=0, name=name, value=value, port=None, port_specified=False,
                  domain='www.codechef.com', domain_specified=False, domain_initial_dot=False,
                  path='/', path_specified=True, secure=False, expires=None, discard=False,
                  comment=None, comment_url=None, rest={'HttpOnly': None}, rfc2109=False) 
开发者ID:sk364,项目名称:codechef-cli,代码行数:7,代码来源:helpers.py

示例11: test_init_session_cookie

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def test_init_session_cookie(self):
        """Should return cookiejar.Cookie instance with name and value as provided"""
        cookie = init_session_cookie("u", "u")
        self.assertIsInstance(cookie, Cookie)
        self.assertEqual(cookie.name, "u")
        self.assertEqual(cookie.value, "u") 
开发者ID:sk364,项目名称:codechef-cli,代码行数:8,代码来源:test_helpers.py

示例12: session_get

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def session_get(self):
        if self.session:
            return self.session
        else:
            cookie = self.headers.get('Cookie')
            if cookie:
                cookie = SimpleCookie(cookie)
                if self.COOKIE_NAME in cookie:
                    return cookie[self.COOKIE_NAME].value

        return None 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:13,代码来源:obs_operator.py

示例13: cookiejar_create

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def cookiejar_create(self, cookiejar_file, session):
        cookie_jar = LWPCookieJar(cookiejar_file.name)
        cookie_jar.set_cookie(Cookie(0, self.COOKIE_NAME, session,
            None, False,
            '', False, True,
            '/', True,
            True,
            None, None, None, None, {}))
        cookie_jar.save()
        cookiejar_file.flush() 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:12,代码来源:obs_operator.py

示例14: addcookies

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def addcookies(self, cookies):
        """Inject Cookies from a CookieJar into our JSON dictionary."""
        if not isinstance(cookies, RequestsCookieJar):
            return False

        for domain, pathdict in cookies._cookies.items():
            search_ip = IP_REGEX.match(domain)
            if search_ip:
                # Match either an IPv4 address or an IPv6 address with a local suffix
                domain_key = search_ip.group("ip")
            else:
                domain_key = domain if domain[0] == '.' else '.' + domain

            if domain_key not in self.cookiedict.keys():
                self.cookiedict[domain_key] = {}

            for path, keydict in pathdict.items():
                if path not in self.cookiedict[domain_key].keys():
                    self.cookiedict[domain_key][path] = {}

                for key, cookieobj in keydict.items():
                    if isinstance(cookieobj, Cookie):
                        print(cookieobj)
                        cookie_attrs = {
                            "value": cookieobj.value,
                            "expires": cookieobj.expires,
                            "secure": cookieobj.secure,
                            "port": cookieobj.port,
                            "version": cookieobj.version
                        }
                        self.cookiedict[domain_key][path][key] = cookie_attrs 
开发者ID:penetrate2hack,项目名称:ITWSV,代码行数:33,代码来源:jsoncookie.py

示例15: create_cookie

# 需要导入模块: from http import cookiejar [as 别名]
# 或者: from http.cookiejar import Cookie [as 别名]
def create_cookie(host, path, secure, expires, name, value):
    """Shortcut function to create a cookie
    """
    return cookielib.Cookie(0, name, value, None, False, host, host.startswith('.'),
                            host.startswith('.'), path, True, secure, expires, False,
                            None, None, {}) 
开发者ID:bomquote,项目名称:transistor,代码行数:8,代码来源:browsercookie.py


注:本文中的http.cookiejar.Cookie方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。