本文整理匯總了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)