http_status.py 793 B

123456789101112131415161718192021222324252627
  1. # 生成一个http响应码以及message的枚举类
  2. from enum import Enum
  3. class HTTPStatus(Enum):
  4. OK = (200, "OK")
  5. CREATED = (201, "Created")
  6. ACCEPTED = (202, "Accepted")
  7. NO_CONTENT = (204, "No Content")
  8. BAD_REQUEST = (400, "Bad Request")
  9. UNAUTHORIZED = (401, "Unauthorized")
  10. FORBIDDEN = (403, "Forbidden")
  11. NOT_FOUND = (404, "Not Found")
  12. METHOD_NOT_ALLOWED = (405, "Method Not Allowed")
  13. INTERNAL_SERVER_ERROR = (500, "Internal Server Error")
  14. NOT_IMPLEMENTED = (501, "Not Implemented")
  15. BAD_GATEWAY = (502, "Bad Gateway")
  16. SERVICE_UNAVAILABLE = (503, "Service Unavailable")
  17. def __init__(self, code, message):
  18. self.code = code
  19. self.message = message
  20. def __str__(self):
  21. return f"{self.code} {self.message}"