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


Python cookies.Cookies類代碼示例

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


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

示例1: authorize

    def authorize(streamProvider, username, password):
        """
        Perform authorization with Telus

        @param streamProvider the stream provider object. Needs to handle the 
                              getAuthURI.
        @param username the username to authenticate with
        @param password the password to authenticate with
        """

        uri = streamProvider.getAuthURI('telus_auth-gateway_net')

        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

        try:
            resp = opener.open(uri)
        except:
            print "Unable get Telus OAUTH location"
            return None
        Cookies.saveCookieJar(jar)

        html = resp.read()

        values = parseForm(['SAMLRequest', 'RelayState'], html)
        action = values.pop('action')
        if values == None:
            print "Form parsing failed in authorize"
            return None

        return Telus.getBookend(username, password, values, action)
開發者ID:siuside,項目名稱:plugin.video.snnow,代碼行數:31,代碼來源:telus.py

示例2: authorize

    def authorize(streamProvider, username, password):
        """
        Perform authorization with Rogers

        @param streamProvider the stream provider object. Needs to handle the 
                              getAuthURI.
        @param username the username to authenticate with
        @param password the password to authenticate with
        """

        uri = streamProvider.getAuthURI('Rogers')

        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))#,
                                      #urllib2.HTTPHandler(debuglevel=1),
                                      #urllib2.HTTPSHandler(debuglevel=1))

        try:
            resp = opener.open(uri)
        except:
            print "Unable get OAUTH location"
            return None
        Cookies.saveCookieJar(jar)

        html = resp.read()

        viewstate = re.search('<input.*__VIEWSTATE.*?value=\"(.*?)\".*?>', html, re.MULTILINE)
        if not viewstate:
            return None

        validation = re.search('<input.*__EVENTVALIDATION.*?value=\"(.*?)\".*?>', html, re.MULTILINE)
        if not validation:
            return None

        return Rogers.getOAuthToken(username, password, viewstate.group(1), validation.group(1), resp.url)
開發者ID:siuside,項目名稱:plugin.video.snnow,代碼行數:35,代碼來源:rogers.py

示例3: check_cookie

def check_cookie(handler, userId=None):
    cookies = Cookies(handler)
    if cookies.__contains__('sessionid') and memcache.get(cookies['sessionid']):
        sessionId=cookies['sessionid']
        userId=str(base64.b64decode(memcache.get(sessionId))).strip()
        memcache.set(sessionId, memcache.get(sessionId))
        return userId
    elif userId:
        uniqueId=str(uuid.uuid1())
        cookies['sessionid'] = uniqueId
        memcache.add(uniqueId, str(base64.b64encode(userId)))
        return userId
    return None
開發者ID:Divyaadz,項目名稱:erp,代碼行數:13,代碼來源:authutil.py

示例4: authorizeDevice

    def authorizeDevice(self, streamProvider, mso_id, channel):
        """
        Authorise the device for a particular channel.

        @param streamProvider the stream provider (eg: the SportsnetNow
                              instance)
        @param mso_id the MSO identifier (eg: 'Rogers')
        @param channel the channel identifier
        """
        settings = Settings.instance().get('adobe')

        values = { 'resource_id' : channel,
                   'requestor_id' : streamProvider.getRequestorID(),
                   'signed_requestor_id' : streamProvider.getSignedRequestorID(),
                   'mso_id' : mso_id,
                   'authentication_token' : settings['AUTHN_TOKEN'],
                   'device_id' : streamProvider.getDeviceID(),
                   'userMeta' : '1' }

        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

        opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))]

        try:
            resp = opener.open(self.AUTHORIZE_URI, urllib.urlencode(values))
        except urllib2.URLError, e:
            print e.args
            return False
開發者ID:micahg,項目名稱:plugin.video.cdncbl,代碼行數:29,代碼來源:adobe.py

示例5: deviceShortAuthorize

    def deviceShortAuthorize(self, streamProvider, mso_id):
        """
        Authorise for a particular channel... a second time.
        @param streamProvider the stream provider (eg: the SportsnetNow
                              instance)
        @param mso_id the MSO identifier (eg: 'Rogers')
        @return the session token required to authorise video the stream
        """
        settings = Settings.instance().get('adobe')

        values = { 'requestor_id' : streamProvider.getRequestorID(),
                   'signed_requestor_id' : streamProvider.getSignedRequestorID(),
                   'session_guid' : uuid.uuid4(),
                   'hashed_guid' : 'false',
                   'authz_token' : settings['AUTHZ_TOKEN'],
                   'mso_id' : mso_id,
                   'device_id' : streamProvider.getDeviceID() }

        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

        opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))]

        try:
            resp = opener.open(self.DEVICE_SHORT_AUTHORIZE, urllib.urlencode(values))
        except urllib2.URLError, e:
            print e.args
            return ''
開發者ID:micahg,項目名稱:plugin.video.cdncbl,代碼行數:28,代碼來源:adobe.py

示例6: callback

    def callback(username, password):
        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
        opener.addheaders = [('User-Agent', urllib.quote(Sportsnet.USER_AGENT))]

        values = { 'callback' : 'mvpdSignInCallback',
                   'username' :  username,
                   'password' : password,
                   't' : str(int(time.time())) }
        try:
            resp = opener.open('https://now.sportsnet.ca/secure/mvpd/myrogers?'+urllib.urlencode(values))
        except:
            print "Unable to login with signinmvpd"
            return False

        res = resp.read()
        json_data  = re.search('mvpdSignInCallback\((.*?)\)', res, re.MULTILINE)
        if not json_data:
            return False

        jsres = json.loads(json_data.group(1))

        if not 'code' in jsres.keys():
            return True

        if jsres['code'] != 'loginsuccess':
            return False

        return True
開發者ID:siuside,項目名稱:plugin.video.snnow,代碼行數:29,代碼來源:sportsnet.py

示例7: preAuthorize

    def preAuthorize(self, streamProvider, resource_ids):
        """
        Pre-authroize.  This _should_ get a list of authorised channels.

        @param streamProvider the stream provider (eg: the SportsnetNow
                              instance)
        @param resource_ids a list of resources to preauthorise
        @return a dictionary with each resource id as a key and boolean value
                indicating if the resource could be authorised
        """
        settings = Settings.instance().get('adobe')

        values = { 'authentication_token' : settings['AUTHN_TOKEN'],
                   'requestor_id' : streamProvider.getRequestorID() }

        value_str = urllib.urlencode(values)
        for resource_id in resource_ids:
            value_str += '&' + urllib.urlencode({ 'resource_id' : resource_id })

        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

        opener.addheaders = [('User-Agent', urllib.quote(self.USER_AGENT))]

        try:
            resp = opener.open(self.PREAUTHORIZE_URI, value_str)
        except urllib2.URLError, e:
            print e.args
            return False
開發者ID:micahg,項目名稱:plugin.video.cdncbl,代碼行數:29,代碼來源:adobe.py

示例8: login_messenger

    def login_messenger(self, driver):
        msg_driver = Cookies(driver)
        try:
            msg_driver.get_cookies()
            driver.refresh()
            time.sleep(4)

        except EOFError:
            username = driver.find_element_by_id("email")
            password = driver.find_element_by_id("pass")

            username.send_keys(self.email)
            password.send_keys(self.passwd)
            driver.find_element_by_name("login").click()
            time.sleep(4)
            msg_driver.log_cookies()
開發者ID:veljkoselakovic,項目名稱:emoji-randomizer,代碼行數:16,代碼來源:CoreMSG.py

示例9: __init__

    def __init__(self, args):
        super(HttpScan, self).__init__(args)
        self.session = requesocks.session()

        adapters.DEFAULT_RETRIES = self.args.max_retries
        self.tor = None
        if self.args.tor:
            self.out.log("Enabling TOR")
            self.tor = Torify()
            self.session.proxies = {'http': 'socks5://127.0.0.1:9050',
                                    'https': 'socks5://127.0.0.1:9050'}
            if self.args.check_tor:
                # Check TOR
                self.out.log("Checking IP via TOR")
                rip, tip = self.tor.check_ip(verbose=True)
                if tip is None:
                    self.out.log('TOR is not working properly!', logging.ERROR)
                    exit(-1)

        if self.args.cookies is not None:
            if path.exists(self.args.cookies) and path.isfile(self.args.cookies):
                self.cookies = MozillaCookieJar(self.args.cookies)
                self.cookies.load()
            else:
                # self.out.log('Could not find cookie file: %s' % self.args.load_cookies, logging.ERROR)
                self.cookies = Cookies.from_request(self.args.cookies)
        else:
            self.cookies = None

        self.ua = UserAgent() if self.args.user_agent is None else self.args.user_agent
開發者ID:0x90,項目名稱:futurescan,代碼行數:30,代碼來源:scan.py

示例10: completeBackgroundLogin

    def completeBackgroundLogin():
        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

        try:
            resp = opener.open('https://sp.auth.adobe.com/adobe-services/completeBackgroundLogin')
        except urllib2.URLError, e:
            print e.args
開發者ID:siuside,項目名稱:plugin.video.snnow,代碼行數:8,代碼來源:shawgo.py

示例11: authorize

    def authorize(streamProvider, username, password):
        """
        Perform authorization with Cogeco

        @param streamProvider the stream provider object.
        @param username the username to authenticate with
        @param password the password to authenticate with
        """

        uri =  streamProvider.getAuthURI("Cogeco")

        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))#,
                                      #urllib2.HTTPHandler(debuglevel=1),
                                      #urllib2.HTTPSHandler(debuglevel=1))

        # TODO: move this into a method that can be reused.. multiple calls..
        try:
            resp = opener.open(uri)
        except:
            print "Unable to redirect to auth page."
            return None
        Cookies.saveCookieJar(jar)

        html = resp.read()

        # TODO: this could be made a function to to parse and return the value based on an expression
        action = re.search('<form.*?action=\"(.*?)"', html, re.MULTILINE)
        if not action:
            print "Unable to find action form"
            return None
        action = action.group(1)

        saml = re.search('<input.*?name=\"SAMLRequest\".*?value=\"(.*?)\"', html, re.MULTILINE)
        if not saml:
            print "Unable to find SAML requst."
            return None
        saml = saml.group(1)

        relay = re.search('<input.*?name=\"RelayState\".*?value=\"(.*?)\"', html, re.MULTILINE)
        if not relay:
            print "Unable to find relay state."
            return None
        relay = relay.group(1)

        return Cogeco.postAuthSaml(username, password, saml, relay, action)
開發者ID:siuside,項目名稱:plugin.video.snnow,代碼行數:46,代碼來源:cogeco.py

示例12: _on_request

    def _on_request(self, adapter, request, **kwargs):
        match = self._find_match(request)
        # TODO(dcramer): find the correct class for this
        if match is None:
            error_msg = 'Connection refused: {0} {1}'.format(request.method,
                                                             request.url)
            response = ConnectionError(error_msg)
            response.request = request

            self._calls.add(request, response)
            raise response

        if 'body' in match and isinstance(match['body'], Exception):
            self._calls.add(request, match['body'])
            raise match['body']

        headers = {}
        if match['content_type'] is not None:
            headers['Content-Type'] = match['content_type']

        if 'callback' in match:  # use callback
            status, r_headers, body = match['callback'](request)
            if isinstance(body, six.text_type):
                body = body.encode('utf-8')
            body = BufferIO(body)
            headers.update(r_headers)

        elif 'body' in match:
            if match['adding_headers']:
                headers.update(match['adding_headers'])
            status = match['status']
            body = BufferIO(match['body'])

        response = HTTPResponse(
            status=status,
            reason=six.moves.http_client.responses[status],
            body=body,
            headers=headers,
            preload_content=False,
        )

        response = adapter.build_response(request, response)
        if not match.get('stream'):
            response.content  # NOQA

        try:
            resp_cookies = Cookies.from_request(response.headers['set-cookie'])
            response.cookies = cookiejar_from_dict(dict(
                (v.name, v.value)
                for _, v
                in resp_cookies.items()
            ))
        except (KeyError, TypeError):
            pass

        self._calls.add(request, response)

        return response
開發者ID:2rs2ts,項目名稱:moto,代碼行數:58,代碼來源:responses.py

示例13: authorize

    def authorize(streamProvider, username, password):
        """
        Perform authorization with ShawGo

        @param streamProvider the stream provider object. Needs to handle the 
                              getAuthURI.
        @param username the username to authenticate with
        @param password the password to authenticate with
        """

        uri = streamProvider.getAuthURI('ShawGo')

        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))#,
                                      #urllib2.HTTPHandler(debuglevel=1),
                                      #urllib2.HTTPSHandler(debuglevel=1))

        try:
            resp = opener.open(uri)
        except:
            print "Unable get OAUTH location"
            return None
        Cookies.saveCookieJar(jar)

        html = resp.read()

        action = re.search('<form.*?action=\"(.*?)"', html, re.MULTILINE)
        if not action:
            print "Unable to find action form"
            return None
        action = action.group(1)

        saml = re.search('<input.*?name=\"SAMLRequest\".*?value=\"(.*?)\"', html, re.MULTILINE)
        if not saml:
            print "Unable to find SAML requst."
            return None
        saml = saml.group(1)

        relay = re.search('<input.*?name=\"RelayState\".*?value=\"(.*?)\"', html, re.MULTILINE)
        if not relay:
            print "Unable to find relay state."
            return None
        relay = relay.group(1)

        return ShawGo.getAuthn(username, password, saml, relay, action)
開發者ID:siuside,項目名稱:plugin.video.snnow,代碼行數:45,代碼來源:shawgo.py

示例14: checkMSOs

    def checkMSOs(self):
        """
        Check the available MSOs. We don't actually use anything from this
        request other than the cookies returned.
        """
        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
        opener.addheaders = [("User-Agent", urllib.quote(self.USER_AGENT))]

        try:
            resp = opener.open(self.AUTHORIZED_MSO_URI)
        except:
            print "Unable get OAUTH location"
            return None
        Cookies.saveCookieJar(jar)

        mso_xml = resp.read()
        return None
開發者ID:micahg,項目名稱:plugin.video.cdncbl,代碼行數:18,代碼來源:snnow.py

示例15: authGateway

    def authGateway(values, url):
        jar = Cookies.getCookieJar()
        opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))

        try:
            resp = opener.open(url, urllib.urlencode(values))
        except urllib2.URLError, e:
            if e.reason[1] == "No address associated with hostname":
                return True
            return None
開發者ID:siuside,項目名稱:plugin.video.snnow,代碼行數:10,代碼來源:telus.py


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