diff options
author | Joel Rivera <rivera@joel.mx> | 2013-06-23 18:57:41 -0500 |
---|---|---|
committer | Joel Rivera <rivera@joel.mx> | 2013-06-23 18:57:41 -0500 |
commit | 1b6f84fb2ed4ee24a3526527b42d4aba9955cb37 (patch) | |
tree | 2daddf8813f5ce95deef69b35216eae10ac5c3b9 /cherrypy/lib/encoding.py | |
parent | 5baf766fec22a3ee5a5f00d2b8f79c8d63d40b58 (diff) | |
download | cherrypy-git-1b6f84fb2ed4ee24a3526527b42d4aba9955cb37.tar.gz |
Bugfix. The IndexError, KeyError, LookupError, UnicodeError exceptions
were not propagated from generators, the solution was to
limit the scope of the try/except block, even if the try/catch
block is inside a for loop because of the premise that the exceptions
are not that heavy when the except block is not executed in
the majority of the cases (which is the expected behavior at
that particular part).
Applying the suggested patch of @jimparis.
Closes issue #1200.
Diffstat (limited to 'cherrypy/lib/encoding.py')
-rw-r--r-- | cherrypy/lib/encoding.py | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/cherrypy/lib/encoding.py b/cherrypy/lib/encoding.py index 1f68143b..bcd498a1 100644 --- a/cherrypy/lib/encoding.py +++ b/cherrypy/lib/encoding.py @@ -80,19 +80,17 @@ class ResponseEncoder: if encoding in self.attempted_charsets: return False self.attempted_charsets.add(encoding) - - try: - body = [] - for chunk in self.body: - if isinstance(chunk, unicodestr): + body = [] + for chunk in self.body: + if isinstance(chunk, unicodestr): + try: chunk = chunk.encode(encoding, self.errors) - body.append(chunk) - self.body = body - except (LookupError, UnicodeError): - return False - else: - return True - + except (LookupError, UnicodeError): + return False + body.append(chunk) + self.body = body + return True + def find_acceptable_charset(self): request = cherrypy.serving.request response = cherrypy.serving.response |