summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2006-12-11 19:34:41 +0000
committerRobert Brewer <fumanchu@aminus.org>2006-12-11 19:34:41 +0000
commit6940c87ffca22d487053172c1900720410b2639a (patch)
tree7a2bd15b05f338674698fccb87d5dabc36858b9d
parent613b2ef0879a4279e46f0862536dbf280c705833 (diff)
downloadcherrypy-6940c87ffca22d487053172c1900720410b2639a.tar.gz
2.x backport of [1382] (Fixed bug in encode; shouldn't attempt encode on any body chunk unless it's of type 'unicode').
-rw-r--r--cherrypy/filters/encodingfilter.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/cherrypy/filters/encodingfilter.py b/cherrypy/filters/encodingfilter.py
index d86f46e7..c82ff8ca 100644
--- a/cherrypy/filters/encodingfilter.py
+++ b/cherrypy/filters/encodingfilter.py
@@ -26,8 +26,10 @@ def encode_stream(encoding, errors='strict'):
being written out.
"""
def encoder(body):
- for line in body:
- yield line.encode(encoding, errors)
+ for chunk in body:
+ if isinstance(chunk, unicode):
+ chunk = chunk.encode(encoding, errors)
+ yield chunk
cherrypy.response.body = encoder(cherrypy.response.body)
return True
@@ -36,7 +38,9 @@ def encode_string(encoding, errors='strict'):
try:
body = []
for chunk in cherrypy.response.body:
- body.append(chunk.encode(encoding, errors))
+ if isinstance(chunk, unicode):
+ chunk = chunk.encode(encoding, errors)
+ body.append(chunk)
cherrypy.response.body = body
except (LookupError, UnicodeError):
return False