Skip to content

Commit c643a96

Browse files
Carreauberkerpeksag
authored andcommitted
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.
1 parent 698845e commit c643a96

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Doc/library/base64.rst

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,18 @@ The legacy interface:
237237

238238

239239
.. function:: decodebytes(s)
240-
decodestring(s)
241240

242241
Decode the :term:`bytes-like object` *s*, which must contain one or more
243242
lines of base64 encoded data, and return the decoded :class:`bytes`.
244-
``decodestring`` is a deprecated alias.
245243

246244
.. versionadded:: 3.1
247245

246+
.. function:: decodestring(s)
247+
248+
Deprecated alias of :func:`decodebytes`.
249+
250+
.. deprecated:: 3.1
251+
248252

249253
.. function:: encode(input, output)
250254

@@ -257,14 +261,19 @@ The legacy interface:
257261

258262

259263
.. function:: encodebytes(s)
260-
encodestring(s)
261264

262265
Encode the :term:`bytes-like object` *s*, which can contain arbitrary binary
263266
data, and return :class:`bytes` containing the base64-encoded data, with newlines
264267
(``b'\n'``) inserted after every 76 bytes of output, and ensuring that
265268
there is a trailing newline, as per :rfc:`2045` (MIME).
266269

267-
``encodestring`` is a deprecated alias.
270+
.. versionadded:: 3.1
271+
272+
.. function:: encodestring(s)
273+
274+
Deprecated alias of :func:`encodebytes`.
275+
276+
.. deprecated:: 3.1
268277

269278

270279
An example usage of the module:

Lib/base64.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,8 @@ def encodebytes(s):
541541
def encodestring(s):
542542
"""Legacy alias of encodebytes()."""
543543
import warnings
544-
warnings.warn("encodestring() is a deprecated alias, use encodebytes()",
544+
warnings.warn("encodestring() is a deprecated alias since 3.1, "
545+
"use encodebytes()",
545546
DeprecationWarning, 2)
546547
return encodebytes(s)
547548

@@ -554,7 +555,8 @@ def decodebytes(s):
554555
def decodestring(s):
555556
"""Legacy alias of decodebytes()."""
556557
import warnings
557-
warnings.warn("decodestring() is a deprecated alias, use decodebytes()",
558+
warnings.warn("decodestring() is a deprecated alias since Python 3.1, "
559+
"use decodebytes()",
558560
DeprecationWarning, 2)
559561
return decodebytes(s)
560562

Lib/test/test_base64.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ def check_type_errors(self, f):
1818
int_data = memoryview(b"1234").cast('I')
1919
self.assertRaises(TypeError, f, int_data)
2020

21+
def test_encodestring_warns(self):
22+
with self.assertWarns(DeprecationWarning):
23+
base64.encodestring(b"www.python.org")
24+
25+
def test_decodestring_warns(self):
26+
with self.assertWarns(DeprecationWarning):
27+
base64.decodestring(b"d3d3LnB5dGhvbi5vcmc=\n")
28+
2129
def test_encodebytes(self):
2230
eq = self.assertEqual
2331
eq(base64.encodebytes(b"www.python.org"), b"d3d3LnB5dGhvbi5vcmc=\n")

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy