Issue #845 resolved

patch to move file_generator() from _cprequest.py to lib/__init__.py

Anonymous created an issue

{{{file_generator()}}} is a generally useful function. Therefore it would be better to reside in the {{{lib}}} namespace rather than in {{{_cprequest}}}. This small patch moves file_generator from {{{_cprequest.py}}} to {{{lib/init.py}}}

I submit this patch in preparation for another patch in which {{{file_generator()}}} function will be used by components other than _cprequest.

This patch is against svn trunk.

{{{ diff -r 35a64c74e3f4 cherrypy/_cprequest.py --- a/cherrypy/_cprequest.py Mon Jul 28 12:04:13 2008 -0500 +++ b/cherrypy/_cprequest.py Mon Jul 28 12:28:39 2008 -0500 @@ -8,7 +8,7 @@ import cherrypy 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): @@ -747,15 +747,6 @@ class Request(object): 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)."""

diff -r 35a64c74e3f4 cherrypy/lib/init.py --- a/cherrypy/lib/init.py Mon Jul 28 12:04:13 2008 -0500 +++ b/cherrypy/lib/init.py Mon Jul 28 12:26:10 2008 -0500 @@ -133,3 +133,14 @@ def unrepr(s):

 return _Builder().build(obj)

+ +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() + + + }}}

Thank you for your consideration.

Reported by Mark Mitchell

Comments (5)

  1. Log in to comment