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


Python Client._render方法代码示例

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


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

示例1: _get_authorization_header

# 需要导入模块: from oauthlib.oauth1 import Client [as 别名]
# 或者: from oauthlib.oauth1.Client import _render [as 别名]
def _get_authorization_header(request, client_key, client_secret):
    """
    Get proper HTTP Authorization header for a given request

    Arguments:
        request: Request object to log Authorization header for

    Returns:
        authorization header
    """
    sha1 = hashlib.sha1()
    body = request.body or ''
    sha1.update(body)
    oauth_body_hash = unicode(base64.b64encode(
        sha1.digest()  # pylint: disable=too-many-function-args
    ))
    client = Client(client_key, client_secret)
    params = client.get_oauth_params(None)
    params.append((u'oauth_body_hash', oauth_body_hash))
    mock_request = mock.Mock(
        uri=unicode(urllib.unquote(request.url)),
        headers=request.headers,
        body=u'',
        decoded_body=u'',
        oauth_params=params,
        http_method=unicode(request.method),
    )
    sig = client.get_oauth_signature(mock_request)
    mock_request.oauth_params.append((u'oauth_signature', sig))

    _, headers, _ = client._render(  # pylint: disable=protected-access
        mock_request
    )
    return headers['Authorization']
开发者ID:UBC-Astrophysics,项目名称:TeachingScripts,代码行数:36,代码来源:upload_csv.py

示例2: _log_correct_authorization_header

# 需要导入模块: from oauthlib.oauth1 import Client [as 别名]
# 或者: from oauthlib.oauth1.Client import _render [as 别名]
    def _log_correct_authorization_header(self, request):
        """
        Helper function that logs proper HTTP Authorization header for a given request

        Used only in debug situations, this logs the correct Authorization header based on
        the request header and body according to OAuth 1 Body signing

        Arguments:
            request (xblock.django.request.DjangoWebobRequest):  Request object to log Authorization header for

        Returns:
            nothing
        """
        sha1 = hashlib.sha1()
        sha1.update(request.body)
        oauth_body_hash = unicode(base64.b64encode(sha1.digest()))
        log.debug("[LTI] oauth_body_hash = {}".format(oauth_body_hash))
        client_key, client_secret = self.get_client_key_secret()
        client = Client(client_key, client_secret)
        mock_request = mock.Mock(
            uri=unicode(urllib.unquote(request.url)),
            headers=request.headers,
            body=u"",
            decoded_body=u"",
            http_method=unicode(request.method),
        )
        params = client.get_oauth_params(mock_request)
        mock_request.oauth_params = params
        mock_request.oauth_params.append((u'oauth_body_hash', oauth_body_hash))
        sig = client.get_oauth_signature(mock_request)
        mock_request.oauth_params.append((u'oauth_signature', sig))

        _, headers, _ = client._render(mock_request)  # pylint: disable=protected-access
        log.debug("\n\n#### COPY AND PASTE AUTHORIZATION HEADER ####\n{}\n####################################\n\n"
                  .format(headers['Authorization']))
开发者ID:dehamzah,项目名称:edx-platform,代码行数:37,代码来源:lti_2_util.py

示例3: _get_authorization_header

# 需要导入模块: from oauthlib.oauth1 import Client [as 别名]
# 或者: from oauthlib.oauth1.Client import _render [as 别名]
def _get_authorization_header(request, client_key, client_secret):
    """
    Get proper HTTP Authorization header for a given request

    Arguments:
        request: Request object to log Authorization header for

    Returns:
        authorization header
    """
    sha1 = hashlib.sha1()
    body = request.body or ''
    sha1.update(body)
    oauth_body_hash = unicode(base64.b64encode(
        sha1.digest()  # pylint: disable=too-many-function-args
    ))
    client = Client(client_key, client_secret)
    params = client.get_oauth_params(request)
    params.append((u'oauth_body_hash', oauth_body_hash))

    blank_request = Request(urllib.unquote(request.url), http_method=request.method, body='', headers=request.headers, encoding='utf_8')
    blank_request.oauth_params = params
    blank_request.decoded_body = ''

    signature = client.get_oauth_signature(blank_request)
    blank_request.oauth_params.append((u'oauth_signature', signature))
    headers = client._render(  # pylint: disable=protected-access
        blank_request
    )[1]
    return headers['Authorization']
开发者ID:caesar2164,项目名称:edx-platform,代码行数:32,代码来源:lti_connection.py


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