Source

CherryPy / cherrypy / _cprequest.py

Diff from to

cherrypy/_cprequest.py

 import cherrypy
 from cherrypy import _cpcgifs, _cpconfig
 from cherrypy._cperror import format_exc, bare_error
-from cherrypy.lib import http
+from cherrypy.lib import http, file_generator
 
 
 class Hook(object):
                                           # FieldStorage only recognizes POST.
                                           environ={'REQUEST_METHOD': "POST"},
                                           keep_blank_values=1)
-        except http.MaxSizeExceeded:
-            # Post data is too big
-            raise cherrypy.HTTPError(413)
+        except Exception, e:
+            if e.__class__.__name__ == 'MaxSizeExceeded':
+                # Post data is too big
+                raise cherrypy.HTTPError(413)
+            else:
+                raise
         
         # Note that, if headers['Content-Type'] is multipart/*,
         # then forms.file will not exist; instead, each form[key]
             cherrypy.response.finalize()
 
 
-def file_generator(input, chunkSize=65536):
-    """Yield the given input (a file object) in chunks (default 64k). (Core)"""
-    chunk = input.read(chunkSize)
-    while chunk:
-        yield chunk
-        chunk = input.read(chunkSize)
-    input.close()
-
-
 class Body(object):
     """The body of the HTTP response (the response entity)."""