[Web-SIG] Re: Bill's comments on WSGI draft 1.4

Alan Kennedy py-web-sig at xhaus.com
Tue Sep 7 21:12:27 CEST 2004


[Phillip J. Eby]
 > Instead of using 'fileno' as an extension attribute on the iterable,
 > we'll add a 'wsgi.file_wrapper' key, usable as follows by an
 > application:
 >
 >     return environ['wsgi.file_wrapper'](something,blksize)
 >
 > The 'file_wrapper' may introspect "something" in order to do a
 > fileno() check, or other "I know how to send this kind of object
 > quickly" optimizations.  It must return an iterable, that the
 > application may return back to the server.

[tony at lownds.com]
 > Here's the tail end of the CGI example.
 >
 >     result = application(environ, start_response)
 >     try:
 >         if hasattr(result, 'read'):
 >             result = iter(lambda: result.read(BLOCKSIZE), '')
 >         for data in result:
 >             write(data)
 >     finally:
 >         if hasattr(result,'close'):
 >             result.close()

Since I am just about to implement "wsgi.file_wrapper", I just wanted to 
check that my understanding of it is correct.

I think Tony's example above is not correct: the hasattr(result, 'read') 
should not be necessary, since the 'file_wrapper' class should implement 
its own iterator? I think it should read simply

result = application(environ, start_response)
try:
   for data in result:
     write(data)
finally:
   if hasattr(result,'close'):
     result.close()

Only the application has to change in this case, to return any file like 
object, wrapped in a 'file_wrapper'?

Is this correct?

Regards,

Alan.


More information about the Web-SIG mailing list