當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。