Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06171bd

Browse files
author
Martin Panter
committed
Issue #16473: Fix byte transform codec documentation; test quotetabs=True
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.
1 parent f9b6875 commit 06171bd

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

Doc/library/codecs.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,9 +1284,9 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
12841284
+----------------------+------------------+------------------------------+------------------------------+
12851285
| Codec | Aliases | Purpose | Encoder / decoder |
12861286
+======================+==================+==============================+==============================+
1287-
| base64_codec [#b64]_ | base64, base_64 | Convert operand to MIME | :meth:`base64.b64encode` / |
1288-
| | | base64 (the result always | :meth:`base64.b64decode` |
1289-
| | | includes a trailing | |
1287+
| base64_codec [#b64]_ | base64, base_64 | Convert operand to multiline | :meth:`base64.encodebytes` / |
1288+
| | | MIME base64 (the result | :meth:`base64.decodebytes` |
1289+
| | | always includes a trailing | |
12901290
| | | ``'\n'``) | |
12911291
| | | | |
12921292
| | | .. versionchanged:: 3.4 | |
@@ -1298,14 +1298,14 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
12981298
| bz2_codec | bz2 | Compress the operand | :meth:`bz2.compress` / |
12991299
| | | using bz2 | :meth:`bz2.decompress` |
13001300
+----------------------+------------------+------------------------------+------------------------------+
1301-
| hex_codec | hex | Convert operand to | :meth:`base64.b16encode` / |
1302-
| | | hexadecimal | :meth:`base64.b16decode` |
1301+
| hex_codec | hex | Convert operand to | :meth:`binascii.b2a_hex` / |
1302+
| | | hexadecimal | :meth:`binascii.a2b_hex` |
13031303
| | | representation, with two | |
13041304
| | | digits per byte | |
13051305
+----------------------+------------------+------------------------------+------------------------------+
1306-
| quopri_codec | quopri, | Convert operand to MIME | :meth:`quopri.encodestring` /|
1307-
| | quotedprintable, | quoted printable | :meth:`quopri.decodestring` |
1308-
| | quoted_printable | | |
1306+
| quopri_codec | quopri, | Convert operand to MIME | :meth:`quopri.encode` with |
1307+
| | quotedprintable, | quoted printable | ``quotetabs=True`` / |
1308+
| | quoted_printable | | :meth:`quopri.decode` |
13091309
+----------------------+------------------+------------------------------+------------------------------+
13101310
| uu_codec | uu | Convert the operand using | :meth:`uu.encode` / |
13111311
| | | uuencode | :meth:`uu.decode` |

Lib/encodings/quopri_codec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def quopri_encode(input, errors='strict'):
1111
assert errors == 'strict'
1212
f = BytesIO(input)
1313
g = BytesIO()
14-
quopri.encode(f, g, 1)
14+
quopri.encode(f, g, quotetabs=True)
1515
return (g.getvalue(), len(input))
1616

1717
def quopri_decode(input, errors='strict'):

Lib/test/test_codecs.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2613,6 +2613,14 @@ def test_aliases(self):
26132613
info = codecs.lookup(alias)
26142614
self.assertEqual(info.name, expected_name)
26152615

2616+
def test_quopri_stateless(self):
2617+
# Should encode with quotetabs=True
2618+
encoded = codecs.encode(b"space tab\teol \n", "quopri-codec")
2619+
self.assertEqual(encoded, b"space=20tab=09eol=20\n")
2620+
# But should still support unescaped tabs and spaces
2621+
unescaped = b"space tab eol\n"
2622+
self.assertEqual(codecs.decode(unescaped, "quopri-codec"), unescaped)
2623+
26162624
def test_uu_invalid(self):
26172625
# Missing "begin" line
26182626
self.assertRaises(ValueError, codecs.decode, b"", "uu-codec")

0 commit comments

Comments
 (0)