Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Allow to respond with binary data #148

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions webapp2.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,11 +416,8 @@ def write(self, text):
"""Appends a text to the response body."""
# webapp uses StringIO as Response.out, so we need to convert anything
# that is not str or unicode to string to keep same behavior.
if six.PY3 and isinstance(text, bytes):
text = text.decode(self.default_charset)

if not isinstance(text, six.string_types):
text = six.text_type(text)
if not isinstance(text, (six.text_type, six.binary_type)):
text = str(text)

if isinstance(text, six.text_type) and not self.charset:
self.charset = self.default_charset
Expand Down