-
Notifications
You must be signed in to change notification settings - Fork 101
Description
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:
meinheld/meinheld/server/response.c
Line 1267 in 6ddb22b
| 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_wrapperhas to introspect the supplied object for things such as afileno()(Unix-like OSes) or ajava.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_wrappermust still return an iterable that wrapsread()andclose(), so that applications using file wrappers are portable across platforms.