[Python-checkins] cpython (merge 3.4 -> 3.5): Issue #16473: Merge codecs doc and test from 3.4 into 3.5

martin.panter python-checkins at python.org
Sat Sep 12 03:44:40 CEST 2015


https://hg.python.org/cpython/rev/28cd11dc2915
changeset: 97935:28cd11dc2915
branch: 3.5
parent: 97932:857ae7ab0955
parent: 97934:de82f41d6669
user: Martin Panter <vadmium>
date: Sat Sep 12 01:22:17 2015 +0000
summary:
 Issue #16473: Merge codecs doc and test from 3.4 into 3.5
files:
 Doc/library/codecs.rst | 16 ++++++++--------
 Lib/encodings/quopri_codec.py | 2 +-
 Lib/test/test_codecs.py | 8 ++++++++
 3 files changed, 17 insertions(+), 9 deletions(-)
diff --git a/Doc/library/codecs.rst b/Doc/library/codecs.rst
--- a/Doc/library/codecs.rst
+++ b/Doc/library/codecs.rst
@@ -1310,9 +1310,9 @@
 +----------------------+------------------+------------------------------+------------------------------+
 | 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 | |
@@ -1324,14 +1324,14 @@
 | 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` |
diff --git a/Lib/encodings/quopri_codec.py b/Lib/encodings/quopri_codec.py
--- a/Lib/encodings/quopri_codec.py
+++ b/Lib/encodings/quopri_codec.py
@@ -11,7 +11,7 @@
 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'):
diff --git a/Lib/test/test_codecs.py b/Lib/test/test_codecs.py
--- a/Lib/test/test_codecs.py
+++ b/Lib/test/test_codecs.py
@@ -2684,6 +2684,14 @@
 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")
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /