def __init__(self, code, message=None, response=None, location=None): """ Initializes a page redirect exception. @type code: C{str} @param code: Refers to an HTTP status code, for example C{http.NOT_FOUND}. If no C{message} is given, C{code} is mapped to a descriptive string that is used instead. @type message: C{str} @param message: A short error message, for example "NOT FOUND". @type response: C{str} @param response: A complete HTML document for an error page. @type location: C{str} @param location: The location response-header field value. It is an absolute URI used to redirect the receiver to a location other than the Request-URI so the request can be completed. """ if not message: try: message = RESPONSES.get(int(code)) except ValueError: # If code wasn't a stringified int, can't map the # status code to a descriptive string so keep message # unchanged. pass if location and message: message = "%s to %s" % (message, location) Error.__init__(self, code, message, response) self.location = location
def __init__(self, code, message=None, response=None): """ Initializes a basic exception. @type code: C{str} @param code: Refers to an HTTP status code, for example C{http.NOT_FOUND}. If no C{message} is given, C{code} is mapped to a descriptive bytestring that is used instead. @type message: C{str} @param message: A short error message, for example "NOT FOUND". @type response: C{bytes} @param response: A complete HTML document for an error page. """ if not message: try: message = RESPONSES.get(int(code)) except ValueError: # If code wasn't a stringified int, can't map the # status code to a descriptive string so keep message # unchanged. pass Exception.__init__(self, code, message, response) self.status = code self.message = message self.response = response
def __init__(self, code, message=None, response=None): """ Initializes a basic exception. @type code: C{str} @param code: Refers to an HTTP status code, for example C{http.NOT_FOUND}. If no C{message} is given, C{code} is mapped to a descriptive string that is used instead. @type message: C{str} @param message: A short error message, for example "NOT FOUND". @type response: C{str} @param response: A complete HTML document for an error page. """ if not message: try: message = RESPONSES.get(int(code)) except ValueError: # If code wasn't a stringified int, can't map the # status code to a descriptive string so keep message # unchanged. pass Exception.__init__(self, code, message, response) self.status = code self.message = message self.response = response
def _codeToMessage(code): """ Returns the response message corresponding to an HTTP code, or None if the code is unknown or unrecognized. @type code: L{bytes} @param code: Refers to an HTTP status code, for example C{http.NOT_FOUND}. @return: A string message or none @rtype: L{bytes} """ try: return RESPONSES.get(int(code)) except (ValueError, AttributeError): return None
def _codeToMessage(code): """ Returns the response message corresponding to an HTTP code, or None if the code is unknown or unrecognized. @type code: L{str} @param code: Refers to an HTTP status code, for example C{http.NOT_FOUND}. @return: A string message or none @rtype: L{str} """ try: return RESPONSES.get(int(code)).decode('ascii') except (ValueError, AttributeError): return None