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


Python errors.InvalidBase64CharactersDefect方法代码示例

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


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

示例1: decode_b

# 需要导入模块: from future.backports.email import errors [as 别名]
# 或者: from future.backports.email.errors import InvalidBase64CharactersDefect [as 别名]
def decode_b(encoded):
    defects = []
    pad_err = len(encoded) % 4
    if pad_err:
        defects.append(errors.InvalidBase64PaddingDefect())
        padded_encoded = encoded + b'==='[:4-pad_err]
    else:
        padded_encoded = encoded
    try:
        # The validate kwarg to b64decode is not supported in Py2.x
        if not re.match(b'^[A-Za-z0-9+/]*={0,2}$', padded_encoded):
            raise binascii.Error('Non-base64 digit found')
        return base64.b64decode(padded_encoded), defects
    except binascii.Error:
        # Since we had correct padding, this must an invalid char error.
        defects = [errors.InvalidBase64CharactersDefect()]
        # The non-alphabet characters are ignored as far as padding
        # goes, but we don't know how many there are.  So we'll just
        # try various padding lengths until something works.
        for i in 0, 1, 2, 3:
            try:
                return base64.b64decode(encoded+b'='*i), defects
            except (binascii.Error, TypeError):    # Py2 raises a TypeError
                if i==0:
                    defects.append(errors.InvalidBase64PaddingDefect())
        else:
            # This should never happen.
            raise AssertionError("unexpected binascii.Error") 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:30,代码来源:_encoded_words.py


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