Skip to content
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

Meinheld's wsgi.file_wrapper does not conform to PEP 3333 #130

Open
vytas7 opened this issue Nov 13, 2021 · 0 comments
Open

Meinheld's wsgi.file_wrapper does not conform to PEP 3333 #130

vytas7 opened this issue Nov 13, 2021 · 0 comments

Comments

@vytas7
Copy link

vytas7 commented Nov 13, 2021

Meinheld provides a wsgi.file_wrapper, however, it seems that the provided implementation does not conform to PEP 3333 (see the relevant chapter: Optional Platform-Specific File Handling).

If the provided file-like object implements .read(), but not .fileno(), Meinheld raises a TypeError, and disconnects the client.
This seems to happen because PyObject_AsFileDescriptor() is used here indiscriminately, even if the provided file-like object doesn't have one:

in_fd = PyObject_AsFileDescriptor(filelike);

The specification reads:

Of course, platform-specific file transmission APIs don't usually accept arbitrary "file-like" objects. Therefore, a wsgi.file_wrapper has to introspect the supplied object for things such as a fileno() (Unix-like OSes) or a java.nio.FileChannel (under Jython) in order to determine if the file-like object is suitable for use with the platform-specific API it supports.

Note that even if the object is not suitable for the platform API, the wsgi.file_wrapper must still return an iterable that wraps read() and close(), so that applications using file wrappers are portable across platforms.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant