当前位置: 首页>>代码示例>>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;未经允许,请勿转载。