[Web-SIG] Pre-PEP: Python Web Container Interface v1.0

Phillip J. Eby pje at telecommunity.com
Mon Dec 8 12:09:17 EST 2003


At 11:39 PM 12/8/03 +0800, Ng Pheng Siong wrote:
>On Mon, Dec 08, 2003 at 09:57:34AM -0500, Phillip J. Eby wrote:
> > >+1 for None.
> > >
> > >Zope is able to use REMOTE_USER if the web server sets it, e.g.,
> >
> > But what does it do if it's set to 'None'?
>
>Let's see...
>
>   ~/pkg/zope262/lib/python/ZPublisher$ egrep -i remote_user *.py
>
>   BaseRequest.py:    elif request.environ.has_key('REMOTE_USER'):
>   BaseRequest.py:        name=request.environ['REMOTE_USER']
>   HTTPRequest.py:        'REMOTE_USER' : 1,
>   Publish.py:        if realm and not request.get('REMOTE_USER',None):
>
>If it is None, Zope does nothing about it, I suppose.

Did you trace every use of 'name' after it's set from REMOTE_USER, to be 
sure that it's okay for it to be None?

I'm not saying there's a problem, I'm saying that it's silly to force the 
authors of every framework to go hunt down every existing use of *every* 
environment variable to be sure they're safe with them being None.


>Well, the plural of `anecdote' is not `data' ;-), but it does seem to me

No kidding.  Even if "some" set of frameworks are okay with None, that's 
not the same as "all" frameworks.  OTOH, any currently correct code will 
work if we *don't* use None or '', making that approach immeasurably 
superior from an "immediate adoption ability" point of view.


>the following 2 styles will be dominant:
>
>1)
>     x = dict.get('XX', None)
>     if x is None:
>         ...
>
>2)
>     if dict.has_key('XX'):
>         ...
>
>So I'm guessing it is not terribly important whether it is '' or None.

Actually, you've just given evidence that it is VERY important.  Code that 
currently uses 'has_key' (or 'in') will BREAK if we put None OR '' for 
non-existent keys.  Non-existent keys are clearly critical for backward 
compatibility with the second style you show above.




More information about the Web-SIG mailing list