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


Python common.to_unicode方法代码示例

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


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

示例1: linkedin_compliance_fix

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def linkedin_compliance_fix(session):

    def _missing_token_type(r):
        token = loads(r.text)
        token['token_type'] = 'Bearer'
        r._content = to_unicode(dumps(token)).encode('UTF-8')
        return r

    def _non_compliant_param_name(url, headers, data):
        token = [('oauth2_access_token', session.access_token)]
        url = add_params_to_uri(url, token)
        return url, headers, data

    session._client.default_token_placement = 'query'
    session.register_compliance_hook('access_token_response',
                                     _missing_token_type)
    session.register_compliance_hook('protected_request',
                                     _non_compliant_param_name)
    return session 
开发者ID:kylebebak,项目名称:Requester,代码行数:21,代码来源:linkedin.py

示例2: facebook_compliance_fix

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def facebook_compliance_fix(session):

    def _compliance_fix(r):
        # if Facebook claims to be sending us json, let's trust them.
        if 'application/json' in r.headers.get('content-type', {}):
            return r

        # Facebook returns a content-type of text/plain when sending their
        # x-www-form-urlencoded responses, along with a 200. If not, let's
        # assume we're getting JSON and bail on the fix.
        if 'text/plain' in r.headers.get('content-type', {}) and r.status_code == 200:
            token = dict(parse_qsl(r.text, keep_blank_values=True))
        else:
            return r

        expires = token.get('expires')
        if expires is not None:
            token['expires_in'] = expires
        token['token_type'] = 'Bearer'
        r._content = to_unicode(dumps(token)).encode('UTF-8')
        return r

    session.register_compliance_hook('access_token_response', _compliance_fix)
    return session 
开发者ID:kylebebak,项目名称:Requester,代码行数:26,代码来源:facebook.py

示例3: mailchimp_compliance_fix

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def mailchimp_compliance_fix(session):
    def _null_scope(r):
        token = json.loads(r.text)
        if 'scope' in token and token['scope'] is None:
            token.pop('scope')
        r._content = to_unicode(json.dumps(token)).encode('utf-8')
        return r

    def _non_zero_expiration(r):
        token = json.loads(r.text)
        if 'expires_in' in token and token['expires_in'] == 0:
            token['expires_in'] = 3600
        r._content = to_unicode(json.dumps(token)).encode('utf-8')
        return r

    session.register_compliance_hook('access_token_response', _null_scope)
    session.register_compliance_hook('access_token_response', _non_zero_expiration)
    return session 
开发者ID:kylebebak,项目名称:Requester,代码行数:20,代码来源:mailchimp.py

示例4: douban_compliance_fix

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def douban_compliance_fix(session):

    def fix_token_type(r):
        token = json.loads(r.text)
        token.setdefault('token_type', 'Bearer')
        fixed_token = json.dumps(token)
        r._content = to_unicode(fixed_token).encode('utf-8')
        return r

    session._client_default_token_placement = 'query'
    session.register_compliance_hook('access_token_response', fix_token_type)

    return session 
开发者ID:kylebebak,项目名称:Requester,代码行数:15,代码来源:douban.py

示例5: fitbit_compliance_fix

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def fitbit_compliance_fix(session):

    def _missing_error(r):
        token = loads(r.text)
        if 'errors' in token:
            # Set the error to the first one we have
            token['error'] = token['errors'][0]['errorType']
        r._content = to_unicode(dumps(token)).encode('UTF-8')
        return r

    session.register_compliance_hook('access_token_response', _missing_error)
    session.register_compliance_hook('refresh_token_response', _missing_error)
    return session 
开发者ID:kylebebak,项目名称:Requester,代码行数:15,代码来源:fitbit.py

示例6: weibo_compliance_fix

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def weibo_compliance_fix(session):

    def _missing_token_type(r):
        token = loads(r.text)
        token['token_type'] = 'Bearer'
        r._content = to_unicode(dumps(token)).encode('UTF-8')
        return r

    session._client.default_token_placement = 'query'
    session.register_compliance_hook('access_token_response',
                                     _missing_token_type)
    return session 
开发者ID:kylebebak,项目名称:Requester,代码行数:14,代码来源:weibo.py

示例7: decode_base64

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def decode_base64(text, encoding='utf-8'):
    """Decode base64 string."""
    text = to_bytes(text, encoding)
    return to_unicode(base64.b64decode(text), encoding) 
开发者ID:gita,项目名称:BhagavadGita,代码行数:6,代码来源:utils.py

示例8: _encode

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def _encode(text, encoding='utf-8'):
    if encoding:
        return to_unicode(text, encoding)
    return text 
开发者ID:gita,项目名称:BhagavadGita,代码行数:6,代码来源:client.py

示例9: dummy_client

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def dummy_client(self):
        return to_unicode('dummy_client', 'utf-8') 
开发者ID:gita,项目名称:BhagavadGita,代码行数:4,代码来源:oauth1.py

示例10: dummy_request_token

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def dummy_request_token(self):
        return to_unicode('dummy_request_token', 'utf-8') 
开发者ID:gita,项目名称:BhagavadGita,代码行数:4,代码来源:oauth1.py

示例11: dummy_access_token

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def dummy_access_token(self):
        return to_unicode('dummy_access_token', 'utf-8') 
开发者ID:gita,项目名称:BhagavadGita,代码行数:4,代码来源:oauth1.py

示例12: prepare_request_body

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def prepare_request_body(
        self,
        private_key=None,
        subject=None,
        issuer=None,
        audience=None,
        expires_at=None,
        issued_at=None,
        extra_claims=None,
        body="",
        scope=None,
        **kwargs
    ):
        key = private_key or self.private_key
        if not key:
            raise ValueError(
                "Encryption key must be supplied to make JWT token requests."
            )

        claim = {
            "iss": issuer or self.issuer,
            "aud": audience or self.audience,
            "sub": subject,
            "exp": int(expires_at or time.time() + 3600),
            "iat": int(issued_at or time.time()),
            "scope": scope,
        }

        for attr in {"iss", "aud"}:
            if claim[attr] is None:
                raise ValueError(
                    "Claim must include {} but none was given.".format(attr)
                )

        if "not_before" in kwargs:
            claim["nbf"] = kwargs.pop("not_before")

        if "jwt_id" in kwargs:
            claim["jti"] = kwargs.pop("jwt_id")

        claim.update(extra_claims or {})

        assertion = jwt.encode(claim, key, "RS256")
        assertion = to_unicode(assertion)

        return prepare_token_request(
            self.grant_type, body=body, assertion=assertion, **kwargs
        ) 
开发者ID:pypa,项目名称:linehaul,代码行数:50,代码来源:oauth2.py

示例13: __init__

# 需要导入模块: from oauthlib import common [as 别名]
# 或者: from oauthlib.common import to_unicode [as 别名]
def __init__(self, client_key,
                 client_secret=None,
                 resource_owner_key=None,
                 resource_owner_secret=None,
                 callback_uri=None,
                 signature_method=SIGNATURE_HMAC,
                 signature_type=SIGNATURE_TYPE_AUTH_HEADER,
                 rsa_key=None, verifier=None, realm=None,
                 encoding='utf-8', decoding=None,
                 nonce=None, timestamp=None):
        """Create an OAuth 1 client.

        :param client_key: Client key (consumer key), mandatory.
        :param resource_owner_key: Resource owner key (oauth token).
        :param resource_owner_secret: Resource owner secret (oauth token secret).
        :param callback_uri: Callback used when obtaining request token.
        :param signature_method: SIGNATURE_HMAC, SIGNATURE_RSA or SIGNATURE_PLAINTEXT.
        :param signature_type: SIGNATURE_TYPE_AUTH_HEADER (default),
                               SIGNATURE_TYPE_QUERY or SIGNATURE_TYPE_BODY
                               depending on where you want to embed the oauth
                               credentials.
        :param rsa_key: RSA key used with SIGNATURE_RSA.
        :param verifier: Verifier used when obtaining an access token.
        :param realm: Realm (scope) to which access is being requested.
        :param encoding: If you provide non-unicode input you may use this
                         to have oauthlib automatically convert.
        :param decoding: If you wish that the returned uri, headers and body
                         from sign be encoded back from unicode, then set
                         decoding to your preferred encoding, i.e. utf-8.
        :param nonce: Use this nonce instead of generating one. (Mainly for testing)
        :param timestamp: Use this timestamp instead of using current. (Mainly for testing)
        """
        # Convert to unicode using encoding if given, else assume unicode
        encode = lambda x: to_unicode(x, encoding) if encoding else x

        self.client_key = encode(client_key)
        self.client_secret = encode(client_secret)
        self.resource_owner_key = encode(resource_owner_key)
        self.resource_owner_secret = encode(resource_owner_secret)
        self.signature_method = encode(signature_method)
        self.signature_type = encode(signature_type)
        self.callback_uri = encode(callback_uri)
        self.rsa_key = encode(rsa_key)
        self.verifier = encode(verifier)
        self.realm = encode(realm)
        self.encoding = encode(encoding)
        self.decoding = encode(decoding)
        self.nonce = encode(nonce)
        self.timestamp = encode(timestamp) 
开发者ID:kylebebak,项目名称:Requester,代码行数:51,代码来源:__init__.py


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