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

tony at lownds.com tony at lownds.com
Tue Sep 7 22:16:50 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?

My change is not correct, wrt using a file_wrapper. I was showing the change
needed for WSGI server to simply use a file-like object. Sorry for any
confusion.

Which do you think is better? That servers should understand file objects
as return values, or that applications should be careful to wrap files?

-Tony



More information about the Web-SIG mailing list