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


Python cookielib.CookieJar方法代码示例

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


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

示例1: __init__

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def __init__(
        self,
        host,
        port=8069,
        timeout=120,
        version=None,
        deserialize=True,
        opener=None,
    ):
        super(ConnectorJSONRPC, self).__init__(host, port, timeout, version)
        self.deserialize = deserialize
        # One URL opener (with cookies handling) shared between
        # JSON and HTTP requests
        if opener is None:
            cookie_jar = CookieJar()
            opener = build_opener(HTTPCookieProcessor(cookie_jar))
        self._opener = opener
        self._proxy_json, self._proxy_http = self._get_proxies() 
开发者ID:OCA,项目名称:odoorpc,代码行数:20,代码来源:__init__.py

示例2: __init__

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def __init__(self, user, pwd, softId="110614",
                 softKey="469c0d8a805a40f39d3c1ec3c9281e9c",
                 codeType="1004"):
        self.softId = softId
        self.softKey = softKey
        self.user = user
        self.pwd = pwd
        self.codeType = codeType
        self.uid = "100"
        self.initUrl = "http://common.taskok.com:9000/Service/ServerConfig.aspx"
        self.version = '1.1.1.2'
        self.cookieJar = cookielib.CookieJar()
        self.opener = urllib2.build_opener(
            urllib2.HTTPCookieProcessor(self.cookieJar))
        self.loginUrl = None
        self.uploadUrl = None
        self.codeUrl = None
        self.params = []
        self.uKey = None 
开发者ID:cundi,项目名称:PySide_For_Amazon_Order,代码行数:21,代码来源:captcha_handler.py

示例3: test_secure

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def test_secure(self):
        from cookielib import CookieJar, DefaultCookiePolicy

        for ns in True, False:
            for whitespace in " ", "":
                c = CookieJar()
                if ns:
                    pol = DefaultCookiePolicy(rfc2965=False)
                    int = interact_netscape
                    vs = ""
                else:
                    pol = DefaultCookiePolicy(rfc2965=True)
                    int = interact_2965
                    vs = "; Version=1"
                c.set_policy(pol)
                url = "http://www.acme.com/"
                int(c, url, "foo1=bar%s%s" % (vs, whitespace))
                int(c, url, "foo2=bar%s; secure%s" %  (vs, whitespace))
                self.assertFalse(
                    c._cookies["www.acme.com"]["/"]["foo1"].secure,
                    "non-secure cookie registered secure")
                self.assertTrue(
                    c._cookies["www.acme.com"]["/"]["foo2"].secure,
                    "secure cookie registered non-secure") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:26,代码来源:test_cookielib.py

示例4: test_path_mirror

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def test_path_mirror(self):
        from cookielib import CookieJar, DefaultCookiePolicy

        pol = DefaultCookiePolicy(rfc2965=True)

        c = CookieJar(pol)
        url = "http://foo.bar.com/"
        interact_2965(c, url, "spam=eggs; Version=1")
        h = interact_2965(c, url)
        self.assertNotIn("Path", h, "absent path returned with path present")

        c = CookieJar(pol)
        url = "http://foo.bar.com/"
        interact_2965(c, url, 'spam=eggs; Version=1; Path=/')
        h = interact_2965(c, url)
        self.assertIn('$Path="/"', h, "path not returned") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_cookielib.py

示例5: test_url_encoding

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def test_url_encoding(self):
        # Try some URL encodings of the PATHs.
        # (the behaviour here has changed from libwww-perl)
        from cookielib import CookieJar, DefaultCookiePolicy

        c = CookieJar(DefaultCookiePolicy(rfc2965=True))
        interact_2965(c, "http://www.acme.com/foo%2f%25/%3c%3c%0Anew%E5/%E5",
                      "foo  =   bar; version    =   1")

        cookie = interact_2965(
            c, "http://www.acme.com/foo%2f%25/<<%0anew�/���",
            'bar=baz; path="/foo/"; version=1');
        version_re = re.compile(r'^\$version=\"?1\"?', re.I)
        self.assertIn("foo=bar", cookie)
        self.assertRegexpMatches(cookie, version_re)

        cookie = interact_2965(
            c, "http://www.acme.com/foo/%25/<<%0anew�/���")
        self.assertFalse(cookie)

        # unicode URL doesn't raise exception
        cookie = interact_2965(c, u"http://www.acme.com/\xfc") 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:24,代码来源:test_cookielib.py

示例6: __init__

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def __init__(self,host=None,user=None,password=None,fileusr=None,filepwd=None):
 
        self.user=user
        self.host=host
        self.password=password
        self.fileusr=fileusr
        self.filepwd=filepwd
        self.cj=cookielib.CookieJar()
        self.opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(self.cj))
        self.opener.addheaders.append(('User-Agent','Mozilla/5.0'))
        self.opener.addheaders.append(('Accept','text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8'))
        self.opener.addheaders.append(('Accept-Language','zh-cn,zh;q=0.5'))
        self.opener.addheaders.append(('Accept-Encoding','gzip,deflate'))
        self.opener.addheaders.append(('Accept-Charset','GB2312,utf-8;q=0.7,*;q=0.7'))
        self.opener.addheaders.append(('Keep-Alive','115'))
        self.opener.addheaders.append(('Connection','keep-alive'))
        self.opener.addheaders.append(('X-Forwarded-For','219.78.113.243')) 
开发者ID:euphrat1ca,项目名称:fuzzdb-collect,代码行数:19,代码来源:dedecms全版本验证码绕过爆破.py

示例7: send_post

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def send_post(url, form_data_dict):
        "pass value by POST method, return response string"
        #set headers
        user_agent = \
            'Mozilla/5.0 (Linux; Android 4.2.2; GT-I9505 Build/JDQ39) ' +\
            'AppleWebKit/537.36 (KHTML, like Gecko) ' +\
            'Chrome/31.0.1650.59 Mobile Safari/537.36'
        headers = {'User-Agent': user_agent}
        #convert form dict data
        data = urllib.urlencode(form_data_dict)
        #get request object
        req = urllib2.Request(url, data, headers)

        #set cookie and create a general opener instead urlopen()
        cookie = cookielib.CookieJar()  # CookieJar object to store cookie
        handler = urllib2.HTTPCookieProcessor(cookie)  # create cookie processor
        opener = urllib2.build_opener(handler)  # a general opener
        #return response page content
        response = opener.open(req, timeout=100)
        page = response.read()

        return page 
开发者ID:PytLab,项目名称:loggers,代码行数:24,代码来源:logger_base.py

示例8: test_secure

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def test_secure(self):
        from cookielib import CookieJar, DefaultCookiePolicy

        for ns in True, False:
            for whitespace in " ", "":
                c = CookieJar()
                if ns:
                    pol = DefaultCookiePolicy(rfc2965=False)
                    int = interact_netscape
                    vs = ""
                else:
                    pol = DefaultCookiePolicy(rfc2965=True)
                    int = interact_2965
                    vs = "; Version=1"
                c.set_policy(pol)
                url = "http://www.acme.com/"
                int(c, url, "foo1=bar%s%s" % (vs, whitespace))
                int(c, url, "foo2=bar%s; secure%s" %  (vs, whitespace))
                self.assertTrue(
                    not c._cookies["www.acme.com"]["/"]["foo1"].secure,
                    "non-secure cookie registered secure")
                self.assertTrue(
                    c._cookies["www.acme.com"]["/"]["foo2"].secure,
                    "secure cookie registered non-secure") 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:26,代码来源:test_cookielib.py

示例9: cookiejar

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def cookiejar(self, domain):
        if not domain:
            return None

        dotdomain = domain if domain[0] == '.' else '.' + domain
        exploded = dotdomain.split(".")
        parent_domains = [".%s" % (".".join(exploded[x:])) for x in range(1, len(exploded) - 1)]
        matching_domains = [d for d in parent_domains if d in self.cookiedict]
        if not matching_domains:
            return None

        cj = cookielib.CookieJar()
        for d in matching_domains:
            for path in self.cookiedict[d]:
                for cookie_name, cookie_attrs in self.cookiedict[d][path].items():
                    ck = cookielib.Cookie(version=cookie_attrs["version"],
                                          name=cookie_name,
                                          value=cookie_attrs["value"],
                                          port=None,
                                          port_specified=False,
                                          domain=d,
                                          domain_specified=True,
                                          domain_initial_dot=False,
                                          path=path,
                                          path_specified=True,
                                          secure=cookie_attrs["secure"],
                                          expires=cookie_attrs["expires"],
                                          discard=True,
                                          comment=None,
                                          comment_url=None,
                                          rest={'HttpOnly': None},
                                          rfc2109=False)

                    if cookie_attrs["port"]:
                        ck.port = cookie_attrs["port"]
                        ck.port_specified = True

                    cj.set_cookie(ck)
        return cj 
开发者ID:flipkart-incubator,项目名称:watchdog,代码行数:41,代码来源:jsoncookie.py

示例10: __init__

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def __init__(self, username, password):
        self._username = username
        self._password = password
        self._logger = logging.getLogger(self.__class__.__name__)

        self._url_opener = urllib2.build_opener(
                        ThrottlingHandler(0.5),
                        urllib2.HTTPCookieProcessor(cookielib.CookieJar()))
        self._url_opener.addheaders = [('User-Agent', 
                'https://github.com/gabrielreid/polar-flow-export')]
        self._logged_in = False 
开发者ID:gabrielreid,项目名称:polar-flow-export,代码行数:13,代码来源:polarflowexport.py

示例11: get_response

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def get_response(self, query):
        response = None
        try:
            # we can't use helpers.retrieve_url because of redirects
            # we need the cookie processor to handle redirects
            opener = urllib_request.build_opener(urllib_request.HTTPCookieProcessor(CookieJar()))
            response = opener.open(query).read().decode('utf-8')
        except urllib_request.HTTPError as e:
            # if the page returns a magnet redirect, used in download_torrent
            if e.code == 302:
                response = e.url
        except Exception:
            pass
        return response 
开发者ID:qbittorrent,项目名称:search-plugins,代码行数:16,代码来源:jackett.py

示例12: __init__

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def __init__(self, host, port, timeout=120, ssl=False, opener=None):
        self._root_url = "{http}{host}:{port}".format(
            http=(ssl and "https://" or "http://"), host=host, port=port
        )
        self._timeout = timeout
        self._builder = URLBuilder(self)
        self._opener = opener
        if not opener:
            cookie_jar = CookieJar()
            self._opener = build_opener(HTTPCookieProcessor(cookie_jar)) 
开发者ID:OCA,项目名称:odoorpc,代码行数:12,代码来源:jsonrpclib.py

示例13: login

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def login(self, username, password):
        self.window.debug.appendPlainText('633: Process login!')
        password = hashlib.md5(password.encode('utf-8')).hexdigest()
        url = "https://logindict.youdao.com/login/acc/login"
        payload = "username=" + urllib.quote(username) + "&password=" + password + \
            "&savelogin=1&app=web&tp=urstoken&cf=7&fr=1&ru=http%3A%2F%2Fdict.youdao.com%2Fwordbook%2Fwordlist%3Fkeyfrom%3Dnull&product=DICT&type=1&um=true&savelogin=1"
        headers = {
            'Cache-Control': '"no-cache"',
            'Referer': 'http://account.youdao.com/login?service=dict&back_url=http://dict.youdao.com/wordbook/wordlist%3Fkeyfrom%3Dlogin_from_dict2.index',
            'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.101 Safari/537.36',
            'Content-Type': 'application/x-www-form-urlencoded'
        }
        url = url + '?' + payload
        req = urllib2.Request(url, headers=headers)
        cookie = cookielib.CookieJar()
        self.opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cookie))
        self.req = urllib2.install_opener(self.opener)
        urllib2.urlopen(req)
        if any(username in c.value for c in cookie):
            self.saveCookies(cookie)
            self.window.debug.appendPlainText('652: Cookie saved')
            return True
        else:
            self.window.debug.appendPlainText('655: Login failed')
            self.error = 1
            return False 
开发者ID:megachweng,项目名称:Anki-Youdao,代码行数:28,代码来源:Youdao-Anki.py

示例14: __init__

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def __init__(self, cookiejar=None):
        import cookielib
        if cookiejar is None:
            cookiejar = cookielib.CookieJar()
        self.cookiejar = cookiejar 
开发者ID:glmcdona,项目名称:meddle,代码行数:7,代码来源:urllib2.py

示例15: cookieAgentFactory

# 需要导入模块: import cookielib [as 别名]
# 或者: from cookielib import CookieJar [as 别名]
def cookieAgentFactory(verify_path, connectTimeout=30):
    customPolicy = BrowserLikePolicyForHTTPS(
        Certificate.loadPEM(FilePath(verify_path).getContent()))
    agent = Agent(reactor, customPolicy, connectTimeout=connectTimeout)
    cookiejar = cookielib.CookieJar()
    return CookieAgent(agent, cookiejar) 
开发者ID:leapcode,项目名称:bitmask-dev,代码行数:8,代码来源:_http.py


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