-----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-----