當前位置: 首頁>>代碼示例>>Python>>正文


Python cookiejar.CookieJar類代碼示例

本文整理匯總了Python中http.cookiejar.CookieJar的典型用法代碼示例。如果您正苦於以下問題:Python CookieJar類的具體用法?Python CookieJar怎麽用?Python CookieJar使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了CookieJar類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: enviaPeticion

def enviaPeticion(url, dominio, ruta, cookieDicc={"TESTID": "set"}):
    try:
        # Empaquetador de cookies.
        jar = CookieJar()
        # Genera un objeto request para posterior peticion.
        peticion = urllib.request.Request(url=url)

        # crearCookie to generate a cookie and add it to the cookie jar.
        for key, item in cookieDicc.items():
            jar.set_cookie(crearCookie(key, item, dominio, ruta))

        # print(crearCookie(key, item))

        jar.add_cookie_header(peticion)

        # Generar peticion.
        edmundoDantes = urllib.request.build_opener()
        abreteSesamo = edmundoDantes.open(peticion)

        RiquezaYVenganza = verificacionAcceso(abreteSesamo)

        if RiquezaYVenganza:
            print( "Busca tu propio Arbol")
        else:
            print( "!(Busca tu propio arbol)")

        return RiquezaYVenganza
    except urllib.error.HTTPError as err:
        print("Pagina fuera de servicio")
        return "Pagina fuera de servicio"
開發者ID:zoek1,項目名稱:Buatman,代碼行數:30,代碼來源:red.py

示例2: _getCookies

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:cwuenstel,項目名稱:southwest-autocheckin,代碼行數:25,代碼來源:SwaClient.py

示例3: dict_2_cookiejar

    def dict_2_cookiejar(d):
        cj = CookieJar()

        for c in d:
            ck = Cookie(
                name=c["name"],
                value=urllib.parse.unquote(c["value"]),
                domain=c["domain"],
                path=c["path"],
                secure=c["secure"],
                rest={"HttpOnly": c["httponly"]},
                version=0,
                port=None,
                port_specified=False,
                domain_specified=False,
                domain_initial_dot=False,
                path_specified=True,
                expires=None,
                discard=True,
                comment=None,
                comment_url=None,
                rfc2109=False,
            )
            cj.set_cookie(ck)

        return cj
開發者ID:LuYangP,項目名稱:weibo,代碼行數:26,代碼來源:login.py

示例4: __init__

 def __init__(self, filename, autoconnect=True, policy=None):
     experimental("Firefox3CookieJar is experimental code")
     CookieJar.__init__(self, policy)
     if filename is not None and not isinstance(filename, str):
         raise ValueError("filename must be string-like")
     self.filename = filename
     self._conn = None
     if autoconnect:
         self.connect()
開發者ID:sfall,項目名稱:mechanize3,代碼行數:9,代碼來源:_firefox3cookiejar.py

示例5: BuiltinBrowser

class BuiltinBrowser(BaseBrowser):
    def __init__(self, base_url=None):
        base_url = get_default_workflowy_url(base_url)
        super().__init__(base_url)
        self.cookie_jar = CookieJar()
        self.opener = build_opener(HTTPCookieProcessor(self.cookie_jar))

    def open(self, url, *, _raw=False, _query=None, **kwargs):
        full_url = urljoin(self.base_url, url)
        if _query is not None:
            full_url += "?" + urlencode(_query)
        
        data = urlencode(kwargs).encode()
        
        headers = {
            "Content-Type" : "application/x-www-form-urlencoded",
        }

        req = Request(full_url, data, headers)
        res = self.opener.open(req)

        with closing(res) as fp:
            content = fp.read()

        content = content.decode()

        if not _raw:
            # TODO: must not raise 404 error
            content = json.loads(content)

        return res, content

    def set_cookie(self, name, value):
        url = urlparse(self.base_url)
        cookie = Cookie(
            version=0,
            name=name,
            value=value,
            port=None,
            port_specified=False,
            domain=url.netloc,
            domain_specified=False,
            domain_initial_dot=False,
            path=url.path,
            path_specified=True,
            secure=False,
            expires=sys.maxsize,
            discard=False,
            comment=None,
            comment_url=None,
            rest={},
            rfc2109=False,
        )

        self.cookie_jar.set_cookie(cookie)
開發者ID:kanekin,項目名稱:wfapi,代碼行數:55,代碼來源:browser.py

示例6: cookiejar_from_dict

def cookiejar_from_dict(cookie_dict, cookiejar=None):
    """Returns a CookieJar from a key/value dictionary.

    :param cookie_dict: Dict of key/values to insert into CookieJar.
    """
    if not isinstance(cookie_dict, CookieJar):
        if cookiejar is None:
            cookiejar = CookieJar()
        if cookie_dict is not None:
            for name in cookie_dict:
                cookiejar.set_cookie(create_cookie(name, cookie_dict[name]))
        return cookiejar
    else:
        return cookie_dict
開發者ID:pombredanne,項目名稱:pulsar,代碼行數:14,代碼來源:httpurl.py

示例7: _cookies_for_domain

 def _cookies_for_domain(self, domain, request):
     if not self._policy.domain_return_ok(domain, request):
         return []
     debug("Checking %s for cookies to return", domain)
     if self.delayload:
         self._delayload_domain(domain)
     return CookieJar._cookies_for_domain(self, domain, request)
開發者ID:sfall,項目名稱:mechanize3,代碼行數:7,代碼來源:_msiecookiejar.py

示例8: cookiesjar

 def cookiesjar(self):
     """Returns cookie jar object
     """
     if not self._cookies_jar:
         self._cookies_jar = CookieJar()
         # add cookies from self._cookies
     return self._cookies_jar
開發者ID:budlight,項目名稱:human_curl,代碼行數:7,代碼來源:core.py

示例9: test_length

    def test_length(self):
        cookie_jar = CookieJar()
        policy = DeFactoCookiePolicy(cookie_jar=cookie_jar)
        cookie_jar.set_policy(policy)

        request = urllib.request.Request('http://example.com/')
        response = FakeResponse(
            [
                'Set-Cookie: k={0}'.format('a' * 400)
            ],
            'http://example.com/'
        )

        cookie_jar.extract_cookies(response, request)

        print(cookie_jar._cookies)

        self.assertTrue(cookie_jar._cookies['example.com']['/'].get('k'))

        request = urllib.request.Request('http://example.com/')
        response = FakeResponse(
            [
                'Set-Cookie: k={0}'.format('a' * 5000)
            ],
            'http://example.com/'
        )

        cookie_jar.extract_cookies(response, request)

        self.assertFalse(cookie_jar._cookies['example.com']['/'].get('k2'))
開發者ID:mback2k,項目名稱:wpull,代碼行數:30,代碼來源:cookie_test.py

示例10: test_empty_value

    def test_empty_value(self):
        cookie_jar = CookieJar()
        policy = DeFactoCookiePolicy(cookie_jar=cookie_jar)
        cookie_jar.set_policy(policy)

        request = urllib.request.Request('http://example.com/')
        response = FakeResponse(
            [
                'Set-Cookie: k'
            ],
            'http://example.com/'
        )

        cookie_jar.extract_cookies(response, request)

        print(cookie_jar._cookies)

        self.assertTrue(cookie_jar._cookies.get('example.com'))
開發者ID:Super-Rad,項目名稱:wpull,代碼行數:18,代碼來源:cookie_test.py

示例11: set_cookie

    def set_cookie(self, cookie):
        if cookie.discard:
            CookieJar.set_cookie(self, cookie)
            return

        def set_cookie(cur):
            # XXX
            # is this RFC 2965-correct?
            # could this do an UPDATE instead?
            row = self._row_from_cookie(cookie, cur)
            name, unused, domain, path = row[1:5]
            cur.execute("""\
DELETE FROM moz_cookies WHERE host = ? AND path = ? AND name = ?""",
                        (domain, path, name))
            cur.execute("""\
INSERT INTO moz_cookies VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
""", row)
        self._transaction(set_cookie)
開發者ID:sfall,項目名稱:mechanize3,代碼行數:18,代碼來源:_firefox3cookiejar.py

示例12: clear

 def clear(self, domain=None, path=None, name=None):
     CookieJar.clear(self, domain, path, name)
     where_parts = []
     sql_params = []
     if domain is not None:
         where_parts.append("host = ?")
         sql_params.append(domain)
         if path is not None:
             where_parts.append("path = ?")
             sql_params.append(path)
             if name is not None:
                 where_parts.append("name = ?")
                 sql_params.append(name)
     where = " AND ".join(where_parts)
     if where:
         where = " WHERE " + where
     def clear(cur):
         cur.execute("DELETE FROM moz_cookies%s" % where,
                     tuple(sql_params))
     self._transaction(clear)
開發者ID:sfall,項目名稱:mechanize3,代碼行數:20,代碼來源:_firefox3cookiejar.py

示例13: __init__

 def __init__(self, username, password, bank=SWEDBANK):
     """ Set default stuff """
     self.data = ""
     self.pch = None
     self.authkey = None
     self.cj = CookieJar()
     self.profile = None
     self.account = None
     self.useragent = None
     self.bankid = None
     self.login(username, password, bank)
開發者ID:kennedyshead,項目名稱:swedbank-cli,代碼行數:11,代碼來源:wrapper.py

示例14: test_ascii

    def test_ascii(self):
        # Differences with FakeResponse:
        # On Python 3, MIME encoded-word syntax is used
        # On Python 2, U backslash syntax is used but it's not decoded back.
        cookie_jar = CookieJar()
        policy = DeFactoCookiePolicy(cookie_jar=cookie_jar)
        cookie_jar.set_policy(policy)

        request = urllib.request.Request('http://example.com/')
        response = FakeResponse(
            [
                'Set-Cookie: k=�'
            ],
            'http://example.com/'
        )

        cookie_jar.extract_cookies(response, request)

        print(cookie_jar._cookies)

        self.assertFalse(cookie_jar._cookies.get('example.com'))
開發者ID:mback2k,項目名稱:wpull,代碼行數:21,代碼來源:cookie_test.py

示例15: __init__

    def __init__(self):
        self.cookiejar = CookieJar()
        self._cookie_processor = HTTPCookieProcessor(self.cookiejar)
        self.form = None

        self.url = "http://0.0.0.0:8080/"
        self.path = "/"

        self.status = None
        self.data = None
        self._response = None
        self._forms = None
開發者ID:fakegit,項目名稱:webpy,代碼行數:12,代碼來源:browser.py


注:本文中的http.cookiejar.CookieJar類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。