##// END OF EJS Templates
P3K: fix DeprecationWarning under Python 3.x (base64.encodestring is deprecated)
Mikhail Korobov -
Show More
@@ -15,9 +15,15 b' import math'
15 import re
15 import re
16 import sys
16 import sys
17 import types
17 import types
18 from base64 import encodestring
19 from datetime import datetime
18 from datetime import datetime
20
19
20 try:
21 # base64.encodestring is deprecated in Python 3.x
22 from base64 import encodebytes
23 except ImportError:
24 # Python 2.x
25 from base64 import encodestring as encodebytes
26
21 from IPython.utils import py3compat
27 from IPython.utils import py3compat
22 from IPython.utils.encoding import DEFAULT_ENCODING
28 from IPython.utils.encoding import DEFAULT_ENCODING
23 from IPython.utils import text
29 from IPython.utils import text
@@ -118,10 +124,10 b' def encode_images(format_dict):'
118 encoded = format_dict.copy()
124 encoded = format_dict.copy()
119 pngdata = format_dict.get('image/png')
125 pngdata = format_dict.get('image/png')
120 if isinstance(pngdata, bytes) and pngdata[:8] == PNG:
126 if isinstance(pngdata, bytes) and pngdata[:8] == PNG:
121 encoded['image/png'] = encodestring(pngdata).decode('ascii')
127 encoded['image/png'] = encodebytes(pngdata).decode('ascii')
122 jpegdata = format_dict.get('image/jpeg')
128 jpegdata = format_dict.get('image/jpeg')
123 if isinstance(jpegdata, bytes) and jpegdata[:2] == JPEG:
129 if isinstance(jpegdata, bytes) and jpegdata[:2] == JPEG:
124 encoded['image/jpeg'] = encodestring(jpegdata).decode('ascii')
130 encoded['image/jpeg'] = encodebytes(jpegdata).decode('ascii')
125 return encoded
131 return encoded
126
132
127
133
General Comments 0
You need to be logged in to leave comments. Login now