當前位置: 首頁>>代碼示例>>Python>>正文


Python errors.InvalidBase64PaddingDefect方法代碼示例

本文整理匯總了Python中future.backports.email.errors.InvalidBase64PaddingDefect方法的典型用法代碼示例。如果您正苦於以下問題:Python errors.InvalidBase64PaddingDefect方法的具體用法?Python errors.InvalidBase64PaddingDefect怎麽用?Python errors.InvalidBase64PaddingDefect使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在future.backports.email.errors的用法示例。


在下文中一共展示了errors.InvalidBase64PaddingDefect方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: decode_b

# 需要導入模塊: from future.backports.email import errors [as 別名]
# 或者: from future.backports.email.errors import InvalidBase64PaddingDefect [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.InvalidBase64PaddingDefect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。