email: Add a failing UTF-16 _flatten example
authorW. Trevor King <wking@tremily.us>
Thu, 24 Jan 2013 04:12:01 +0000 (23:12 -0500)
committerW. Trevor King <wking@tremily.us>
Thu, 24 Jan 2013 04:49:43 +0000 (23:49 -0500)
Signed-off-by: W. Trevor King <wking@tremily.us>
rss2email/email.py

index 3b9f98379ff3f26af6f37c24a1a4eb305fd5c716..4fac7993c4f483663d5ddf931344e60845bfb9d6 100644 (file)
@@ -175,7 +175,7 @@ def _flatten(message):
     ...     content_type='plain',
     ...     config=config)
     >>> for line in _flatten(message).split(b'\n'):
-    ...     print(line)
+    ...     print(line)  # doctest: +REPORT_UDIFF
     b'MIME-Version: 1.0'
     b'Content-Type: text/plain; charset="utf-8"'
     b'Content-Transfer-Encoding: base64'
@@ -196,7 +196,7 @@ def _flatten(message):
     ...     content_type='plain',
     ...     config=config)
     >>> for line in _flatten(message).split(b'\n'):
-    ...     print(line)
+    ...     print(line)  # doctest: +REPORT_UDIFF
     b'MIME-Version: 1.0'
     b'Content-Type: text/plain; charset="utf-8"'
     b'From: John <jdoe@a.com>'
@@ -205,6 +205,26 @@ def _flatten(message):
     b'Content-Transfer-Encoding: 8bit'
     b''
     b"You're great, \xce\x96\xce\xb5\xcf\x8d\xcf\x82!\\n"
+
+    Here's an 8-bit version in UTF-16:
+
+    >>> config.set('DEFAULT', 'encodings', 'US-ASCII, UTF-16-LE')
+    >>> message = get_message(
+    ...     sender='John <jdoe@a.com>', recipient='Ζεύς <z@olympus.org>',
+    ...     subject='Homage',
+    ...     body="You're great, Ζεύς!\\n",
+    ...     content_type='plain',
+    ...     config=config)
+    >>> for line in _flatten(message).split(b'\n'):
+    ...     print(line)  # doctest: +REPORT_UDIFF
+    b'MIME-Version: 1.0'
+    b'Content-Type: text/plain; charset="utf-16-le"'
+    b'From: John <jdoe@a.com>'
+    b'To: =?utf-8?b?zpbOtc+Nz4I=?= <z@olympus.org>'
+    b'Subject: Homage'
+    b'Content-Transfer-Encoding: 8bit'
+    b''
+    b"\x00Y\x00o\x00u\x00'\x00r\x00e\x00 \x00g\x00r\x00e\x00a\x00t\x00,\x00 \x00\x96\x03\xb5\x03\xcd\x03\xc2\x03!\x00\\\x00n\x00"
     """
     return message.as_string().encode(str(message.get_charset()))