本文整理匯總了Python中email.encoders.encode_noop方法的典型用法代碼示例。如果您正苦於以下問題:Python encoders.encode_noop方法的具體用法?Python encoders.encode_noop怎麽用?Python encoders.encode_noop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類email.encoders
的用法示例。
在下文中一共展示了encoders.encode_noop方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_binary_body_with_encode_noop
# 需要導入模塊: from email import encoders [as 別名]
# 或者: from email.encoders import encode_noop [as 別名]
def test_binary_body_with_encode_noop(self):
# Issue 16564: This does not produce an RFC valid message, since to be
# valid it should have a CTE of binary. But the below works, and is
# documented as working this way.
bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
msg = MIMEApplication(bytesdata, _encoder=encoders.encode_noop)
self.assertEqual(msg.get_payload(), bytesdata)
self.assertEqual(msg.get_payload(decode=True), bytesdata)
s = StringIO()
g = Generator(s)
g.flatten(msg)
wireform = s.getvalue()
msg2 = email.message_from_string(wireform)
self.assertEqual(msg.get_payload(), bytesdata)
self.assertEqual(msg2.get_payload(decode=True), bytesdata)
# Test the basic MIMEText class
示例2: test_binary_body_with_encode_noop
# 需要導入模塊: from email import encoders [as 別名]
# 或者: from email.encoders import encode_noop [as 別名]
def test_binary_body_with_encode_noop(self):
# Issue 16564: This does not produce an RFC valid message, since to be
# valid it should have a CTE of binary. But the below works in
# Python2, and is documented as working this way.
bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
msg = MIMEApplication(bytesdata, _encoder=encoders.encode_noop)
# Treated as a string, this will be invalid code points.
self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata))
self.assertEqual(msg.get_payload(decode=True), bytesdata)
s = BytesIO()
g = BytesGenerator(s)
g.flatten(msg)
wireform = s.getvalue()
msg2 = email.message_from_bytes(wireform)
self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata))
self.assertEqual(msg2.get_payload(decode=True), bytesdata)
示例3: __init__
# 需要導入模塊: from email import encoders [as 別名]
# 或者: from email.encoders import encode_noop [as 別名]
def __init__(self, method, uri, headers, body):
if isinstance(body, dict):
body = json.dumps(body)
headers["Content-Type"] = "application/json"
headers["Content-Length"] = len(body)
if body is None:
body = ""
lines = ["%s %s HTTP/1.1" % (method, uri)]
lines.extend(
["%s: %s" % (key, value) for key, value in sorted(headers.items())]
)
lines.append("")
lines.append(body)
payload = "\r\n".join(lines)
if six.PY2:
# email.message.Message is an old-style class, so we
# cannot use 'super()'.
MIMEApplication.__init__(self, payload, "http", encode_noop)
else: # pragma: NO COVER Python3
super_init = super(MIMEApplicationHTTP, self).__init__
super_init(payload, "http", encode_noop)