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

Fix FileBasedBuffer (and ReadOnlyFileBasedBuffer) to act more like iterators #82

Merged
merged 4 commits into from Mar 16, 2016

Conversation

Projects
None yet
2 participants
@bertjwregeer
Member

bertjwregeer commented Feb 7, 2015

FileBasedBuffer is the parent class for a variety of sub-classes,
including ReadOnlyFileBasedBuffer. Since FileBasedBuffer can be used as
an app_iter return (and by extension it's sub-classes can as well) it
should probably behave more like an iterator, and the file returned from
open().

Even if an iterator contains no more objects, calling bool() will still
return True, in the case of FileBasedBuffer this is not true until this
fix.


Without this fix, if an application calls a second WSGI application that
returns an wsgi.file_wrapper (aka ReadOnlyFileBasedBuffer) they can't
simply test to see if the application returned a valid iterator or not
by testing it's truthiness.

This is documented in bug report: #76

While one could argue that testing the truthiness of a return from an
WSGI application is the wrong thing to do, I would argue that an
iterator like object should not return False when tested with bool.
bool(iter([])) == True after all.

Fixes: #76

bertjwregeer added some commits Feb 7, 2015

Remove __nonzero__ and bool from FileBasedBuffer
FileBasedBuffer is the parent class for a variety of sub-classes,
including ReadOnlyFileBasedBuffer. Since FileBasedBuffer can be used as
an app_iter return (and by extension it's sub-classes can as well) it
should probably behave more like an iterator, and the file returned from
open().

Even if an iterator contains no more objects, calling bool() will still
return True, in the case of FileBasedBuffer this is not true until this
fix.

----

Without this fix, if an application calls a second WSGI application that
returns an wsgi.file_wrapper (aka ReadOnlyFileBasedBuffer) they can't
simply test to see if the application returned a valid iterator or not
by testing it's truthiness.

This is documented in bug report:
#76

While one could argue that testing the truthiness of a return from an
WSGI application is the wrong thing to do, I would argue that an
iterator like object should not return False when tested with bool.
bool(iter([])) == True after all.
@mmerickel

This comment has been minimized.

Show comment
Hide comment
@mmerickel

mmerickel Mar 16, 2016

Member

LGTM I could go either way but it seems harmless to change this.

Member

mmerickel commented Mar 16, 2016

LGTM I could go either way but it seems harmless to change this.

bertjwregeer added a commit to bertjwregeer/waitress that referenced this pull request Mar 16, 2016

@bertjwregeer bertjwregeer merged commit ef5a1a2 into Pylons:master Mar 16, 2016

1 check failed

continuous-integration/travis-ci/pr The Travis CI build failed
Details

@pyup-bot pyup-bot referenced this pull request Jun 30, 2017

Merged

Initial Update #100

@pyup-bot pyup-bot referenced this pull request Nov 3, 2017

Closed

Update waitress to 1.1.0 #469

@pyup-bot pyup-bot referenced this pull request Jan 26, 2018

Closed

Update waitress to 1.1.0 #406

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment