Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../email
File: encoders.py
# Copyright (C) 2001-2006 Python Software Foundation
[0] Fix | Delete
# Author: Barry Warsaw
[1] Fix | Delete
# Contact: email-sig@python.org
[2] Fix | Delete
[3] Fix | Delete
"""Encodings and related functions."""
[4] Fix | Delete
[5] Fix | Delete
__all__ = [
[6] Fix | Delete
'encode_7or8bit',
[7] Fix | Delete
'encode_base64',
[8] Fix | Delete
'encode_noop',
[9] Fix | Delete
'encode_quopri',
[10] Fix | Delete
]
[11] Fix | Delete
[12] Fix | Delete
import base64
[13] Fix | Delete
[14] Fix | Delete
from quopri import encodestring as _encodestring
[15] Fix | Delete
[16] Fix | Delete
[17] Fix | Delete
[18] Fix | Delete
def _qencode(s):
[19] Fix | Delete
enc = _encodestring(s, quotetabs=True)
[20] Fix | Delete
# Must encode spaces, which quopri.encodestring() doesn't do
[21] Fix | Delete
return enc.replace(' ', '=20')
[22] Fix | Delete
[23] Fix | Delete
[24] Fix | Delete
def _bencode(s):
[25] Fix | Delete
# We can't quite use base64.encodestring() since it tacks on a "courtesy
[26] Fix | Delete
# newline". Blech!
[27] Fix | Delete
if not s:
[28] Fix | Delete
return s
[29] Fix | Delete
hasnewline = (s[-1] == '\n')
[30] Fix | Delete
value = base64.encodestring(s)
[31] Fix | Delete
if not hasnewline and value[-1] == '\n':
[32] Fix | Delete
return value[:-1]
[33] Fix | Delete
return value
[34] Fix | Delete
[35] Fix | Delete
[36] Fix | Delete
[37] Fix | Delete
def encode_base64(msg):
[38] Fix | Delete
"""Encode the message's payload in Base64.
[39] Fix | Delete
[40] Fix | Delete
Also, add an appropriate Content-Transfer-Encoding header.
[41] Fix | Delete
"""
[42] Fix | Delete
orig = msg.get_payload()
[43] Fix | Delete
encdata = _bencode(orig)
[44] Fix | Delete
msg.set_payload(encdata)
[45] Fix | Delete
msg['Content-Transfer-Encoding'] = 'base64'
[46] Fix | Delete
[47] Fix | Delete
[48] Fix | Delete
[49] Fix | Delete
def encode_quopri(msg):
[50] Fix | Delete
"""Encode the message's payload in quoted-printable.
[51] Fix | Delete
[52] Fix | Delete
Also, add an appropriate Content-Transfer-Encoding header.
[53] Fix | Delete
"""
[54] Fix | Delete
orig = msg.get_payload()
[55] Fix | Delete
encdata = _qencode(orig)
[56] Fix | Delete
msg.set_payload(encdata)
[57] Fix | Delete
msg['Content-Transfer-Encoding'] = 'quoted-printable'
[58] Fix | Delete
[59] Fix | Delete
[60] Fix | Delete
[61] Fix | Delete
def encode_7or8bit(msg):
[62] Fix | Delete
"""Set the Content-Transfer-Encoding header to 7bit or 8bit."""
[63] Fix | Delete
orig = msg.get_payload()
[64] Fix | Delete
if orig is None:
[65] Fix | Delete
# There's no payload. For backwards compatibility we use 7bit
[66] Fix | Delete
msg['Content-Transfer-Encoding'] = '7bit'
[67] Fix | Delete
return
[68] Fix | Delete
# We play a trick to make this go fast. If encoding to ASCII succeeds, we
[69] Fix | Delete
# know the data must be 7bit, otherwise treat it as 8bit.
[70] Fix | Delete
try:
[71] Fix | Delete
orig.encode('ascii')
[72] Fix | Delete
except UnicodeError:
[73] Fix | Delete
msg['Content-Transfer-Encoding'] = '8bit'
[74] Fix | Delete
else:
[75] Fix | Delete
msg['Content-Transfer-Encoding'] = '7bit'
[76] Fix | Delete
[77] Fix | Delete
[78] Fix | Delete
[79] Fix | Delete
def encode_noop(msg):
[80] Fix | Delete
"""Do nothing."""
[81] Fix | Delete
[82] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function