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

Skip to content

Commit 9ab9694

Browse files
author
Martin Panter
committed
Issue #16473: Merge codecs doc and test from 3.4 into 3.5
2 parents 3133a9f + 06171bd commit 9ab9694

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
@@ -1310,9 +1310,9 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
13101310
+----------------------+------------------+------------------------------+------------------------------+
13111311
| Codec | Aliases | Purpose | Encoder / decoder |
13121312
+======================+==================+==============================+==============================+
1313-
| base64_codec [#b64]_ | base64, base_64 | Convert operand to MIME | :meth:`base64.b64encode` / |
1314-
| | | base64 (the result always | :meth:`base64.b64decode` |
1315-
| | | includes a trailing | |
1313+
| base64_codec [#b64]_ | base64, base_64 | Convert operand to multiline | :meth:`base64.encodebytes` / |
1314+
| | | MIME base64 (the result | :meth:`base64.decodebytes` |
1315+
| | | always includes a trailing | |
13161316
| | | ``'\n'``) | |
13171317
| | | | |
13181318
| | | .. versionchanged:: 3.4 | |
@@ -1324,14 +1324,14 @@ to :class:`bytes` mappings. They are not supported by :meth:`bytes.decode`
13241324
| bz2_codec | bz2 | Compress the operand | :meth:`bz2.compress` / |
13251325
| | | using bz2 | :meth:`bz2.decompress` |
13261326
+----------------------+------------------+------------------------------+------------------------------+
1327-
| hex_codec | hex | Convert operand to | :meth:`base64.b16encode` / |
1328-
| | | hexadecimal | :meth:`base64.b16decode` |
1327+
| hex_codec | hex | Convert operand to | :meth:`binascii.b2a_hex` / |
1328+
| | | hexadecimal | :meth:`binascii.a2b_hex` |
13291329
| | | representation, with two | |
13301330
| | | digits per byte | |
13311331
+----------------------+------------------+------------------------------+------------------------------+
1332-
| quopri_codec | quopri, | Convert operand to MIME | :meth:`quopri.encodestring` /|
1333-
| | quotedprintable, | quoted printable | :meth:`quopri.decodestring` |
1334-
| | quoted_printable | | |
1332+
| quopri_codec | quopri, | Convert operand to MIME | :meth:`quopri.encode` with |
1333+
| | quotedprintable, | quoted printable | ``quotetabs=True`` / |
1334+
| | quoted_printable | | :meth:`quopri.decode` |
13351335
+----------------------+------------------+------------------------------+------------------------------+
13361336
| uu_codec | uu | Convert the operand using | :meth:`uu.encode` / |
13371337
| | | 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
@@ -2684,6 +2684,14 @@ def test_aliases(self):
26842684
info = codecs.lookup(alias)
26852685
self.assertEqual(info.name, expected_name)
26862686

2687+
def test_quopri_stateless(self):
2688+
# Should encode with quotetabs=True
2689+
encoded = codecs.encode(b"space tab\teol \n", "quopri-codec")
2690+
self.assertEqual(encoded, b"space=20tab=09eol=20\n")
2691+
# But should still support unescaped tabs and spaces
2692+
unescaped = b"space tab eol\n"
2693+
self.assertEqual(codecs.decode(unescaped, "quopri-codec"), unescaped)
2694+
26872695
def test_uu_invalid(self):
26882696
# Missing "begin" line
26892697
self.assertRaises(ValueError, codecs.decode, b"", "uu-codec")

0 commit comments

Comments
 (0)