Comment 12 for bug 322486

Revision history for this message
Tres Seaver (tseaver) wrote :

My $0.02: the framework should get the hell out of the application's
way, here: if the application passes an int, or even a string which can
be converted to an int, then the lookup should be omitted altogether.

In any non-int case, then passing something which can't be looked up
could reasonably be construed as an error in the application, and should
*raise an exception* rather than DWIMing a 500; the traceback would
then point the finger at the offending bit of code, as it should, rather
than hiding it.

This behavior matches the contract spelled out in the interface, except
that it allows int()-able strings. We should squish the bit of the docs
which disallow passing '200' or 200: that is silly.

So, my version would look like::

    def setStatus(self, status, reason=None):
        """See IHTTPResponse"""
        if status is None:
            status = 200
        try:
            status = int(status)
        except ValueError:
            if type(status) in StringTypes:
                status = status.lower()
            status = status_codes[status] # raise KeyError
        self._status = status

        if reason is None:
            reason = status_reasons.get(status, "Unknown")

        self._reason = reason
        self._status_set = True