[Web-SIG] WSGI tests
Phillip J. Eby
pje at telecommunity.com
Wed Sep 29 18:36:16 CEST 2004
At 11:21 AM 9/29/04 -0500, Ian Bicking wrote:
>Phillip J. Eby wrote:
>>At 02:19 AM 9/29/04 -0500, Ian Bicking wrote:
>>
>>>The only one I was mistakenly requiring seems to be QUERY_STRING; from
>>>my reading, all these are required:
>>>
>>>'REQUEST_METHOD', 'SCRIPT_NAME', 'PATH_INFO', 'SERVER_NAME', 'SERVER_PORT'
>>>
>>>Well, maybe SCRIPT_NAME isn't required.
>>
>>Or PATH_INFO - if the request is addressed directly to the application,
>>and there's no trailing '/', it can be empty, and is therefore allowed to
>>be missing, as in CGI.
>
>OK, fixed.
Actually, it just occurred to me that there *is* a legitimate test you can
do for SCRIPT_NAME and PATH_INFO: at least *one* of them must be present
and non-blank, because if you're at the site root, SCRIPT_NAME is empty and
PATH_INFO has to be '/'. (Or the other way around, the CGI spec isn't
clear on this, but Apache CGI puts the '/' in PATH_INFO.) Anyway, it's
never valid to have both empty or missing, so you can:
assert environ.get('SCRIPT_NAME') or environ.get('PATH_INFO')
Also, if present and non-empty, both of these variables must *begin* with a
'/', so it's more like:
script_name = environ.get('SCRIPT_NAME','')
path_info = environ.get('PATH_INFO','')
assert not script_name or script_name.startswith('/')
assert not path_info or path_info.startswith('/')
assert script_name or path_info
>>By the way, I found another issue with lint: IteratorWrapper doesn't
>>close the original iterable if it had a close() method.
>
>Fixed as well.
Actually, no. Lint's iterator close() is still broken. You have to use
close() on the *iterable*, not on iter(iterable). The two may be different
objects, since an iterable may return a separate iterator object.
Also, pycgiwrapper returns None from __call__, when it should return an
iterator. A simple way to fix that would be to just 'return [body]' after
calling start_respsonse.
I'm pretty much coming to the conclusion that WSGI is no longer "simple",
alas. For it to actually be usable, there's going to have to be a
reference library, as well as tests. I'm going to keep pecking away at
your lint program, and eventually your other test facilities as well, so
that I'll have something to test the reference library with. :)
More information about the Web-SIG
mailing list