Re: [Web-SIG] Future of WSGI

2009-12-27 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

Malthe Borch wrote:
> 
> 2009/11/24 Ian Bicking :
>> Why does this matter?
> 
> It's all convention, but the CGI interpretation was to read the HTTP
> request line by line until a blank line came and that was the
> environment. Everything after that is the body.

"Headers", not environment:  the CGI environment is literally the
os.environ set up by the CGI parent process before forking and execing
the script.



Tres.
- --
===
Tres Seaver  +1 540-429-0999  tsea...@palladion.com
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAks3boYACgkQ+gerLs4ltQ5coACg0ijXgG1wy1BdNnPzN2Jm2FLG
1R0Anj0/o6zwjtatFERoQ2HS3BOgyVEA
=RhAH
-END PGP SIGNATURE-

___
Web-SIG mailing list
Web-SIG@python.org
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: 
http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com


Re: [Web-SIG] Future of WSGI

2009-12-27 Thread Malthe Borch


2009/11/24 Henry Precheur :
> (See http://tools.ietf.org/html/rfc2616#section-5)
>
> The request body, the request method (GET, POST, ...), the request URL,
> the HTTP version are all in `environ`.

That reference does not mention the environment. It's not an official term.

> If you really want to separate the headers from the rest you would put
> another dictionary containing the headers inside `environ`. Instead WSGI
> puts the headers prefixed with HTTP_ in `environ`, because that's what
> CGI is doing. It might not be 100% clean, or logic, but it's SIMPLER,
> there's no need to deal with nested dictionaries or other more complex
> structure, and it's extensible.

I don't mind those. CGI does it too, like you say.

> namedtuple is Python 2.6+: WSGI can't use it. WSGI must work w/ older
> versions of Python.

It was meant as illustration, but sure.

\malthe

___
Web-SIG mailing list
Web-SIG@python.org
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: 
http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com


Re: [Web-SIG] Future of WSGI

2009-12-27 Thread Henry Precheur



On Tue, Nov 24, 2009 at 10:50:00PM +0100, Malthe Borch wrote:
> How people use or abuse software is not our concern; but the standard
> library should not itself abuse its own abstractions.

Your assumption is that `environ` == HTTP headers. That's simply NOT the
case. A request is:
  - A request line
  - Some headers
  - A body

(See http://tools.ietf.org/html/rfc2616#section-5)

The request body, the request method (GET, POST, ...), the request URL,
the HTTP version are all in `environ`.

If you really want to separate the headers from the rest you would put
another dictionary containing the headers inside `environ`. Instead WSGI
puts the headers prefixed with HTTP_ in `environ`, because that's what
CGI is doing. It might not be 100% clean, or logic, but it's SIMPLER,
there's no need to deal with nested dictionaries or other more complex
structure, and it's extensible.

>   Request = namedtuple("Request", "environ body")
>   Response = namedtuple("Response", "status headers iterable")
> 
> Iterable might be "body" or "chunks" or some other term.

namedtuple is Python 2.6+: WSGI can't use it. WSGI must work w/ older
versions of Python.

-- 
  Henry Prêcheur


___
Web-SIG mailing list
Web-SIG@python.org
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: 
http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com


Re: [Web-SIG] Future of WSGI

2009-12-27 Thread Malthe Borch


2009/11/24 Ian Bicking :
> Why does this matter?

It's all convention, but the CGI interpretation was to read the HTTP
request line by line until a blank line came and that was the
environment. Everything after that is the body.

If you want to obtain a shorter call signature – e.g. (environ,
start_response) instead of (environ, body, start_response), that's
fine; but maybe this should be a decorator.

You could take this argument further and do this in two steps (leaving
out ``start_response`` in the following):

  (stream,) => (cgi_environ, body) => (hybrid_environ,)

That would preserve all information.

Why does it matter? This is the single most difficult question to
answer in software design because it's a matter of balance. On the one
hand we strive to find the best abstractions to express our problems
which will eventually be serialized into one or more tracks of
assembler code. On the other, we must be pragmatic and stop our quest
in time to still get things done in reasonable time.

I'm not sure the balance is in favor of the hybrid model; when you
google "environ http" you don't see a lot of body input stream in
there. You don't see "multi-threading" in there either; however, in
the WSGI environment, you do! We just put it there, because we don't
know where else to put it! Unable to find or respect the abtractions,
we are lucky to have Python's versatile dictionary. The downside:
bitrot.

\malthe

___
Web-SIG mailing list
Web-SIG@python.org
Web SIG: http://www.python.org/sigs/web-sig
Unsubscribe: 
http://mail.python.org/mailman/options/web-sig/archive%40mail-archive.com