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


Python urls.url_decode_stream方法代碼示例

本文整理匯總了Python中werkzeug.urls.url_decode_stream方法的典型用法代碼示例。如果您正苦於以下問題:Python urls.url_decode_stream方法的具體用法?Python urls.url_decode_stream怎麽用?Python urls.url_decode_stream使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在werkzeug.urls的用法示例。


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

示例1: request_authentication

# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_decode_stream [as 別名]
def request_authentication(
        self, redirect_url: str
    ) -> AuthenticationContinuation:
        response = self.request('POST', self.REQUEST_TOKEN_URL.format(self))
        request_token = url_decode_stream(response)
        response.close()
        return AuthenticationContinuation(
            self.AUTHORIZE_URL.format(self) + '?' + url_encode({
                'oauth_token': request_token['oauth_token'],
                'oauth_callback': redirect_url
            }),
            (request_token['oauth_token'], request_token['oauth_token_secret'])
        ) 
開發者ID:spoqa,項目名稱:geofront,代碼行數:15,代碼來源:stash.py

示例2: authenticate

# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_decode_stream [as 別名]
def authenticate(self,
                     state,
                     requested_redirect_url: str,
                     wsgi_environ: Mapping[str, object]) -> Identity:
        logger = logging.getLogger(__name__ + '.StashTeam.authenticate')
        logger.debug('state = %r', state)
        try:
            oauth_token, oauth_token_secret = state
        except ValueError:
            raise AuthenticationError()
        req = Request(wsgi_environ, populate_request=False, shallow=True)
        args = cast(ImmutableMultiDict, req.args)
        logger.debug('req.args = %r', args)
        if args.get('oauth_token') != oauth_token:
            raise AuthenticationError()
        response = self.request(
            'POST', self.ACCESS_TOKEN_URL.format(self),
            resource_owner_key=oauth_token,
            resource_owner_secret=oauth_token_secret
        )
        access_token = url_decode_stream(response)
        logger.debug('access_token = %r', access_token)
        response.close()
        response = self.request(
            'GET', self.USER_URL.format(self),
            resource_owner_key=access_token['oauth_token'],
            resource_owner_secret=access_token['oauth_token_secret']
        )
        whoami = response.read().decode('utf-8')
        return Identity(
            type(self),
            self.USER_PROFILE_URL.format(self, whoami),
            (access_token['oauth_token'], access_token['oauth_token_secret'])
        ) 
開發者ID:spoqa,項目名稱:geofront,代碼行數:36,代碼來源:stash.py

示例3: _parse_urlencoded

# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_decode_stream [as 別名]
def _parse_urlencoded(self, stream, mimetype, content_length, options):
        if self.max_form_memory_size is not None and \
           content_length is not None and \
           content_length > self.max_form_memory_size:
            raise exceptions.RequestEntityTooLarge()
        form = url_decode_stream(stream, self.charset,
                                 errors=self.errors, cls=self.cls)
        return stream, form, self.cls()

    #: mapping of mimetypes to parsing functions 
開發者ID:jpush,項目名稱:jbox,代碼行數:12,代碼來源:formparser.py

示例4: test_streamed_url_decoding

# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_decode_stream [as 別名]
def test_streamed_url_decoding(self):
        item1 = u'a' * 100000
        item2 = u'b' * 400
        string = ('a=%s&b=%s&c=%s' % (item1, item2, item2)).encode('ascii')
        gen = urls.url_decode_stream(BytesIO(string), limit=len(string),
                                     return_iterator=True)
        self.assert_strict_equal(next(gen), ('a', item1))
        self.assert_strict_equal(next(gen), ('b', item2))
        self.assert_strict_equal(next(gen), ('c', item2))
        self.assert_raises(StopIteration, lambda: next(gen)) 
開發者ID:GeekTrainer,項目名稱:Flask,代碼行數:12,代碼來源:urls.py

示例5: test_stream_decoding_string_fails

# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_decode_stream [as 別名]
def test_stream_decoding_string_fails(self):
        self.assert_raises(TypeError, urls.url_decode_stream, 'testing') 
開發者ID:GeekTrainer,項目名稱:Flask,代碼行數:4,代碼來源:urls.py

示例6: authenticate

# 需要導入模塊: from werkzeug import urls [as 別名]
# 或者: from werkzeug.urls import url_decode_stream [as 別名]
def authenticate(
        self,
        state,
        requested_redirect_url: str,
        wsgi_environ: Mapping[str, object]
    ) -> Identity:
        logger = self.logger.getChild('authenticate')
        req = Request(wsgi_environ, populate_request=False, shallow=True)
        args = cast(ImmutableMultiDict, req.args)
        try:
            code = args['code']
            if args['state'] != state:
                raise AuthenticationError()
        except KeyError:
            raise AuthenticationError()
        data = url_encode({
            'client_id': self.client_id,
            'client_secret': self.client_secret,
            'code': code,
            'redirect_uri': requested_redirect_url,
            'grant_type': 'authorization_code',
        }).encode()
        try:
            response = urllib.request.urlopen(self.access_token_url, data)
        except urllib.error.HTTPError as e:
            logger.debug('Response of POST %s (with/ %r): %s\n%s',
                         self.access_token_url, data, e.code, e.read())
            raise
        assert isinstance(response, http.client.HTTPResponse), \
            'isinstance(response, {0.__module__}.{0.__qualname__})'.format(
                type(response))
        headers = getattr(response, 'headers')  # workaround mypy
        content_type = headers['Content-Type']
        mimetype, options = parse_options_header(content_type)
        if mimetype == 'application/x-www-form-urlencoded':
            token_data = url_decode_stream(response)
        elif mimetype == 'application/json':
            charset = options.get('charset', 'utf-8')
            token_data = json.load(
                io.TextIOWrapper(cast(IO[bytes], response), encoding=charset)
            )
        else:
            response.close()
            raise AuthenticationError(
                '{} sent unsupported content type: {}'.format(
                    self.access_token_url,
                    content_type
                )
            )
        response.close()
        identity = self.determine_identity(token_data['access_token'])
        if self.authorize(identity):
            return identity
        raise AuthenticationError(
            self.unauthorized_identity_message_format.format(
                identity=identity, team=self
            )
        ) 
開發者ID:spoqa,項目名稱:geofront,代碼行數:60,代碼來源:oauth.py


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