This commit is contained in:
恍兮惚兮 2024-08-09 21:48:20 +08:00
parent d23939555e
commit 64fbc6cb1e
3 changed files with 103 additions and 102 deletions

View File

@ -41,95 +41,7 @@ class curl_ws_frame(Structure):
] ]
class CURLcode(c_int): CURLcode = c_uint
OK = 0
UNSUPPORTED_PROTOCOL = 1
FAILED_INIT = 2
URL_MALFORMAT = 3
COULDNT_RESOLVE_PROXY = 5
COULDNT_RESOLVE_HOST = 6
COULDNT_CONNECT = 7
FTP_WEIRD_SERVER_REPLY = 8
REMOTE_ACCESS_DENIED = 9
FTP_WEIRD_PASS_REPLY = 11
FTP_WEIRD_PASV_REPLY = 13
FTP_WEIRD_227_FORMAT = 14
FTP_CANT_GET_HOST = 15
FTP_COULDNT_SET_TYPE = 17
PARTIAL_FILE = 18
FTP_COULDNT_RETR_FILE = 19
QUOTE_ERROR = 21
HTTP_RETURNED_ERROR = 22
WRITE_ERROR = 23
UPLOAD_FAILED = 25
READ_ERROR = 26
OUT_OF_MEMORY = 27
OPERATION_TIMEDOUT = 28
FTP_PORT_FAILED = 30
FTP_COULDNT_USE_REST = 31
RANGE_ERROR = 33
HTTP_POST_ERROR = 34
SSL_CONNECT_ERROR = 35
BAD_DOWNLOAD_RESUME = 36
FILE_COULDNT_READ_FILE = 37
LDAP_CANNOT_BIND = 38
LDAP_SEARCH_FAILED = 39
FUNCTION_NOT_FOUND = 41
ABORTED_BY_CALLBACK = 42
BAD_FUNCTION_ARGUMENT = 43
INTERFACE_FAILED = 45
TOO_MANY_REDIRECTS = 47
UNKNOWN_TELNET_OPTION = 48
TELNET_OPTION_SYNTAX = 49
PEER_FAILED_VERIFICATION = 51
GOT_NOTHING = 52
SSL_ENGINE_NOTFOUND = 53
SSL_ENGINE_SETFAILED = 54
SEND_ERROR = 55
RECV_ERROR = 56
SSL_CERTPROBLEM = 58
SSL_CIPHER = 59
SSL_CACERT = 60
BAD_CONTENT_ENCODING = 61
LDAP_INVALID_URL = 62
FILESIZE_EXCEEDED = 63
USE_SSL_FAILED = 64
SEND_FAIL_REWIND = 65
SSL_ENGINE_INITFAILED = 66
LOGIN_DENIED = 67
TFTP_NOTFOUND = 68
TFTP_PERM = 69
REMOTE_DISK_FULL = 70
TFTP_ILLEGAL = 71
TFTP_UNKNOWNID = 72
REMOTE_FILE_EXISTS = 73
TFTP_NOSUCHUSER = 74
CONV_FAILED = 75
CONV_REQD = 76
SSL_CACERT_BADFILE = 77
REMOTE_FILE_NOT_FOUND = 78
SSH = 79
SSL_SHUTDOWN_FAILED = 80
AGAIN = 81
SSL_CRL_BADFILE = 82
SSL_ISSUER_ERROR = 83
FTP_PRET_FAILED = 84
RTSP_CSEQ_ERROR = 85
RTSP_SESSION_ERROR = 86
FTP_BAD_FILE_LIST = 87
CHUNK_FAILED = 88
NO_CONNECTION_AVAILABLE = 89
SSL_PINNEDPUBKEYNOTMATCH = 90
SSL_INVALIDCERTSTATUS = 91
HTTP2_STREAM = 92
RECURSIVE_API_CALL = 93
AUTH_ERROR = 94
HTTP3 = 95
QUIC_CONNECT_ERROR = 96
PROXY = 97
SSL_CLIENTCERT = 98
UNRECOVERABLE_POLL = 99
LAST = 100
class CURLoption(c_int): class CURLoption(c_int):
@ -321,22 +233,111 @@ class AutoCURLHandle(CURL):
class CURLException(RequestException): class CURLException(RequestException):
OK = 0
UNSUPPORTED_PROTOCOL = 1
FAILED_INIT = 2
URL_MALFORMAT = 3
COULDNT_RESOLVE_PROXY = 5
COULDNT_RESOLVE_HOST = 6
COULDNT_CONNECT = 7
FTP_WEIRD_SERVER_REPLY = 8
REMOTE_ACCESS_DENIED = 9
FTP_WEIRD_PASS_REPLY = 11
FTP_WEIRD_PASV_REPLY = 13
FTP_WEIRD_227_FORMAT = 14
FTP_CANT_GET_HOST = 15
FTP_COULDNT_SET_TYPE = 17
PARTIAL_FILE = 18
FTP_COULDNT_RETR_FILE = 19
QUOTE_ERROR = 21
HTTP_RETURNED_ERROR = 22
WRITE_ERROR = 23
UPLOAD_FAILED = 25
READ_ERROR = 26
OUT_OF_MEMORY = 27
OPERATION_TIMEDOUT = 28
FTP_PORT_FAILED = 30
FTP_COULDNT_USE_REST = 31
RANGE_ERROR = 33
HTTP_POST_ERROR = 34
SSL_CONNECT_ERROR = 35
BAD_DOWNLOAD_RESUME = 36
FILE_COULDNT_READ_FILE = 37
LDAP_CANNOT_BIND = 38
LDAP_SEARCH_FAILED = 39
FUNCTION_NOT_FOUND = 41
ABORTED_BY_CALLBACK = 42
BAD_FUNCTION_ARGUMENT = 43
INTERFACE_FAILED = 45
TOO_MANY_REDIRECTS = 47
UNKNOWN_TELNET_OPTION = 48
TELNET_OPTION_SYNTAX = 49
PEER_FAILED_VERIFICATION = 51
GOT_NOTHING = 52
SSL_ENGINE_NOTFOUND = 53
SSL_ENGINE_SETFAILED = 54
SEND_ERROR = 55
RECV_ERROR = 56
SSL_CERTPROBLEM = 58
SSL_CIPHER = 59
SSL_CACERT = 60
BAD_CONTENT_ENCODING = 61
LDAP_INVALID_URL = 62
FILESIZE_EXCEEDED = 63
USE_SSL_FAILED = 64
SEND_FAIL_REWIND = 65
SSL_ENGINE_INITFAILED = 66
LOGIN_DENIED = 67
TFTP_NOTFOUND = 68
TFTP_PERM = 69
REMOTE_DISK_FULL = 70
TFTP_ILLEGAL = 71
TFTP_UNKNOWNID = 72
REMOTE_FILE_EXISTS = 73
TFTP_NOSUCHUSER = 74
CONV_FAILED = 75
CONV_REQD = 76
SSL_CACERT_BADFILE = 77
REMOTE_FILE_NOT_FOUND = 78
SSH = 79
SSL_SHUTDOWN_FAILED = 80
AGAIN = 81
SSL_CRL_BADFILE = 82
SSL_ISSUER_ERROR = 83
FTP_PRET_FAILED = 84
RTSP_CSEQ_ERROR = 85
RTSP_SESSION_ERROR = 86
FTP_BAD_FILE_LIST = 87
CHUNK_FAILED = 88
NO_CONNECTION_AVAILABLE = 89
SSL_PINNEDPUBKEYNOTMATCH = 90
SSL_INVALIDCERTSTATUS = 91
HTTP2_STREAM = 92
RECURSIVE_API_CALL = 93
AUTH_ERROR = 94
HTTP3 = 95
QUIC_CONNECT_ERROR = 96
PROXY = 97
SSL_CLIENTCERT = 98
UNRECOVERABLE_POLL = 99
LAST = 100
def __init__(self, code) -> None: def __init__(self, code) -> None:
if not isinstance(code, CURLcode): error = f"UNKNOWN ERROR {code}"
raise Exception("not a valid CURLException") message = curl_easy_strerror(code).decode("utf8")
self.errorcode = code.value for _ in dir(self):
error = curl_easy_strerror(code).decode("utf8") if _.startswith("") and code == getattr(self, _):
for _ in dir(CURLcode): error = _
if _.startswith("") and code.value == getattr(CURLcode, _):
error = f"{_}: {error}"
break break
if message:
error += f": {message}"
super().__init__(error) super().__init__(error)
def MaybeRaiseException(error: CURLcode): def MaybeRaiseException(error):
if not error.value: if not error:
return return
e = CURLException(error) e = CURLException(error)
if error.value == CURLcode.OPERATION_TIMEDOUT: if error == CURLException.OPERATION_TIMEDOUT:
raise Timeout(e) raise Timeout(e)
raise e raise e

View File

@ -25,7 +25,7 @@ class WebSocket:
error = curl_ws_recv( error = curl_ws_recv(
self.curl, buffer, (10240), pointer(rlen), pointer(meta) self.curl, buffer, (10240), pointer(rlen), pointer(meta)
) )
if error.value == CURLcode.AGAIN: if error == CURLException.AGAIN:
time.sleep(0.01) time.sleep(0.01)
elif error: elif error:
MaybeRaiseException(error) MaybeRaiseException(error)

View File

@ -99,7 +99,7 @@ class basetrans(commonbase):
gobject.baseobject.textgetmethod( gobject.baseobject.textgetmethod(
"<msg_error_not_refresh>" "<msg_error_not_refresh>"
+ globalconfig["fanyi"][self.typename]["name"] + globalconfig["fanyi"][self.typename]["name"]
+ " inittranslator failed : " + " init translator failed : "
+ str(stringfyerror(e)) + str(stringfyerror(e))
) )
print_exc() print_exc()
@ -309,7 +309,7 @@ class basetrans(commonbase):
try: try:
self._private_init() self._private_init()
except Exception as e: except Exception as e:
raise Exception("inittranslator failed : " + str(stringfyerror(e))) raise Exception("init translator failed : " + str(stringfyerror(e)))
return self.maybecachetranslate(contentraw, contentsolved, is_auto_run) return self.maybecachetranslate(contentraw, contentsolved, is_auto_run)
def _fythread(self): def _fythread(self):