Spaces:
Running on Zero
Running on Zero
File size: 2,838 Bytes
ed4faae | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 | from typing import Optional
class MemeGeneratorException(Exception):
status_code: int = 520
def __init__(self, message: str):
self.message = message
def __str__(self) -> str:
return self.__repr__()
def __repr__(self) -> str:
return f"表情制作出错!{self.message}"
class NoSuchMeme(MemeGeneratorException):
status_code: int = 531
def __init__(self, meme_key: str):
self.meme_key = meme_key
message = f"表情“{self.meme_key}”不存在"
super().__init__(message)
class TextOverLength(MemeGeneratorException):
status_code: int = 532
def __init__(self, text: str):
self.text = text
repr = text if len(text) <= 10 else (text[:10] + "...")
message = f"文本“{repr}”过长"
super().__init__(message)
class OpenImageFailed(MemeGeneratorException):
status_code: int = 533
def __init__(self, error_message: str):
self.error_message = error_message
message = f"图片加载失败({self.error_message})"
super().__init__(message)
class ParamsMismatch(MemeGeneratorException):
status_code: int = 540
class ImageNumberMismatch(ParamsMismatch):
status_code: int = 541
def __init__(self, min_images: int = 0, max_images: int = 0):
self.min_images = min_images
self.max_images = max_images
message = f"图片数量不符,图片数量应为 {min_images}" + (
f" ~ {max_images}" if max_images > min_images else ""
)
super().__init__(message)
class TextNumberMismatch(ParamsMismatch):
status_code: int = 542
def __init__(self, min_texts: int = 0, max_texts: int = 0):
self.min_texts = min_texts
self.max_texts = max_texts
message = f"文本数量不符,文本数量应为 {min_texts}" + (
f" ~ {max_texts}" if max_texts > min_texts else ""
)
super().__init__(message)
class TextOrNameNotEnough(ParamsMismatch):
status_code: int = 543
def __init__(self, message: Optional[str] = None):
message = message or "文本或用户名数量不足"
super().__init__(message)
class ArgMismatch(ParamsMismatch):
status_code: int = 550
class ArgParserMismatch(ArgMismatch):
status_code: int = 551
def __init__(self, error_message: str):
self.error_message = error_message
message = f"参数解析失败({self.error_message})"
super().__init__(message)
class ArgModelMismatch(ArgMismatch):
status_code: int = 552
def __init__(self, error_message: str):
self.error_message = error_message
message = f"参数模型验证失败({self.error_message})"
super().__init__(message)
class MemeFeedback(MemeGeneratorException):
status_code: int = 560
|