本文整理汇总了Python中quopri.encodestring方法的典型用法代码示例。如果您正苦于以下问题:Python quopri.encodestring方法的具体用法?Python quopri.encodestring怎么用?Python quopri.encodestring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类quopri
的用法示例。
在下文中一共展示了quopri.encodestring方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def add(self, location: str, content_type: str, payload: str, encoding: str = 'quoted-printable') -> None:
resource = EmailMessage()
if content_type == 'text/html':
resource.add_header('Content-Type', 'text/html', charset='utf-8')
else:
resource['Content-Type'] = content_type
if encoding == 'quoted-printable':
resource['Content-Transfer-Encoding'] = encoding
resource.set_payload(quopri.encodestring(payload.encode()))
elif encoding == 'base64':
resource['Content-Transfer-Encoding'] = encoding
resource.set_payload(base64.b64encode(payload))
elif encoding == 'base64-encoded': # Already base64 encoded
resource['Content-Transfer-Encoding'] = 'base64'
resource.set_payload(payload)
else:
raise ValueError('invalid encoding')
resource['Content-Location'] = location
self._msg.attach(resource)
示例2: _qencode
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def _qencode(s):
enc = _encodestring(s, quotetabs=True)
# Must encode spaces, which quopri.encodestring() doesn't do
return enc.replace(' ', '=20')
示例3: _encode_quopri_mhtml
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def _encode_quopri_mhtml(msg):
"""Encode the message's payload in quoted-printable.
Substitute for quopri's default 'encode_quopri' method, which needlessly
encodes all spaces and tabs, instead of only those at the end on the
line.
Args:
msg: Email message to quote.
"""
orig = msg.get_payload(decode=True)
encdata = quopri.encodestring(orig, quotetabs=False)
msg.set_payload(encdata)
msg['Content-Transfer-Encoding'] = 'quoted-printable'
示例4: test_encodestring
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def test_encodestring(self):
for p, e in self.STRINGS:
self.assertTrue(quopri.encodestring(p) == e)
示例5: test_idempotent_string
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def test_idempotent_string(self):
for p, e in self.STRINGS:
self.assertTrue(quopri.decodestring(quopri.encodestring(e)) == e)
示例6: test_embedded_ws
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def test_embedded_ws(self):
for p, e in self.ESTRINGS:
self.assertTrue(quopri.encodestring(p, quotetabs=True) == e)
self.assertTrue(quopri.decodestring(e) == p)
示例7: test_encode_header
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def test_encode_header(self):
for p, e in self.HSTRINGS:
self.assertTrue(quopri.encodestring(p, header=True) == e)
示例8: encode_transfer_encoding
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def encode_transfer_encoding(encoding, body):
if encoding == 'quoted-printable':
return quopri.encodestring(body, quotetabs=False)
elif encoding == 'base64':
return email.encoders._bencode(body)
else:
return body
示例9: _qencode
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def _qencode(s):
enc = _encodestring(s, quotetabs=True)
# Must encode spaces, which quopri.encodestring() doesn't do
return enc.replace(b' ', b'=20')
示例10: test_encodestring
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def test_encodestring(self):
for p, e in self.STRINGS:
self.assertEqual(quopri.encodestring(p), e)
示例11: test_idempotent_string
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def test_idempotent_string(self):
for p, e in self.STRINGS:
self.assertEqual(quopri.decodestring(quopri.encodestring(e)), e)
示例12: test_embedded_ws
# 需要导入模块: import quopri [as 别名]
# 或者: from quopri import encodestring [as 别名]
def test_embedded_ws(self):
for p, e in self.ESTRINGS:
self.assertEqual(quopri.encodestring(p, quotetabs=True), e)
self.assertEqual(quopri.decodestring(e), p)