• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python utils.parse_qs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中social.utils.parse_qs函数的典型用法代码示例。如果您正苦于以下问题:Python parse_qs函数的具体用法?Python parse_qs怎么用?Python parse_qs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: do_login

    def do_login(self, after_complete_checks=True, user_data_body=None,
                 expected_username=None):
        self.strategy.set_settings({
            'SOCIAL_AUTH_GITHUB_KEY': 'a-key',
            'SOCIAL_AUTH_GITHUB_SECRET': 'a-secret-key',
            'SOCIAL_AUTH_LOGIN_REDIRECT_URL': self.login_redirect_url,
            'SOCIAL_AUTH_AUTHENTICATION_BACKENDS': (
                'social.backends.github.GithubOAuth2',
            )
        })
        start_url = do_auth(self.strategy).url
        target_url = self.strategy.build_absolute_uri(
            '/complete/github/?code=foobar'
        )

        start_query = parse_qs(urlparse(start_url).query)
        location_url = target_url + ('?' in target_url and '&' or '?') + \
                       'state=' + start_query['state']
        location_query = parse_qs(urlparse(location_url).query)

        HTTPretty.register_uri(HTTPretty.GET, start_url, status=301,
                               location=location_url)
        HTTPretty.register_uri(HTTPretty.GET, location_url, status=200,
                               body='foobar')

        response = requests.get(start_url)
        expect(response.url).to.equal(location_url)
        expect(response.text).to.equal('foobar')

        HTTPretty.register_uri(HTTPretty.GET,
                               uri=self.backend.ACCESS_TOKEN_URL,
                               status=200,
                               body=self.access_token_body or '',
                               content_type='text/json')

        if self.user_data_url:
            user_data_body = user_data_body or self.user_data_body or ''
            HTTPretty.register_uri(HTTPretty.GET, self.user_data_url,
                                   body=user_data_body,
                                   content_type='text/json')
        self.strategy.set_request_data(location_query)
        class Request(object):session = {}
        self.strategy.request = Request()

        def _login_lambda(strategy, user, social_user):
            strategy.request = Request()
            return strategy.session_set('username', user.username)

        redirect = do_complete(
            self.strategy,
            user=self.user,
            login=_login_lambda
        )
        if after_complete_checks:
            expect(self.strategy.session_get('username')).to.equal(
                expected_username or self.expected_username
            )
            expect(redirect.url).to.equal(self.login_redirect_url)
        return redirect
开发者ID:blendedlearn,项目名称:blended_learning,代码行数:59,代码来源:actions.py


示例2: auth_by_token

def auth_by_token(request, backend):

    key, secret = request.backend.get_key_and_secret()

    response = requests.get(request.backend.ACCESS_TOKEN_URL, params={
        'client_id': key,
        'redirect_uri': request.data.get('redirect_uri'),
        'client_secret': secret,
        'code': request.data.get('code')
    })

    try:
        response = response.json()
    except ValueError:
        response = parse_qs(response.text)

    try:
        access_token = response['access_token']

        # check if user has signed up
        email = request.backend.user_data(access_token).get('email')

        try:
            User.objects.get(email=email)
            new_user = False
        except User.DoesNotExist:
            new_user = True

        return new_user, request.backend.do_auth(access_token)

    except KeyError:
        raise APIException(response['error']['message'])
开发者ID:fbenke,项目名称:BeamPay,代码行数:32,代码来源:social_auth.py


示例3: run_oauth

    def run_oauth(self, m, user=None):

        strategy = DjangoStrategy(DjangoStorage)
        backend = self.Backend_Class(strategy, redirect_uri=self.client_complete_url)

        start_url = do_auth(backend).url
        start_query = parse_qs(urlparse(start_url).query)

        # set 'state' in client
        backend.data.update({'state': start_query['state']})

        m.get(backend.USER_DATA_URL,
              json={"username": self.social_username,
                    "email": self.social_email},
              status_code=200)

        m.post(backend.ACCESS_TOKEN_URL,
               json={'access_token': self.access_token,
                     'token_type': self.token_type,
                     'expires_in': self.expires_in,
                     'scope': self.scope,
                     'refresh_token': self.refresh_token},
               status_code=200)

        def _login(backend, user, social_user):
            backend.strategy.session_set('username', user.username)

        do_complete(backend, user=user, login=_login)

        social = backend.strategy.storage.user.get_social_auth(backend.name, self.social_username)

        return strategy.session_get('username'), social, backend
开发者ID:SarvaPulla,项目名称:tethys,代码行数:32,代码来源:test_hydroshare.py


示例4: test_disconnect_with_partial_pipeline

    def test_disconnect_with_partial_pipeline(self):
        self.strategy.set_settings({
            'SOCIAL_AUTH_DISCONNECT_PIPELINE': (
                'social.pipeline.partial.save_status_to_session',
                'social.tests.pipeline.ask_for_password',
                'social.tests.pipeline.set_password',
                'social.pipeline.disconnect.allowed_to_disconnect',
                'social.pipeline.disconnect.get_entries',
                'social.pipeline.disconnect.revoke_tokens',
                'social.pipeline.disconnect.disconnect'
            )
        })
        self.do_login()
        user = User.get(self.expected_username)
        redirect = do_disconnect(self.backend, user)

        url = self.strategy.build_absolute_uri('/password')
        expect(redirect.url).to.equal(url)
        HTTPretty.register_uri(HTTPretty.GET, redirect.url, status=200,
                               body='foobar')
        HTTPretty.register_uri(HTTPretty.POST, redirect.url, status=200)

        password = 'foobar'
        requests.get(url)
        requests.post(url, data={'password': password})
        data = parse_qs(HTTPretty.last_request.body)
        expect(data['password']).to.equal(password)
        self.strategy.session_set('password', data['password'])

        redirect = do_disconnect(self.backend, user)
        expect(len(user.social)).to.equal(0)
开发者ID:Akanksha18,项目名称:Amipool,代码行数:31,代码来源:test_disconnect.py


示例5: auth_complete

    def auth_complete(self, *args, **kwargs):
        """Return user, might be logged in"""
        # Multiple unauthorized tokens are supported (see #521)
        self.process_error(self.data)
        name = self.name + 'unauthorized_token_name'
        token = None
        unauthed_tokens = self.strategy.session_get(name, [])
        if not unauthed_tokens:
            raise AuthTokenError(self, 'Missing unauthorized token')
        token_param_name = self.OAUTH_TOKEN_PARAMETER_NAME
        data_token = self.data.get(token_param_name, 'no-token')
        for unauthed_token in unauthed_tokens:
            orig_unauthed_token = unauthed_token
            if not isinstance(unauthed_token, dict):
                unauthed_token = parse_qs(unauthed_token)
            if unauthed_token.get(token_param_name) == data_token:
                self.strategy.session_set(name, list(
                    set(unauthed_tokens) -
                    set([orig_unauthed_token]))
                )
                token = unauthed_token
                break
        else:
            raise AuthTokenError(self, 'Incorrect tokens')

        try:
            access_token = self.access_token(token)
        except HTTPError as err:
            if err.response.status_code == 400:
                raise AuthCanceled(self)
            else:
                raise
        return self.do_auth(access_token, *args, **kwargs)
开发者ID:AndrewJHart,项目名称:python-social-auth,代码行数:33,代码来源:oauth.py


示例6: parse_nonce_and_return_access_token_body

 def parse_nonce_and_return_access_token_body(self, request, _url, headers):
     """
     Get the nonce from the request parameters, add it to the id_token, and
     return the complete response.
     """
     nonce = parse_qs(request.body).get('nonce')
     body = self.prepare_access_token_body(nonce=nonce)
     return 200, headers, body
开发者ID:PublicInMotionGmbH,项目名称:python-social-auth,代码行数:8,代码来源:open_id.py


示例7: do_start

 def do_start(self):
     start_url = self.strategy.start().url
     target_url = self.auth_handlers(start_url)
     response = requests.get(start_url)
     expect(response.url).to.equal(target_url)
     expect(response.text).to.equal('foobar')
     self.strategy.set_request_data(parse_qs(urlparse(target_url).query))
     return self.strategy.complete()
开发者ID:devvine,项目名称:python-social-auth,代码行数:8,代码来源:oauth.py


示例8: handle_state

    def handle_state(self, start_url, target_url):
        start_query = parse_qs(urlparse(start_url).query)
        redirect_uri = start_query.get('redirect_uri')

        if getattr(self.backend, 'STATE_PARAMETER', False):
            if start_query.get('state'):
                target_url = url_add_parameters(target_url, {
                    'state': start_query['state']
                })

        if redirect_uri and getattr(self.backend, 'REDIRECT_STATE', False):
            redirect_query = parse_qs(urlparse(redirect_uri).query)
            if redirect_query.get('redirect_state'):
                target_url = url_add_parameters(target_url, {
                    'redirect_state': redirect_query['redirect_state']
                })
        return target_url
开发者ID:2070616d,项目名称:TP3,代码行数:17,代码来源:oauth.py


示例9: do_login

    def do_login(self, after_complete_checks=True, user_data_body=None, expected_username=None):
        self.strategy.set_settings(
            {
                "SOCIAL_AUTH_GITHUB_KEY": "a-key",
                "SOCIAL_AUTH_GITHUB_SECRET": "a-secret-key",
                "SOCIAL_AUTH_LOGIN_REDIRECT_URL": self.login_redirect_url,
                "SOCIAL_AUTH_AUTHENTICATION_BACKENDS": ("social.backends.github.GithubOAuth2",),
            }
        )
        start_url = do_auth(self.backend).url
        target_url = self.strategy.build_absolute_uri("/complete/github/?code=foobar")

        start_query = parse_qs(urlparse(start_url).query)
        location_url = target_url + ("?" in target_url and "&" or "?") + "state=" + start_query["state"]
        location_query = parse_qs(urlparse(location_url).query)

        HTTPretty.register_uri(HTTPretty.GET, start_url, status=301, location=location_url)
        HTTPretty.register_uri(HTTPretty.GET, location_url, status=200, body="foobar")

        response = requests.get(start_url)
        expect(response.url).to.equal(location_url)
        expect(response.text).to.equal("foobar")

        HTTPretty.register_uri(
            HTTPretty.POST,
            uri=self.backend.ACCESS_TOKEN_URL,
            status=200,
            body=self.access_token_body or "",
            content_type="text/json",
        )

        if self.user_data_url:
            user_data_body = user_data_body or self.user_data_body or ""
            HTTPretty.register_uri(HTTPretty.GET, self.user_data_url, body=user_data_body, content_type="text/json")
        self.strategy.set_request_data(location_query, self.backend)

        def _login(backend, user, social_user):
            backend.strategy.session_set("username", user.username)

        redirect = do_complete(self.backend, user=self.user, login=_login)

        if after_complete_checks:
            expect(self.strategy.session_get("username")).to.equal(expected_username or self.expected_username)
            expect(redirect.url).to.equal(self.login_redirect_url)
        return redirect
开发者ID:humaneu,项目名称:flask_app,代码行数:45,代码来源:actions.py


示例10: do_auth

 def do_auth(self, access_token, *args, **kwargs):
     """Finish the auth process once the access_token was retrieved"""
     if not isinstance(access_token, dict):
         access_token = parse_qs(access_token)
     data = self.user_data(access_token)
     if data is not None and 'access_token' not in data:
         data['access_token'] = access_token
     kwargs.update({'response': data, 'backend': self})
     return self.strategy.authenticate(*args, **kwargs)
开发者ID:AdaLovelance,项目名称:hackingcodeschool,代码行数:9,代码来源:oauth.py


示例11: do_start

 def do_start(self):
     start_url = self.backend.start().url
     target_url = self.auth_handlers(start_url)
     response = requests.get(start_url)
     self.assertEqual(response.url, target_url)
     self.assertEqual(response.text, 'foobar')
     self.strategy.set_request_data(parse_qs(urlparse(target_url).query),
                                    self.backend)
     return self.backend.complete()
开发者ID:2070616d,项目名称:TP3,代码行数:9,代码来源:oauth.py


示例12: pipeline_slug_handling

    def pipeline_slug_handling(self, url):
        slug = 'foo-bar'
        requests.get(url)
        requests.post(url, data={'slug': slug})

        data = parse_qs(HTTPretty.last_request.body)
        expect(data['slug']).to.equal(slug)
        self.strategy.session_set('slug', data['slug'])
        return slug
开发者ID:devvine,项目名称:python-social-auth,代码行数:9,代码来源:base.py


示例13: pipeline_password_handling

    def pipeline_password_handling(self, url):
        password = 'foobar'
        requests.get(url)
        requests.post(url, data={'password': password})

        data = parse_qs(HTTPretty.last_request.body)
        expect(data['password']).to.equal(password)
        self.strategy.session_set('password', data['password'])
        return password
开发者ID:devvine,项目名称:python-social-auth,代码行数:9,代码来源:base.py


示例14: oauth_authorization_request

 def oauth_authorization_request(self, token):
     """Generate OAuth request to authorize token."""
     if not isinstance(token, dict):
         token = parse_qs(token)
     params = self.auth_extra_arguments() or {}
     params.update(self.get_scope_argument())
     params['oauth_token'] = token.get('oauth_token')
     params['redirect_uri'] = self.redirect_uri
     return self.AUTHORIZATION_URL + '?' + urlencode(params)
开发者ID:simonair,项目名称:python-social-auth,代码行数:9,代码来源:oauth.py


示例15: oauth_authorization_request

 def oauth_authorization_request(self, token):
     """Generate OAuth request to authorize token."""
     if not isinstance(token, dict):
         token = parse_qs(token)
     params = self.auth_extra_arguments() or {}
     params.update(self.get_scope_argument())
     params[self.OAUTH_TOKEN_PARAMETER_NAME] = token.get(self.OAUTH_TOKEN_PARAMETER_NAME)
     state = self.get_or_create_state()
     params[self.REDIRECT_URI_PARAMETER_NAME] = self.get_redirect_uri(state)
     return "{0}?{1}".format(self.authorization_url(), urlencode(params))
开发者ID:JonesChi,项目名称:python-social-auth,代码行数:10,代码来源:oauth.py


示例16: do_start

    def do_start(self):
        name = self.backend.name.upper().replace('-', '_')
        self.strategy.set_settings({
            'SOCIAL_AUTH_' + name + '_KEY': 'a-key',
            'SOCIAL_AUTH_' + name + '_SECRET': 'a-secret-key',
        })
        start_url = self.strategy.start().url
        target_url = self.strategy.build_absolute_uri(self.complete_url)
        start_query = parse_qs(urlparse(start_url).query)

        if self.backend.STATE_PARAMETER:
            location_url = target_url + ('?' in target_url and '&' or '?') + \
                           'state=' + start_query['state']
        elif self.backend.REDIRECT_STATE:
            location_url = target_url + ('?' in target_url and '&' or '?') + \
                           'redirect_state=' + start_query['redirect_state']
        else:
            location_url = target_url
        location_query = parse_qs(urlparse(location_url).query)

        HTTPretty.register_uri(HTTPretty.GET, start_url, status=301,
                               location=location_url)
        HTTPretty.register_uri(HTTPretty.GET, location_url, status=200,
                               body='foobar')

        response = requests.get(start_url)
        expect(response.url).to.equal(location_url)
        expect(response.text).to.equal('foobar')

        method = self.backend.ACCESS_TOKEN_METHOD == 'GET' and HTTPretty.GET \
                                                            or HTTPretty.POST
        HTTPretty.register_uri(method,
                               uri=self.backend.ACCESS_TOKEN_URL,
                               status=200,
                               body=self.access_token_body or '',
                               content_type='text/json')

        if self.user_data_url:
            HTTPretty.register_uri(HTTPretty.GET, self.user_data_url,
                                   body=self.user_data_body or '',
                                   content_type='text/json')
        self.strategy.set_request_data(location_query)
开发者ID:wwitzel3,项目名称:python-social-auth,代码行数:42,代码来源:oauth2.py


示例17: oauth_authorization_request

 def oauth_authorization_request(self, token):
     """Generate OAuth request to authorize token."""
     if not isinstance(token, dict):
         token = parse_qs(token)
     params = self.auth_extra_arguments() or {}
     params.update(self.get_scope_argument())
     params[self.OAUTH_TOKEN_PARAMETER_NAME] = token.get(
         self.OAUTH_TOKEN_PARAMETER_NAME
     )
     params[self.REDIRECT_URI_PARAMETER_NAME] = self.redirect_uri
     return self.AUTHORIZATION_URL + '?' + urlencode(params)
开发者ID:AndrewJHart,项目名称:python-social-auth,代码行数:11,代码来源:oauth.py


示例18: test_login_social_oauth1_session

 def test_login_social_oauth1_session(self):
     resp = self.client.post(reverse('login_social_session'),
         data={'provider': 'twitter'})
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(resp.data, parse_qs(self.request_token_body))
     resp = self.client.post(reverse('login_social_session'), data={
         'provider': 'twitter',
         'oauth_token': 'foobar',
         'oauth_verifier': 'overifier'
     })
     self.assertEqual(resp.status_code, 200)
开发者ID:aabmass,项目名称:django-rest-social-auth,代码行数:11,代码来源:test_social.py


示例19: handle_state

def handle_state(backend, start_url, target_url):
    try:
        if backend.STATE_PARAMETER or backend.REDIRECT_STATE:
            query = parse_qs(urlparse(start_url).query)
            target_url = target_url + ("?" in target_url and "&" or "?")
            if "state" in query or "redirect_state" in query:
                name = "state" in query and "state" or "redirect_state"
                target_url += "{0}={1}".format(name, query[name])
    except AttributeError:
        pass
    return bytes(target_url)
开发者ID:EnTeQuAk,项目名称:doit,代码行数:11,代码来源:fixtures.py


示例20: handle_state

 def handle_state(self, start_url, target_url):
     try:
         if self.backend.STATE_PARAMETER or self.backend.REDIRECT_STATE:
             query = parse_qs(urlparse(start_url).query)
             target_url = target_url + ('?' in target_url and '&' or '?')
             if 'state' in query or 'redirect_state' in query:
                 name = 'state' in query and 'state' or 'redirect_state'
                 target_url += '{0}={1}'.format(name, query[name])
     except AttributeError:
         pass
     return target_url
开发者ID:devvine,项目名称:python-social-auth,代码行数:11,代码来源:oauth.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utils.sanitize_redirect函数代码示例发布时间:2022-05-27
下一篇:
Python utils.module_member函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap