我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用quopri.encodestring()。
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)
def _qencode(s): enc = _encodestring(s, quotetabs=True) # Must encode spaces, which quopri.encodestring() doesn't do return enc.replace(' ', '=20')
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
def test_encodestring(self): for p, e in self.STRINGS: self.assertEqual(quopri.encodestring(p), e)
def test_idempotent_string(self): for p, e in self.STRINGS: self.assertEqual(quopri.decodestring(quopri.encodestring(e)), e)
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)
def test_encode_header(self): for p, e in self.HSTRINGS: self.assertEqual(quopri.encodestring(p, header=True), e)
def test_encodestring(self): for p, e in self.STRINGS: self.assertTrue(quopri.encodestring(p) == e)
def test_idempotent_string(self): for p, e in self.STRINGS: self.assertTrue(quopri.decodestring(quopri.encodestring(e)) == e)
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)
def test_encode_header(self): for p, e in self.HSTRINGS: self.assertTrue(quopri.encodestring(p, header=True) == e)
def _qencode(s): enc = _encodestring(s, quotetabs=True) # Must encode spaces, which quopri.encodestring() doesn't do return enc.replace(b' ', b'=20')