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


Python common.urlencode方法代码示例

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


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

示例1: create_access_token

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import urlencode [as 别名]
def create_access_token(self, request, credentials):
        """Create and save a new access token.

        Similar to OAuth 2, indication of granted scopes will be included as a
        space separated list in ``oauth_authorized_realms``.

        :param request: An oauthlib.common.Request object.
        :returns: The token as an urlencoded string.
        """
        request.realms = self.request_validator.get_realms(
            request.resource_owner_key, request)
        token = {
            'oauth_token': self.token_generator(),
            'oauth_token_secret': self.token_generator(),
            # Backport the authorized scopes indication used in OAuth2
            'oauth_authorized_realms': ' '.join(request.realms)
        }
        token.update(credentials)
        self.request_validator.save_access_token(token, request)
        return urlencode(token.items()) 
开发者ID:kylebebak,项目名称:Requester,代码行数:22,代码来源:access_token.py

示例2: _render

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import urlencode [as 别名]
def _render(self, request, formencode=False, realm=None):
        """Render a signed request according to signature type

        Returns a 3-tuple containing the request URI, headers, and body.

        If the formencode argument is True and the body contains parameters, it
        is escaped and returned as a valid formencoded string.
        """
        # TODO what if there are body params on a header-type auth?
        # TODO what if there are query params on a body-type auth?

        uri, headers, body = request.uri, request.headers, request.body

        # TODO: right now these prepare_* methods are very narrow in scope--they
        # only affect their little thing. In some cases (for example, with
        # header auth) it might be advantageous to allow these methods to touch
        # other parts of the request, like the headers—so the prepare_headers
        # method could also set the Content-Type header to x-www-form-urlencoded
        # like the spec requires. This would be a fundamental change though, and
        # I'm not sure how I feel about it.
        if self.signature_type == SIGNATURE_TYPE_AUTH_HEADER:
            headers = parameters.prepare_headers(
                request.oauth_params, request.headers, realm=realm)
        elif self.signature_type == SIGNATURE_TYPE_BODY and request.decoded_body is not None:
            body = parameters.prepare_form_encoded_body(
                request.oauth_params, request.decoded_body)
            if formencode:
                body = urlencode(body)
            headers['Content-Type'] = 'application/x-www-form-urlencoded'
        elif self.signature_type == SIGNATURE_TYPE_QUERY:
            uri = parameters.prepare_request_uri_query(
                request.oauth_params, request.uri)
        else:
            raise ValueError('Unknown signature type specified.')

        return uri, headers, body 
开发者ID:kylebebak,项目名称:Requester,代码行数:38,代码来源:__init__.py

示例3: prepare_request_uri_query

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import urlencode [as 别名]
def prepare_request_uri_query(oauth_params, uri):
    """Prepare the Request URI Query.

    Per `section 3.5.3`_ of the spec.

    .. _`section 3.5.3`: https://tools.ietf.org/html/rfc5849#section-3.5.3

    """
    # append OAuth params to the existing set of query components
    sch, net, path, par, query, fra = urlparse(uri)
    query = urlencode(
        _append_params(oauth_params, extract_params(query) or []))
    return urlunparse((sch, net, path, par, query, fra)) 
开发者ID:kylebebak,项目名称:Requester,代码行数:15,代码来源:parameters.py

示例4: create_request_token

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import urlencode [as 别名]
def create_request_token(self, request, credentials):
        """Create and save a new request token.

        :param request: An oauthlib.common.Request object.
        :param credentials: A dict of extra token credentials.
        :returns: The token as an urlencoded string.
        """
        token = {
            'oauth_token': self.token_generator(),
            'oauth_token_secret': self.token_generator(),
            'oauth_callback_confirmed': 'true'
        }
        token.update(credentials)
        self.request_validator.save_request_token(token, request)
        return urlencode(token.items()) 
开发者ID:kylebebak,项目名称:Requester,代码行数:17,代码来源:request_token.py

示例5: urlencoded

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import urlencode [as 别名]
def urlencoded(self):
        return urlencode(self.twotuples) 
开发者ID:kylebebak,项目名称:Requester,代码行数:4,代码来源:errors.py

示例6: require_oauth

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import urlencode [as 别名]
def require_oauth(self, *realms, **kwargs):
        """Protect resource with specified scopes."""

        def wrapper(f):
            @wraps(f)
            def decorated(*args, **kwargs):
                for func in self._before_request_funcs:
                    func()

                if hasattr(request, 'oauth') and request.oauth:
                    return f(*args, **kwargs)

                server = self.server
                uri, http_method, body, headers = extract_params()
                try:
                    valid, req = server.validate_protected_resource_request(
                        uri, http_method, body, headers, realms)
                except Exception as e:
                    log.warn('Exception: %r', e)
                    e.urlencoded = urlencode([('error', 'unknown')])
                    e.status_code = 400
                    return _error_response(e)
                for func in self._after_request_funcs:
                    valid, req = func(valid, req)

                if not valid:
                    return abort(401)
                # alias user for convenience
                req.user = req.access_token.user
                request.oauth = req
                return f(*args, **kwargs)

            return decorated

        return wrapper 
开发者ID:gita,项目名称:BhagavadGita,代码行数:37,代码来源:oauth1.py

示例7: prepare_request_uri_query

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import urlencode [as 别名]
def prepare_request_uri_query(oauth_params, uri):
    """Prepare the Request URI Query.

    Per `section 3.5.3`_ of the spec.

    .. _`section 3.5.3`: http://tools.ietf.org/html/rfc5849#section-3.5.3

    """
    # append OAuth params to the existing set of query components
    sch, net, path, par, query, fra = urlparse(uri)
    query = urlencode(
        _append_params(oauth_params, extract_params(query) or []))
    return urlunparse((sch, net, path, par, query, fra)) 
开发者ID:Tautulli,项目名称:Tautulli,代码行数:15,代码来源:parameters.py

示例8: fetch_from_twitter

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import urlencode [as 别名]
def fetch_from_twitter(
    credentials,
    path,
    params: List[Tuple[str, str]],
    since_id: Optional[int],
    per_page: int,
    n_pages: int,
) -> List[Dict[str, Any]]:
    oauth_client = oauth1.Client(
        client_key=credentials["consumer_key"],
        client_secret=credentials["consumer_secret"],
        resource_owner_key=credentials["resource_owner_key"],
        resource_owner_secret=credentials["resource_owner_secret"],
    )

    page_dataframes = [create_empty_table()]

    max_id = None
    async with aiohttp.ClientSession() as session:  # aiohttp timeout of 5min
        for page in range(n_pages):
            # Assume {path} contains '?' already
            page_params = [
                *params,
                ("tweet_mode", "extended"),
                ("count", str(per_page)),
            ]
            if since_id:
                page_params.append(("since_id", str(since_id)))
            if max_id:
                page_params.append(("max_id", str(max_id)))

            page_url = f"https://api.twitter.com/1.1/{path}?{urlencode(page_params)}"

            page_url, headers, body = oauth_client.sign(
                page_url, headers={"Accept": "application/json"}
            )

            # aiohttp internally performs URL canonization before sending
            # request. DISABLE THIS: it rewrites the signed URL!
            #
            # https://github.com/aio-libs/aiohttp/issues/3424
            page_url = yarl.URL(page_url, encoded=True)  # disable magic

            response = await session.get(page_url, headers=headers)
            response.raise_for_status()
            page_statuses = await response.json()

            if isinstance(page_statuses, dict) and "statuses" in page_statuses:
                # /search wraps result in {}
                page_statuses = page_statuses["statuses"]

            if not page_statuses:
                break

            # Parse one page at a time, instead of parsing all at the end.
            # Should save a bit of memory and make a smaller CPU-blip in our
            # event loop.
            page_dataframes.append(statuses_to_dataframe(page_statuses))
            max_id = page_statuses[-1]["id"] - 1

    return pd.concat(page_dataframes, ignore_index=True, sort=False) 
开发者ID:CJWorkbench,项目名称:cjworkbench,代码行数:63,代码来源:twitter.py


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