Re: [Zope-dev] SVN: zope.publisher/trunk/ Fixed LP #322486: setStatus() now allows any int()-able status value.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Shane Hathaway wrote:
Log message for revision 95601: Fixed LP #322486: setStatus() now allows any int()-able status value.
Yay!
Modified: zope.publisher/trunk/src/zope/publisher/http.py =================================================================== --- zope.publisher/trunk/src/zope/publisher/http.py 2009-01-30 18:31:20 UTC (rev 95600) +++ zope.publisher/trunk/src/zope/publisher/http.py 2009-01-30 18:45:20 UTC (rev 95601) @@ -647,12 +647,16 @@ self.authUser = '-'
def setStatus(self, status, reason=None): - 'See IHTTPResponse' + """See IHTTPResponse""" if status is None: status = 200 - else: - if type(status) in StringTypes: + try: + status = int(status) + except ValueError: + if isinstance(status, basestring): status = status.lower() + # Use a standard status code, falling back to 500 for + # nonstandard values (such as "valueerror") status = status_codes.get(status, 500) self._status = status
Modified: zope.publisher/trunk/src/zope/publisher/interfaces/http.py =================================================================== --- zope.publisher/trunk/src/zope/publisher/interfaces/http.py 2009-01-30 18:31:20 UTC (rev 95600) +++ zope.publisher/trunk/src/zope/publisher/interfaces/http.py 2009-01-30 18:45:20 UTC (rev 95601) @@ -333,12 +333,17 @@ def setStatus(status, reason=None): """Sets the HTTP status code of the response
- The argument may either be an integer or a string from { OK, - Created, Accepted, NoContent, MovedPermanently, - MovedTemporarily, NotModified, BadRequest, Unauthorized, - Forbidden, NotFound, InternalError, NotImplemented, - BadGateway, ServiceUnavailable } that will be converted to the - correct integer value. + The status parameter must be either an integer, a value + that can be converted to an integer using the int() function, + or one of the standard status messages listed in the status_codes + dict of the zope.publisher.http module (including "OK", "NotFound", + and so on). If the parameter is some other value, the status will + be set to 500. + + The reason parameter is a short message to be sent with the status + code to the client. If reason is not provided, a standard + reason will be supplied, falling back to "Unknown" for unregistered + status codes. """
Is there any reason to hide the KeyError behind a 500, rather than letting it propagate to the application? In this implementation, we lose the information about the bad 'status' value. Tres. - -- =================================================================== Tres Seaver +1 540-429-0999 tseaver@palladion.com Palladion Software "Excellence by Design" http://palladion.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFJg1HF+gerLs4ltQ4RAo/+AJ9cbU8e7onPJwb7IzTI0wIIR8LbXgCcCsfb X9DVTXPucIKiCD+ex/ypfKs= =Snto -----END PGP SIGNATURE-----
Tres Seaver wrote:
Is there any reason to hide the KeyError behind a 500, rather than letting it propagate to the application? In this implementation, we lose the information about the bad 'status' value.
I agree, but I hit a legacy design snag. The handleException() method still calls setStatus(exception_type_name), where we could be handling any kind of exception, similar to what Zope has always done. IMHO, we should change the contract of setStatus() to not do any lookup at all and make handleException() do the lookup instead, or something along those lines. But I'm trying to make conservative changes ATM. Shane
participants (2)
-
Shane Hathaway -
Tres Seaver