Skip to content

Commit ef00fe1

Browse files
committed
Use io.BytesIO instead of StringIO
On Python 3, StringIO is for strings.
1 parent 20aa278 commit ef00fe1

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

examples/deepzoom/deepzoom_server.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
1919
#
2020

21-
from cStringIO import StringIO
2221
from flask import Flask, abort, make_response, render_template, url_for
22+
from io import BytesIO
2323
from openslide import ImageSlide, open_slide
2424
from openslide.deepzoom import DeepZoomGenerator
2525
from optparse import OptionParser
@@ -95,7 +95,7 @@ def tile(slug, level, col, row, format):
9595
except ValueError:
9696
# Invalid level or coordinates
9797
abort(404)
98-
buf = StringIO()
98+
buf = BytesIO()
9999
tile.save(buf, format, quality=app.config['DEEPZOOM_TILE_QUALITY'])
100100
resp = make_response(buf.getvalue())
101101
resp.mimetype = 'image/%s' % format

openslide/deepzoom.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"""
2525

2626
from __future__ import division
27-
import cStringIO as StringIO
27+
from io import BytesIO
2828
import math
2929
import openslide
3030
from PIL import Image
@@ -209,6 +209,6 @@ def get_dzi(self, format):
209209
w, h = self._l0_dimensions
210210
SubElement(image, 'Size', Width=str(w), Height=str(h))
211211
tree = ElementTree(element=image)
212-
buf = StringIO.StringIO()
212+
buf = BytesIO()
213213
tree.write(buf, encoding='UTF-8')
214-
return unicode(buf.getvalue(), 'UTF-8')
214+
return buf.getvalue().decode()

0 commit comments

Comments
 (0)