]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
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 9529e66d07cbfdc86be8a80ee69567b3f616400c..f5d1a9d787d5fd4ba5131486298dcf0151325df8 100644 (file)
@@ -1193,21 +1193,22 @@ The following codecs provide str-to-str encoding and decoding
 +--------------------+---------------------------+---------------------------+------------------------------+
 | Codec              | Aliases                   | Purpose                   | Encoder/decoder              |
 +====================+===========================+===========================+==============================+
-| base64_codec       | base64, base-64           | Convert operand to MIME   | :meth:`base64.b64encode`,    |
-|                    |                           | base64 (the result always | :meth:`base64.b64decode`     |
-|                    |                           | includes a trailing       |                              |
-|                    |                           | ``'\n'``)                 |                              |
+| base64_codec       | base64, base-64           | Convert operand to        | :meth:`base64.encodestring`, |
+|                    |                           | multiline MIME base64 (the| :meth:`base64.decodestring`  |
+|                    |                           | result always includes a  |                              |
+|                    |                           | trailing ``'\n'``)        |                              |
 +--------------------+---------------------------+---------------------------+------------------------------+
 | 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, quoted-printable, | Convert operand to MIME   | :meth:`quopri.encodestring`, |
-|                    | quotedprintable           | quoted printable          | :meth:`quopri.decodestring`  |
+| quopri_codec       | quopri, quoted-printable, | Convert operand to MIME   | :meth:`quopri.encode` with   |
+|                    | quotedprintable           | quoted printable          | ``quotetabs=True``,          |
+|                    |                           |                           | :meth:`quopri.decode`        |
 +--------------------+---------------------------+---------------------------+------------------------------+
 | string_escape      |                           | Produce a string that is  |                              |
 |                    |                           | suitable as string        |                              |
index f2591496fee82412f60faf8004093a55612a2108..e4965da86c2adc4f38d6574dfe98726bab477d92 100644 (file)
@@ -21,7 +21,7 @@ def quopri_encode(input, errors='strict'):
     # using str() because of cStringIO's Unicode undesired Unicode behavior.
     f = StringIO(str(input))
     g = StringIO()
-    quopri.encode(f, g, 1)
+    quopri.encode(f, g, quotetabs=True)
     output = g.getvalue()
     return (output, len(input))
 
index 7300f236061a9ee1f6d7c514d19f49bc2512c2d1..cf486373ccaec574b33e8da90378f394a43840eb 100644 (file)
@@ -2103,6 +2103,14 @@ class BomTest(unittest.TestCase):
 
 class TransformCodecTest(unittest.TestCase):
 
+    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, "", "uu-codec")