Joel Rivera committed a70206d

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.

Comments (0)

Files changed (1)


         if encoding in self.attempted_charsets:
             return False
-        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