Skip to content

Commit 34dfcd6

Browse files
committed
examples: Fix Deep Zoom servers when using classic PIL
io.BytesIO.fileno() raises io.UnsupportedOperation, which Pillow understands but PIL does not. Use a subclass that raises AttributeError instead.
1 parent 4bde09c commit 34dfcd6

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

examples/deepzoom/deepzoom_multiserver.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@
4040
app.config.from_envvar('DEEPZOOM_MULTISERVER_SETTINGS', silent=True)
4141

4242

43+
class PILBytesIO(BytesIO):
44+
def fileno(self):
45+
'''Classic PIL doesn't understand io.UnsupportedOperation.'''
46+
raise AttributeError('Not supported')
47+
48+
4349
class _SlideCache(object):
4450
def __init__(self, cache_size, dz_opts):
4551
self.cache_size = cache_size
@@ -145,7 +151,7 @@ def tile(path, level, col, row, format):
145151
except ValueError:
146152
# Invalid level or coordinates
147153
abort(404)
148-
buf = BytesIO()
154+
buf = PILBytesIO()
149155
tile.save(buf, format, quality=app.config['DEEPZOOM_TILE_QUALITY'])
150156
resp = make_response(buf.getvalue())
151157
resp.mimetype = 'image/%s' % format

examples/deepzoom/deepzoom_server.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@
3939
app.config.from_envvar('DEEPZOOM_TILER_SETTINGS', silent=True)
4040

4141

42+
class PILBytesIO(BytesIO):
43+
def fileno(self):
44+
'''Classic PIL doesn't understand io.UnsupportedOperation.'''
45+
raise AttributeError('Not supported')
46+
47+
4248
@app.before_first_request
4349
def load_slide():
4450
slidefile = app.config['DEEPZOOM_SLIDE']
@@ -97,7 +103,7 @@ def tile(slug, level, col, row, format):
97103
except ValueError:
98104
# Invalid level or coordinates
99105
abort(404)
100-
buf = BytesIO()
106+
buf = PILBytesIO()
101107
tile.save(buf, format, quality=app.config['DEEPZOOM_TILE_QUALITY'])
102108
resp = make_response(buf.getvalue())
103109
resp.mimetype = 'image/%s' % format

0 commit comments

Comments
 (0)