mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-28 08:04:13 +08:00
fix
This commit is contained in:
parent
e9b7655e4d
commit
d5b3f73cef
@ -262,6 +262,8 @@ curl_ws_send.restype=CURLcode
|
|||||||
curl_easy_duphandle=libcurl.curl_easy_duphandle
|
curl_easy_duphandle=libcurl.curl_easy_duphandle
|
||||||
curl_easy_duphandle.argtypes=CURL,
|
curl_easy_duphandle.argtypes=CURL,
|
||||||
curl_easy_duphandle.restype=CURL
|
curl_easy_duphandle.restype=CURL
|
||||||
|
curl_easy_reset=libcurl.curl_easy_reset
|
||||||
|
curl_easy_reset.argtypes=CURL,
|
||||||
CURLWS_TEXT=1<<0
|
CURLWS_TEXT=1<<0
|
||||||
CURLWS_BINARY=1<<1
|
CURLWS_BINARY=1<<1
|
||||||
CURLWS_CLOSE=1<<3
|
CURLWS_CLOSE=1<<3
|
||||||
|
@ -10,6 +10,15 @@ class autostatus:
|
|||||||
|
|
||||||
def __del__(self):
|
def __del__(self):
|
||||||
self.ref._status=0
|
self.ref._status=0
|
||||||
|
class Response(ResponseBase):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.last_error=0
|
||||||
|
def iter_content(self,chunk_size=1024):
|
||||||
|
yield self.content
|
||||||
|
def raise_for_status(self):
|
||||||
|
if self.last_error:
|
||||||
|
raise CURLException(self.last_error)
|
||||||
class Session(Sessionbase):
|
class Session(Sessionbase):
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
@ -95,9 +104,10 @@ class Session(Sessionbase):
|
|||||||
resp=Response()
|
resp=Response()
|
||||||
resp.content=self._getmembyte(_content)
|
resp.content=self._getmembyte(_content)
|
||||||
resp.status_code=self._getStatusCode(curl)
|
resp.status_code=self._getStatusCode(curl)
|
||||||
|
resp.last_error=self.last_error
|
||||||
resp.headers=self._update_header_cookie(self._getmembyte(_headers).decode('utf8'))
|
resp.headers=self._update_header_cookie(self._getmembyte(_headers).decode('utf8'))
|
||||||
resp.cookies=self.cookies
|
resp.cookies=self.cookies
|
||||||
|
curl_easy_reset(curl)
|
||||||
return resp
|
return resp
|
||||||
|
|
||||||
Sessionimpl[0]=Session
|
Sessionimpl[0]=Session
|
||||||
|
@ -46,7 +46,7 @@ class CaseInsensitiveDict(MutableMapping):
|
|||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return str(dict(self.items()))
|
return str(dict(self.items()))
|
||||||
class Response:
|
class ResponseBase:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.headers=CaseInsensitiveDict()
|
self.headers=CaseInsensitiveDict()
|
||||||
self.cookies={}
|
self.cookies={}
|
||||||
@ -67,8 +67,6 @@ class Response:
|
|||||||
return charset
|
return charset
|
||||||
def json(self):
|
def json(self):
|
||||||
return json.loads(self.text)
|
return json.loads(self.text)
|
||||||
def iter_content(self,chunk_size=1024):
|
|
||||||
yield self.content
|
|
||||||
class Sessionbase:
|
class Sessionbase:
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
self.UA='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
self.UA='Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
|
||||||
|
@ -7,7 +7,7 @@ try:
|
|||||||
from brotli_dec import decompress
|
from brotli_dec import decompress
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
class winhttp_resp(Response):
|
class Response(ResponseBase):
|
||||||
def iter_content(self,chunk_size=1024):
|
def iter_content(self,chunk_size=1024):
|
||||||
downloadedSize=DWORD()
|
downloadedSize=DWORD()
|
||||||
buff=create_string_buffer(chunk_size)
|
buff=create_string_buffer(chunk_size)
|
||||||
@ -19,17 +19,16 @@ class winhttp_resp(Response):
|
|||||||
del self.hconn
|
del self.hconn
|
||||||
break
|
break
|
||||||
yield buff[:downloadedSize.value]
|
yield buff[:downloadedSize.value]
|
||||||
|
def raise_for_status(self):
|
||||||
|
error=GetLastError()
|
||||||
|
if error:
|
||||||
|
raise WinhttpException(error)
|
||||||
class Session(Sessionbase):
|
class Session(Sessionbase):
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.hSession=AutoWinHttpHandle(WinHttpOpen(self.UA,WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,WINHTTP_NO_PROXY_NAME,WINHTTP_NO_PROXY_BYPASS,0))
|
self.hSession=AutoWinHttpHandle(WinHttpOpen(self.UA,WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,WINHTTP_NO_PROXY_NAME,WINHTTP_NO_PROXY_BYPASS,0))
|
||||||
if self.hSession==0:
|
if self.hSession==0:
|
||||||
raise WinhttpException(GetLastError())
|
raise WinhttpException(GetLastError())
|
||||||
|
|
||||||
def raise_for_status(self):
|
|
||||||
error=GetLastError()
|
|
||||||
if error:
|
|
||||||
raise WinhttpException(error)
|
|
||||||
|
|
||||||
|
|
||||||
def _getheaders(self,hreq):
|
def _getheaders(self,hreq):
|
||||||
@ -49,7 +48,9 @@ class Session(Sessionbase):
|
|||||||
pointer(dwSize),
|
pointer(dwSize),
|
||||||
None )
|
None )
|
||||||
if bResults==0:
|
if bResults==0:
|
||||||
self.raise_for_status()
|
error=GetLastError()
|
||||||
|
if error:
|
||||||
|
raise WinhttpException(error)
|
||||||
return dwStatusCode.value
|
return dwStatusCode.value
|
||||||
|
|
||||||
def _set_proxy(self,hsess,proxy):
|
def _set_proxy(self,hsess,proxy):
|
||||||
@ -81,7 +82,7 @@ class Session(Sessionbase):
|
|||||||
raise WinhttpException(GetLastError())
|
raise WinhttpException(GetLastError())
|
||||||
|
|
||||||
headers=self._update_header_cookie(self._getheaders(hRequest))
|
headers=self._update_header_cookie(self._getheaders(hRequest))
|
||||||
resp=winhttp_resp()
|
resp=Response()
|
||||||
resp.status_code=self._getStatusCode(hRequest)
|
resp.status_code=self._getStatusCode(hRequest)
|
||||||
resp.headers=headers
|
resp.headers=headers
|
||||||
resp.cookies=self.cookies
|
resp.cookies=self.cookies
|
||||||
|
Loading…
x
Reference in New Issue
Block a user