Skip to content

Commit

Permalink
update BinaryCapsule class to include data content type
Browse files Browse the repository at this point in the history
  • Loading branch information
chekunkov committed Jul 29, 2015
1 parent 640ff7e commit 88427c1
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion splash/kernel/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def done(result):
'text/plain': result if isinstance(result, basestring) else str(result),
}
if isinstance(result, BinaryCapsule):
data["image/png"] = result.as_b64()
data[result.content_type] = result.as_b64()
self._publish_execute_result(parent, data, {}, self.execution_count)

super(SplashKernel, self).send_execute_reply(stream, ident, parent, md, reply)
Expand Down
4 changes: 2 additions & 2 deletions splash/qtrender_lua.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ def png(self, width=None, height=None, render_all=False,
height = int(height)
result = self.tab.png(width, height, b64=False, render_all=render_all,
scale_method=scale_method)
return BinaryCapsule(result)
return BinaryCapsule(result, 'image/png')

@command()
def jpeg(self, width=None, height=None, render_all=False,
Expand All @@ -399,7 +399,7 @@ def jpeg(self, width=None, height=None, render_all=False,
quality = int(quality)
result = self.tab.jpeg(width, height, b64=False, render_all=render_all,
scale_method=scale_method, quality=quality)
return BinaryCapsule(result)
return BinaryCapsule(result, 'image/jpeg')

@command()
def har(self):
Expand Down
3 changes: 2 additions & 1 deletion splash/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class BadRequest(Exception):

class BinaryCapsule(object):
""" A wrapper for passing binary data. """
def __init__(self, data):
def __init__(self, data, content_type):
self.data = data
self.content_type = content_type

def as_b64(self):
return base64.b64encode(self.data)
Expand Down

0 comments on commit 88427c1

Please sign in to comment.