当前位置: 首页>>代码示例>>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;未经允许,请勿转载。