[Web-SIG] PEP 444 (aka Web3)

Chris McDonough chrism at plope.com
Sun Sep 19 17:42:36 CEST 2010


On Thu, 2010-09-16 at 05:29 +0200, Roberto De Ioris wrote:
> About the *.file_wrapper removal, i suggest
> a PSGI-like approach where 'body' can contains a File Object.
> 
> def file_app(environ):
>     fd = open('/tmp/pippo.txt', 'r')
>     status = b'200 OK'
>     headers = [(b'Content-type', b'text/plain')]
>     body = fd
>     return body, status, headers

I don't see why this couldn't work as long as middleware didn't convert
the body into something not-file-like.  But it is really an
implementation detail of the origin server (it might specialize when the
body is a file), and doesn't really need to be in the spec.

> or
> 
> def file_app(environ):
>     fd = open('/tmp/pippo.txt', 'r')
>     status = b'200 OK'
>     headers = [(b'Content-type', b'text/plain')]
>     body = [b'Header', fd, b'Footer']
>     return body, status, headers

This won't work, as the body is required to return an iterable which
returns bytes, and cannot be an iterable which returns either bytes or
other iterables (it must be a "flat" sequence).

- C




More information about the Web-SIG mailing list