本文整理汇总了Python中email.charset.Charset.input_codec方法的典型用法代码示例。如果您正苦于以下问题:Python Charset.input_codec方法的具体用法?Python Charset.input_codec怎么用?Python Charset.input_codec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类email.charset.Charset
的用法示例。
在下文中一共展示了Charset.input_codec方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_charset
# 需要导入模块: from email.charset import Charset [as 别名]
# 或者: from email.charset.Charset import input_codec [as 别名]
def create_charset(mime_encoding):
"""Create an appropriate email charset for the given encoding.
Valid options are 'base64' for Base64 encoding, 'qp' for
Quoted-Printable, and 'none' for no encoding, in which case mails will
be sent as 7bit if the content is all ASCII, or 8bit otherwise.
"""
charset = Charset()
charset.input_charset = 'utf-8'
charset.output_charset = 'utf-8'
charset.input_codec = 'utf-8'
charset.output_codec = 'utf-8'
pref = mime_encoding.lower()
if pref == 'base64':
charset.header_encoding = BASE64
charset.body_encoding = BASE64
elif pref in ('qp', 'quoted-printable'):
charset.header_encoding = QP
charset.body_encoding = QP
elif pref == 'none':
charset.header_encoding = SHORTEST
charset.body_encoding = None
else:
raise TracError(_("Invalid email encoding setting: %(mime_encoding)s",
mime_encoding=mime_encoding))
return charset
示例2: _make_charset
# 需要导入模块: from email.charset import Charset [as 别名]
# 或者: from email.charset.Charset import input_codec [as 别名]
def _make_charset(self):
charset = Charset()
charset.input_charset = 'utf-8'
pref = self.mime_encoding.lower()
if pref == 'base64':
charset.header_encoding = BASE64
charset.body_encoding = BASE64
charset.output_charset = 'utf-8'
charset.input_codec = 'utf-8'
charset.output_codec = 'utf-8'
elif pref in ['qp', 'quoted-printable']:
charset.header_encoding = QP
charset.body_encoding = QP
charset.output_charset = 'utf-8'
charset.input_codec = 'utf-8'
charset.output_codec = 'utf-8'
elif pref == 'none':
charset.header_encoding = None
charset.body_encoding = None
charset.input_codec = None
charset.output_charset = 'ascii'
else:
raise TracError(_('Invalid email encoding setting: %s' % pref))
return charset