98 lines
2.2 KiB
Python
98 lines
2.2 KiB
Python
class HTTPException(Exception):
|
|
""" Base class for HTTP exceptions """
|
|
|
|
|
|
class InvalidResponse(HTTPException):
|
|
""" Response message cannot be parsed """
|
|
|
|
def __init(self, message):
|
|
self.message = message
|
|
|
|
|
|
class InvalidStatusLine(HTTPException):
|
|
""" Response status line is invalid """
|
|
|
|
def __init(self, line):
|
|
self.line = line
|
|
|
|
|
|
class UnsupportedEncoding(HTTPException):
|
|
""" Reponse Encoding not support """
|
|
|
|
def __init(self, enc_type, encoding):
|
|
self.enc_type = enc_type
|
|
self.encoding = encoding
|
|
|
|
|
|
class IncompleteResponse(HTTPException):
|
|
def __init(self, cause):
|
|
self.cause = cause
|
|
|
|
|
|
class HTTPServerException(Exception):
|
|
""" Base class for HTTP Server exceptions """
|
|
status_code: str
|
|
message: str
|
|
body: str
|
|
|
|
def __init__(self, body=""):
|
|
self.body = body
|
|
|
|
|
|
class BadRequest(HTTPServerException):
|
|
""" Malformed HTTP request"""
|
|
status_code = 400
|
|
message = "Bad Request"
|
|
|
|
|
|
class MethodNotAllowed(HTTPServerException):
|
|
""" Method is not allowed """
|
|
status_code = 405
|
|
message = "Method Not Allowed"
|
|
|
|
def __init(self, allowed_methods):
|
|
self.allowed_methods = allowed_methods
|
|
|
|
|
|
class InternalServerError(HTTPServerException):
|
|
""" Internal Server Error """
|
|
status_code = 500
|
|
message = "Internal Server Error"
|
|
|
|
|
|
class NotImplemented(HTTPServerException):
|
|
""" Functionality not implemented """
|
|
status_code = 501
|
|
message = "Not Implemented"
|
|
|
|
|
|
class NotFound(HTTPServerException):
|
|
""" Resource not found """
|
|
status_code = 404
|
|
message = "Not Found"
|
|
|
|
|
|
class Forbidden(HTTPServerException):
|
|
""" Request not allowed """
|
|
status_code = 403
|
|
message = "Forbidden"
|
|
|
|
|
|
class Conflict(HTTPServerException):
|
|
""" Conflict in the current state of the target resource """
|
|
status_code = 409
|
|
message = "Conflict"
|
|
|
|
|
|
class HTTPVersionNotSupported(HTTPServerException):
|
|
""" The server does not support the major version HTTP used in the request message """
|
|
status_code = 505
|
|
message = "HTTP Version Not Supported"
|
|
|
|
|
|
class InvalidRequestLine(BadRequest):
|
|
""" Request start-line is invalid """
|
|
|
|
def __init__(self, line):
|
|
self.request_line = line
|