123456789101112131415161718192021222324252627 |
- # 生成一个http响应码以及message的枚举类
- from enum import Enum
- class HTTPStatus(Enum):
- OK = (200, "OK")
- CREATED = (201, "Created")
- ACCEPTED = (202, "Accepted")
- NO_CONTENT = (204, "No Content")
- BAD_REQUEST = (400, "Bad Request")
- UNAUTHORIZED = (401, "Unauthorized")
- FORBIDDEN = (403, "Forbidden")
- NOT_FOUND = (404, "Not Found")
- METHOD_NOT_ALLOWED = (405, "Method Not Allowed")
- INTERNAL_SERVER_ERROR = (500, "Internal Server Error")
- NOT_IMPLEMENTED = (501, "Not Implemented")
- BAD_GATEWAY = (502, "Bad Gateway")
- SERVICE_UNAVAILABLE = (503, "Service Unavailable")
- def __init__(self, code, message):
- self.code = code
- self.message = message
- def __str__(self):
- return f"{self.code} {self.message}"
|