當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。