New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cherrypy.wsgiserver.wsgiserver2.ChunkedRFile.__iter__ broken #1131

bb-migration opened this Issue Mar 9, 2012 · 3 comments


1 participant

bb-migration commented Mar 9, 2012

Originally reported by: Anonymous

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

My code:


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

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


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


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


This comment has been minimized.

bb-migration commented Mar 9, 2012

Original comment by Jim Paris (Bitbucket: jimparis, GitHub: jimparis):

(I was the original reporter)

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

I'll put together a testcase


This comment has been minimized.

bb-migration commented Mar 9, 2012

Original comment by Jim Paris (Bitbucket: jimparis, GitHub: jimparis):

Attaching a patch to cherrypy/test/ that should show the problems. Apply this and run

nosetests -s cherrypy.test.test_conn:ConnectionTests.test_Chunked_Encoding

This comment has been minimized.

bb-migration commented Mar 9, 2012

Original comment by Jim Paris (Bitbucket: jimparis, GitHub: jimparis):

Two more patches.

The first one improves the test to include data that does not end in EOL, to trigger more bugs.

The second one fixes at least some of the bugs in ChunkedRFile so that these new test cases pass.

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Jul 19, 2017

Updated py-cheroot to 5.7.0.

- CI improvements:
  * Don't run tests during deploy stage
  * Use VM based build job env only for pyenv envs
  * Opt-in for beta trusty image @ Travis CI
  * Be verbose when running tests (show test names)
  * Show xfail/skip details during test run

- #34: Fix ``_handle_no_ssl`` error handler calls

- #21: Fix ``test_conn`` tests:
  * Improve setup_server def in HTTP connection tests
  * Fix HTTP streaming tests
  * Fix HTTP/1.1 pipelining test under Python 3
  * Fix ``test_readall_or_close`` test
  * Fix ``test_No_Message_Body``
  * Clarify ``test_598`` fail reason

- #36: Add GitHub templates for PR, issue && contributing

- #27: Default HTTP Server header to Cheroot version str

- Cleanup _compat functions from server module


- Fix all PEP 257 related errors in all non-test modules.

  ``cheroot/test/*`` folder is only one left allowed to fail with this linter.

- #30: Optimize chunked body reader loop by returning empty data is the size is 0.

  Ref: cherrypy/cherrypy#1602

- Reset buffer if the body size is unknown

  Ref: cherrypy/cherrypy#1486

- Add missing size hint to SizeCheckWrapper

  Ref: cherrypy/cherrypy#1131


- #32: Ignore "unknown error" and "https proxy request" SSL errors.

  Ref: sabnzbd/sabnzbd#820

  Ref: sabnzbd/sabnzbd#860


- Make Appveyor list separate tests in corresponding tab.

- #29: Configure Travis CI build stages.

  Prioritize tests by stages.

  Move deploy stage to be run very last after all other stages finish.

- #31: Ignore "Protocol wrong type for socket" (EPROTOTYPE) @ OSX for non-blocking sockets.

  This was originally fixed for regular sockets in cherrypy/cherrypy#1392.



- #17 via #25: Instead of a read_headers function, cheroot now
  supplies a HeaderReader class to perform the same function.

  Any HTTPRequest object may override the header_reader attribute
  to customize the handling of incoming headers.

  The server module also presents a provisional implementation of
  a DropUnderscoreHeaderReader that will exclude any headers
  containing an underscore. It remains an exercise for the
  implementer to demonstrate how this functionality might be
  employed in a server such as CherryPy.

- #26: Configured TravisCI to run tests under OS X.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment