Issue #16473: Fix byte transform codec documentation; test quotetabs=True
authorMartin Panter <vadmium>
Sat, 12 Sep 2015 00:34:28 +0000 (00:34 +0000)
committerMartin Panter <vadmium>
Sat, 12 Sep 2015 00:34:28 +0000 (00:34 +0000)
This changes the equivalent functions listed for the Base-64, hex and Quoted-
Printable codecs to reflect the functions actually used. Also mention and
test the "quotetabs" setting for Quoted-Printable encoding.

Doc/library/codecs.rst
Lib/encodings/quopri_codec.py
Lib/test/test_codecs.py

index 9496035cd7f14565f124042e1fbf73204cfe8103..f3017da2c8f01ddee3d0ae70af2f21f0798295c4 100644 (file)
@@ -1284,9 +1284,9 @@ to :class:`bytes` mappings.  They are not supported by :meth:`bytes.decode`
 +----------------------+------------------+------------------------------+------------------------------+
 | Codec                | Aliases          | Purpose                      | Encoder / decoder            |
 +======================+==================+==============================+==============================+
-| base64_codec [#b64]_ | base64, base_64  | Convert operand to MIME      | :meth:`base64.b64encode` /   |
-|                      |                  | base64 (the result always    | :meth:`base64.b64decode`     |
-|                      |                  | includes a trailing          |                              |
+| base64_codec [#b64]_ | base64, base_64  | Convert operand to multiline | :meth:`base64.encodebytes` / |
+|                      |                  | MIME base64 (the result      | :meth:`base64.decodebytes`   |
+|                      |                  | always includes a trailing   |                              |
 |                      |                  | ``'\n'``)                    |                              |
 |                      |                  |                              |                              |
 |                      |                  | .. versionchanged:: 3.4      |                              |
@@ -1298,14 +1298,14 @@ to :class:`bytes` mappings.  They are not supported by :meth:`bytes.decode`
 | bz2_codec            | bz2              | Compress the operand         | :meth:`bz2.compress` /       |
 |                      |                  | using bz2                    | :meth:`bz2.decompress`       |
 +----------------------+------------------+------------------------------+------------------------------+
-| hex_codec            | hex              | Convert operand to           | :meth:`base64.b16encode` /   |
-|                      |                  | hexadecimal                  | :meth:`base64.b16decode`     |
+| hex_codec            | hex              | Convert operand to           | :meth:`binascii.b2a_hex` /   |
+|                      |                  | hexadecimal                  | :meth:`binascii.a2b_hex`     |
 |                      |                  | representation, with two     |                              |
 |                      |                  | digits per byte              |                              |
 +----------------------+------------------+------------------------------+------------------------------+
-| quopri_codec         | quopri,          | Convert operand to MIME      | :meth:`quopri.encodestring` /|
-|                      | quotedprintable, | quoted printable             | :meth:`quopri.decodestring`  |
-|                      | quoted_printable |                              |                              |
+| quopri_codec         | quopri,          | Convert operand to MIME      | :meth:`quopri.encode` with   |
+|                      | quotedprintable, | quoted printable             | ``quotetabs=True`` /         |
+|                      | quoted_printable |                              | :meth:`quopri.decode`        |
 +----------------------+------------------+------------------------------+------------------------------+
 | uu_codec             | uu               | Convert the operand using    | :meth:`uu.encode` /          |
 |                      |                  | uuencode                     | :meth:`uu.decode`            |
index 0533dbe4e7b2abd7eceddc1e6ffb71fa444ea1e8..496cb7655d032def0791960108b517ae2ac6c4a3 100644 (file)
@@ -11,7 +11,7 @@ def quopri_encode(input, errors='strict'):
     assert errors == 'strict'
     f = BytesIO(input)
     g = BytesIO()
-    quopri.encode(f, g, 1)
+    quopri.encode(f, g, quotetabs=True)
     return (g.getvalue(), len(input))
 
 def quopri_decode(input, errors='strict'):
index 6629ccd4e2b387aad1ef576582ca40fd3df7c927..8b78c240415599330088074bdc108e23042521c9 100644 (file)
@@ -2613,6 +2613,14 @@ class TransformCodecTest(unittest.TestCase):
                     info = codecs.lookup(alias)
                     self.assertEqual(info.name, expected_name)
 
+    def test_quopri_stateless(self):
+        # Should encode with quotetabs=True
+        encoded = codecs.encode(b"space tab\teol \n", "quopri-codec")
+        self.assertEqual(encoded, b"space=20tab=09eol=20\n")
+        # But should still support unescaped tabs and spaces
+        unescaped = b"space tab eol\n"
+        self.assertEqual(codecs.decode(unescaped, "quopri-codec"), unescaped)
+
     def test_uu_invalid(self):
         # Missing "begin" line
         self.assertRaises(ValueError, codecs.decode, b"", "uu-codec")