Add Python version since deprecation in base64 methods. (#33)

Allow developers to not have to either test on N Python versions or
looked through multiple versions of the docs to know whether they can
easily update.
This commit is contained in:
Matthias Bussonnier 2017-03-02 06:21:26 -08:00 committed by Berker Peksag
parent 698845eba7
commit c643a967dd
3 changed files with 25 additions and 6 deletions

View File

@ -237,14 +237,18 @@ The legacy interface:
.. function:: decodebytes(s) .. function:: decodebytes(s)
decodestring(s)
Decode the :term:`bytes-like object` *s*, which must contain one or more Decode the :term:`bytes-like object` *s*, which must contain one or more
lines of base64 encoded data, and return the decoded :class:`bytes`. lines of base64 encoded data, and return the decoded :class:`bytes`.
``decodestring`` is a deprecated alias.
.. versionadded:: 3.1 .. versionadded:: 3.1
.. function:: decodestring(s)
Deprecated alias of :func:`decodebytes`.
.. deprecated:: 3.1
.. function:: encode(input, output) .. function:: encode(input, output)
@ -257,14 +261,19 @@ The legacy interface:
.. function:: encodebytes(s) .. function:: encodebytes(s)
encodestring(s)
Encode the :term:`bytes-like object` *s*, which can contain arbitrary binary Encode the :term:`bytes-like object` *s*, which can contain arbitrary binary
data, and return :class:`bytes` containing the base64-encoded data, with newlines data, and return :class:`bytes` containing the base64-encoded data, with newlines
(``b'\n'``) inserted after every 76 bytes of output, and ensuring that (``b'\n'``) inserted after every 76 bytes of output, and ensuring that
there is a trailing newline, as per :rfc:`2045` (MIME). there is a trailing newline, as per :rfc:`2045` (MIME).
``encodestring`` is a deprecated alias. .. versionadded:: 3.1
.. function:: encodestring(s)
Deprecated alias of :func:`encodebytes`.
.. deprecated:: 3.1
An example usage of the module: An example usage of the module:

View File

@ -541,7 +541,8 @@ def encodebytes(s):
def encodestring(s): def encodestring(s):
"""Legacy alias of encodebytes().""" """Legacy alias of encodebytes()."""
import warnings import warnings
warnings.warn("encodestring() is a deprecated alias, use encodebytes()", warnings.warn("encodestring() is a deprecated alias since 3.1, "
"use encodebytes()",
DeprecationWarning, 2) DeprecationWarning, 2)
return encodebytes(s) return encodebytes(s)
@ -554,7 +555,8 @@ def decodebytes(s):
def decodestring(s): def decodestring(s):
"""Legacy alias of decodebytes().""" """Legacy alias of decodebytes()."""
import warnings import warnings
warnings.warn("decodestring() is a deprecated alias, use decodebytes()", warnings.warn("decodestring() is a deprecated alias since Python 3.1, "
"use decodebytes()",
DeprecationWarning, 2) DeprecationWarning, 2)
return decodebytes(s) return decodebytes(s)

View File

@ -18,6 +18,14 @@ class LegacyBase64TestCase(unittest.TestCase):
int_data = memoryview(b"1234").cast('I') int_data = memoryview(b"1234").cast('I')
self.assertRaises(TypeError, f, int_data) self.assertRaises(TypeError, f, int_data)
def test_encodestring_warns(self):
with self.assertWarns(DeprecationWarning):
base64.encodestring(b"www.python.org")
def test_decodestring_warns(self):
with self.assertWarns(DeprecationWarning):
base64.decodestring(b"d3d3LnB5dGhvbi5vcmc=\n")
def test_encodebytes(self): def test_encodebytes(self):
eq = self.assertEqual eq = self.assertEqual
eq(base64.encodebytes(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=\n") eq(base64.encodebytes(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=\n")