File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff line change 9
9
import struct
10
10
import string
11
11
import binascii
12
+ from warnings import warnpy3k_with_fix
12
13
13
14
14
15
__all__ = [
29
30
_translation = [chr (_x ) for _x in range (256 )]
30
31
EMPTYSTRING = ''
31
32
32
-
33
33
def _translate (s , altchars ):
34
34
translation = _translation [:]
35
35
for k , v in altchars .items ():
@@ -316,6 +316,8 @@ def decode(input, output):
316
316
317
317
def encodestring (s ):
318
318
"""Encode a string into multiple lines of base-64 data."""
319
+ warnpy3k_with_fix ("base64.encodestring is not supported in 3.x" ,
320
+ "use base64.encodebytes instead" , stacklevel = 2 )
319
321
pieces = []
320
322
for i in range (0 , len (s ), MAXBINSIZE ):
321
323
chunk = s [i : i + MAXBINSIZE ]
@@ -325,6 +327,8 @@ def encodestring(s):
325
327
326
328
def decodestring (s ):
327
329
"""Decode a string."""
330
+ warnpy3k_with_fix ("base64.decodestring is not supported in 3.x" ,
331
+ "use base64.decodebytes instead" , stacklevel = 2 )
328
332
return binascii .a2b_base64 (s )
329
333
330
334
Original file line number Diff line number Diff line change 1
1
import unittest
2
2
from test import test_support
3
3
import base64
4
+ import sys
4
5
5
6
6
7
@@ -21,6 +22,11 @@ def test_encodestring(self):
21
22
# Non-bytes
22
23
eq (base64 .encodestring (bytearray ('abc' )), 'YWJj\n ' )
23
24
25
+ if sys .py3kwarning :
26
+ with warnings .catch_warnings (record = True ) as w :
27
+ warnings .filterwarnings ('always' , category = Py3xWarning )
28
+ base64 .encodestring ("" )
29
+
24
30
def test_decodestring (self ):
25
31
eq = self .assertEqual
26
32
eq (base64 .decodestring ("d3d3LnB5dGhvbi5vcmc=\n " ), "www.python.org" )
@@ -37,6 +43,11 @@ def test_decodestring(self):
37
43
# Non-bytes
38
44
eq (base64 .decodestring (bytearray ("YWJj\n " )), "abc" )
39
45
46
+ if sys .py3kwarning :
47
+ with warnings .catch_warnings (record = True ) as w :
48
+ warnings .filterwarnings ('always' , category = Py3xWarning )
49
+ base64 .decodestring ('' )
50
+
40
51
def test_encode (self ):
41
52
eq = self .assertEqual
42
53
from cStringIO import StringIO
You can’t perform that action at this time.
0 commit comments