Comment 7 for bug 322486

Revision history for this message
Shane Hathaway (shane-hathawaymix) wrote :

I dug through the version history to find out if an indentation bug was introduced recently. I'm afraid not. Look for "def setStatus" in the version that's just about to have its 10th anniversary:

http://svn.zope.org/Zope/trunk/lib/python/ZPublisher/HTTPResponse.py?rev=15919&view=markup

Amazingly, Zope has never had support for arbitrary status codes in HTTP responses. So changing the indentation is in fact adding a feature we've never had.

OTOH, the existing behavior is highly unexpected, and adding a new API for something that should be very simple seems overkill to me. I suggest a combination of the suggestions:

        else:
            if isinstance(status, basestring):
                status = status_codes[status.lower()]
        self._status = status

This changes three things:

1. If you pass an integer, it goes through. It's rather surprising that it doesn't already.
2. If you pass a string that is not registered, it raises a KeyError.
3. "type(x) in y" is a deprecated idiom, we might as replace it with isinstance() while we're here.

BTW, it's not clear to me which suggestion Jim and Fred gave their +1 vote for.