Issue #1131 new

cherrypy.wsgiserver.wsgiserver2.ChunkedRFile.__iter__ broken

Anonymous created an issue

cherrypy.wsgiserver.wsgiserver2.ChunkedRFile.iter references sizehint, which is not defined:

My code: {{{

!python

def disable_prb(): cherrypy.request.process_request_body = False cherrypy.tools.disable_prb = cherrypy.Tool('before_request_body', disable_prb)

class Root(object): @cherrypy.expose @cherrypy.tools.disable_prb() def index(self): for line in cherrypy.request.rfile: print "got line: " + line }}}

Error: {{{ [09/Mar/2012:14:44:15] HTTP Traceback (most recent call last): File "/usr/lib/python2.7/dist-packages/cherrypy/_cprequest.py", line 656, in respond response.body = self.handler() File "/usr/lib/python2.7/dist-packages/cherrypy/lib/encoding.py", line 188, in call self.body = self.oldhandler(*args, kwargs) File "/usr/lib/python2.7/dist-packages/cherrypy/_cpdispatch.py", line 34, in __call__ return self.callable(*self.args, self.kwargs) File "server-put.py", line 19, in index for line in cherrypy.request.rfile: File "/usr/lib/python2.7/dist-packages/cherrypy/wsgiserver/wsgiserver2.py", line 513, in iter line = self.readline(sizehint) NameError: global name 'sizehint' is not defined }}}

wsgiserver2.py: {{{

!python

def __iter__(self):
    # Shamelessly stolen from StringIO
    total = 0
    line = self.readline(sizehint)
    while line:
        yield line
        total += len(line)
        if 0 < sizehint <= total:
            break
        line = self.readline(sizehint)

}}}

Comments (3)

  1. Jim Paris

    (I was the original reporter)

    It's even worse. ChunkedRFile.read() and ChunkedRFile.readline() are both broken and get stuck in a loop if size = None.

    I'll put together a testcase

  2. Log in to comment