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


Python errors.InvalidBase64PaddingDefect方法代碼示例

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


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

示例1: decode_b

# 需要導入模塊: from email import errors [as 別名]
# 或者: from 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:
        return base64.b64decode(padded_encoded, validate=True), 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, validate=False), defects
            except binascii.Error:
                if i==0:
                    defects.append(errors.InvalidBase64PaddingDefect())
        else:
            # This should never happen.
            raise AssertionError("unexpected binascii.Error") 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:27,代碼來源:_encoded_words.py

示例2: test_bad_padding_in_base64_payload

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import InvalidBase64PaddingDefect [as 別名]
def test_bad_padding_in_base64_payload(self):
        source = textwrap.dedent("""\
            Subject: test
            MIME-Version: 1.0
            Content-Type: text/plain; charset="utf-8"
            Content-Transfer-Encoding: base64

            dmk
            """)
        msg = self._str_msg(source)
        with self._raise_point(errors.InvalidBase64PaddingDefect):
            payload = msg.get_payload(decode=True)
        if self.raise_expected: return
        self.assertEqual(payload, b'vi')
        self.assertDefectsEqual(self.get_defects(msg),
                                [errors.InvalidBase64PaddingDefect]) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:18,代碼來源:test_defect_handling.py

示例3: test_missing_padding

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import InvalidBase64PaddingDefect [as 別名]
def test_missing_padding(self):
        self._test(b'dmk', b'vi', [errors.InvalidBase64PaddingDefect]) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:4,代碼來源:test__encoded_words.py

示例4: test_invalid_character_and_bad_padding

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import InvalidBase64PaddingDefect [as 別名]
def test_invalid_character_and_bad_padding(self):
        self._test(b'dm\x01k', b'vi', [errors.InvalidBase64CharactersDefect,
                                       errors.InvalidBase64PaddingDefect]) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:5,代碼來源:test__encoded_words.py

示例5: test_b_undecodable_bytes_ignored_with_defect

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import InvalidBase64PaddingDefect [as 別名]
def test_b_undecodable_bytes_ignored_with_defect(self):
        self._test(b'=?us-ascii?b?dm\xACk?='.decode('us-ascii',
                                                   'surrogateescape'),
                   'vi',
                   defects = [
                    errors.InvalidBase64CharactersDefect,
                    errors.InvalidBase64PaddingDefect]) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:test__encoded_words.py

示例6: test_b_invalid_bytes_incorrect_padding

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import InvalidBase64PaddingDefect [as 別名]
def test_b_invalid_bytes_incorrect_padding(self):
        self._test('=?us-ascii?b?dm\x01k?=',
                   'vi',
                   defects = [
                    errors.InvalidBase64CharactersDefect,
                    errors.InvalidBase64PaddingDefect]) 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:8,代碼來源:test__encoded_words.py

示例7: test_get_unstructured_missing_base64_padding

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import InvalidBase64PaddingDefect [as 別名]
def test_get_unstructured_missing_base64_padding(self):
        self._test_get_x(self._get_unst,
            '=?utf-8?b?dmk?=',
            'vi',
            'vi',
            [errors.InvalidBase64PaddingDefect],
            '') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:9,代碼來源:test__header_value_parser.py

示例8: test_get_unstructured_invalid_base64_character_and_bad_padding

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import InvalidBase64PaddingDefect [as 別名]
def test_get_unstructured_invalid_base64_character_and_bad_padding(self):
        self._test_get_x(self._get_unst,
            '=?utf-8?b?dm\x01k?=',
            'vi',
            'vi',
            [errors.InvalidBase64CharactersDefect,
             errors.InvalidBase64PaddingDefect],
            '') 
開發者ID:Microvellum,項目名稱:Fluid-Designer,代碼行數:10,代碼來源:test__header_value_parser.py

示例9: decode_b

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import InvalidBase64PaddingDefect [as 別名]
def decode_b(encoded):
    # First try encoding with validate=True, fixing the padding if needed.
    # This will succeed only if encoded includes no invalid characters.
    pad_err = len(encoded) % 4
    missing_padding = b'==='[:4-pad_err] if pad_err else b''
    try:
        return (
            base64.b64decode(encoded + missing_padding, validate=True),
            [errors.InvalidBase64PaddingDefect()] if pad_err else [],
        )
    except binascii.Error:
        # Since we had correct padding, this is likely an invalid char error.
        #
        # The non-alphabet characters are ignored as far as padding
        # goes, but we don't know how many there are.  So try without adding
        # padding to see if it works.
        try:
            return (
                base64.b64decode(encoded, validate=False),
                [errors.InvalidBase64CharactersDefect()],
            )
        except binascii.Error:
            # Add as much padding as could possibly be necessary (extra padding
            # is ignored).
            try:
                return (
                    base64.b64decode(encoded + b'==', validate=False),
                    [errors.InvalidBase64CharactersDefect(),
                     errors.InvalidBase64PaddingDefect()],
                )
            except binascii.Error:
                # This only happens when the encoded string's length is 1 more
                # than a multiple of 4, which is invalid.
                #
                # bpo-27397: Just return the encoded string since there's no
                # way to decode.
                return encoded, [errors.InvalidBase64LengthDefect()] 
開發者ID:CedricGuillemet,項目名稱:Imogen,代碼行數:39,代碼來源:_encoded_words.py

示例10: test_missing_padding

# 需要導入模塊: from email import errors [as 別名]
# 或者: from email.errors import InvalidBase64PaddingDefect [as 別名]
def test_missing_padding(self):
        # 1 missing padding character
        self._test(b'dmk', b'vi', [errors.InvalidBase64PaddingDefect])
        # 2 missing padding characters
        self._test(b'dg', b'v', [errors.InvalidBase64PaddingDefect]) 
開發者ID:bkerler,項目名稱:android_universal,代碼行數:7,代碼來源:test__encoded_words.py


注:本文中的email.errors.InvalidBase64PaddingDefect方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。