[Web-SIG] environ["wsgi.input"].read()

Brian Smith brian at briansmith.org
Fri Jan 25 19:23:24 CET 2008


James Y Knight wrote:
> On Jan 25, 2008, at 10:04 AM, Brian Smith wrote:
> > 1. PEP 333 doesn't indicate that the size parameter for the read() 
> > method is optional. Is it optional or required? If it is 
> > optional, is the default value -1?
> 
> The spec says it's required (by virtue of not saying it's optional)

I would agree, except PEP 333 also says it is a file-like object. The
definition of file-like object at
http://docs.python.org/lib/bltin-file-objects.html implies that the size
parameter is optional. Note that the behaviors that are optional for
file-like objects are in a different section than the one that defines
the read() method with the optional parameter.

> The CGI specification, and thus WSGI by implication,
> doesn't allow for chunked input. The CONTENT_LENGTH
> environment key is a required value if there is
> content. The only correct thing for a gateway to
> do is to reject a request with chunked input.

The gateway can also decode the chunked entity and calculate the
Content-Length before passing it on to the application.

> The spec is fairly clear as to what you can rely on here. 
> Additional behavior may of course be implemented in some 
> gateway, but it's going to be non-portable.

I disagree about the clarity of the spec. But, I agree that applications
should not rely on the handling of a negative or missing size parameter.

- Brian



More information about the Web-SIG mailing list