[Web-SIG] PEP 444 (aka Web3)
Roberto De Ioris
roberto at unbit.it
Thu Sep 16 08:57:29 CEST 2010
Il giorno 16/set/2010, alle ore 08.37, Masklinn ha scritto:
>> I generally like it.
>>
>> 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
>>
> As far as I understand it, `body` is an iterable so there should not be any problem with sending a file through directly in this manner. Better, the web3 spec specifically mandates that if the `body` iterable has a `close` method it must be called on request completion (second-to-last paragraph in the specification details section [0]). So a File Object as a body is already completely handled by web3.
>
> On the other hand, `body` has to yield bytes, so `fd = open('/tmp/pippo.txt', 'rb')` I think.
>
In this case i do not see a need for wsgi.file_wrapper replacement.
The Web3 gateway/hosting system can manage File-Like Object the way it wants
(and transparently for the application)
--
Roberto De Ioris
http://unbit.it
JID: roberto at jabber.unbit.it
More information about the Web-SIG
mailing list