diff --git a/webapp2.py b/webapp2.py index e48e7bf..178c7d7 100755 --- a/webapp2.py +++ b/webapp2.py @@ -416,14 +416,12 @@ 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, bytes): + if not isinstance(text, six.string_types): + text = six.text_type(text) - if not isinstance(text, six.string_types): - text = six.text_type(text) - - if isinstance(text, six.text_type) and not self.charset: - self.charset = self.default_charset + if isinstance(text, six.text_type) and not self.charset: + self.charset = self.default_charset super(Response, self).write(text)