[New-bugs-announce] [issue19957] Minor refactor of Lib/email/encoders.py

Vajrasky Kok report at bugs.python.org
Thu Dec 12 07:21:19 CET 2013


New submission from Vajrasky Kok:

In Lib/email/encoders.py:

def encode_7or8bit(msg):
    """Set the Content-Transfer-Encoding header to 7bit or 8bit."""
    orig = msg.get_payload(decode=True)
    if orig is None:
        # There's no payload.  For backwards compatibility we use 7bit
        msg['Content-Transfer-Encoding'] = '7bit'
        return
    # We play a trick to make this go fast.  If encoding/decode to ASCII
    # succeeds, we know the data must be 7bit, otherwise treat it as 8bit.
    try:
        if isinstance(orig, str):
            orig.encode('ascii')
        else:
            orig.decode('ascii')
    except UnicodeError:
        charset = msg.get_charset()


msg.get_payload(decode=True) always return bytes so there is no point of these lines:

        if isinstance(orig, str):
            orig.encode('ascii')
        else:
            orig.decode('ascii')

Attached the patch to refactor this function.

----------
components: email
files: minor_refactor_encoders_in_email_lib.patch
keywords: patch
messages: 205944
nosy: barry, r.david.murray, vajrasky
priority: normal
severity: normal
status: open
title: Minor refactor of Lib/email/encoders.py
versions: Python 3.4
Added file: http://bugs.python.org/file33099/minor_refactor_encoders_in_email_lib.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue19957>
_______________________________________


More information about the New-bugs-announce mailing list