[Web-SIG] Returned application object and fileno.

Alan Kennedy py-web-sig at xhaus.com
Wed Sep 1 15:40:00 CEST 2004


[Alan Kennedy]
>> But we also need to consider what happens when the application 
>> returns, for example, a StringIO.StringIO, or a gzip.GzipFile.

[Phillip J. Eby]
> No, we don't.  WSGI does not support that.  You must return an 
> *iterable*.  As Andrew says, 'fileno()' was added to allow 
> special-casing operating system file descriptors on platforms that have 
> them, and have APIs like 'sendfile()' that can copy data directly from 
> one descriptor to another.
> 
> If you would like to support special Java stuff, or CLR stuff, you can 
> always have your server look for some other attribute name and support 
> that as a platform-specific, optional extension for higher performance.

But that is explicitly forbidden: "Finally, servers must not directly 
use any other attributes of the iterable returned by the application. 
For example, it[sic] the iterable is a file object, it may have a read() 
method, but the server must not utilize it. Only attributes specified 
here, or accessed via e.g. the PEP 234 iteration APIs are acceptable."

> But that's *all* the 'fileno()' support is: a *platform-specific* 
> *optional extension* to boost performance in certain cases.  The server 
> isn't even required to *check* for a fileno attribute, and the 
> application certainly isn't required to provide it.

Fair enough, it is good to support recognition of file-like objects on 
platforms that have file descriptor tables.

But I don't see any WSGI compliant way in jython that I can take a 
static file object returned by a WSGI application and do anything with 
it at all.

For example, if the application works like this, which I'd imagine is a 
common expected usage pattern, then I can do nothing

def app_object(environ, start_response):
   start_response("200 OK", [ ('content-type', 'image/jpg') ])
   return open("%s.jpg" % environ['PATH_INFO'], 'rb')

This will work on cpython, of course, because of implicit fileno() 
method on the (cpython) file object. But will fail on jython, which will 
confuse the hell out of appliction authors.

Regards,

Alan.


More information about the Web-SIG mailing list