Permalink
Browse files

[svn] use the response's encoding when coercing it to unicode, or the…

… default encoding

when it has none set. only decode when it's not already unicode

--HG--
branch : trunk
  • Loading branch information...
1 parent 98d97a5 commit 02d6243052f005298946c643db3c2a3e622e4a9d pjenvey committed Mar 18, 2007
Showing with 10 additions and 16 deletions.
  1. +10 −16 pylons/decorators/__init__.py
@@ -1,5 +1,6 @@
"""Pylons Decorators: ``jsonify``, ``validate``, REST, and Cache decorators"""
import simplejson as json
+import sys
from paste.util.multidict import UnicodeMultiDict
from decorator import decorator
@@ -87,22 +88,15 @@ def wrapper(func, self, *args, **kwargs):
pylons.request.environ['REQUEST_METHOD'] = 'GET'
pylons.request.environ['pylons.routes_dict']['action'] = form
response = self._dispatch_call()
- if isinstance(params, UnicodeMultiDict):
-
- # Don't decode back to unicode if its already unicode
- if len(response.content) > 0 and isinstance(response.content[0], unicode):
- form_content = u''.join(response.content)
-
- # Content has been encoded to str, decode back to unicode
- elif len(response.content) > 0:
- encoding = pylons.request.defaults['charset']
- encode_errors = pylons.request.defaults['errors']
- form_content = u''.join(
- [x.decode(encoding, encode_errors) for x in response.content])
- else:
- form_content = u''
- else:
- form_content = "".join(response.content)
+ form_content = ''.join(response.content)
+ if isinstance(params, UnicodeMultiDict) and \
+ not isinstance(form_content, unicode):
+ # Passing unicode form values to htmlfill: decode the response
+ # to unicode so htmlfill can safely combine the two
+ encoding = response.determine_charset()
+ if encoding is None:
+ encoding = sys.getdefaultencoding()
+ form_content = form_content.decode(encoding, response.errors)
response.content = [htmlfill.render(form_content, params, errors)]
return response
return func(self, *args, **kwargs)

0 comments on commit 02d6243

Please sign in to comment.