added __all__ fields

This commit is contained in:
Andrei 2024-12-19 20:29:22 +03:00
parent 9dffd3b691
commit bba945836d
9 changed files with 66 additions and 60 deletions

View File

@ -158,8 +158,7 @@ class Control(CaptchaParams):
Notes:
https://anti-captcha.com/apidoc/methods/getBalance
"""
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
return await self._captcha_handling_instrument.send_post_request(
return await AIOCaptchaInstrument.send_post_request(
url_postfix=ControlPostfixEnm.GET_BALANCE, payload={"clientKey": self.create_task_payload.clientKey}
)
@ -346,8 +345,7 @@ class Control(CaptchaParams):
Notes:
https://anti-captcha.com/apidoc/methods/getSpendingStats
"""
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
return await self._captcha_handling_instrument.send_post_request(
return await AIOCaptchaInstrument.send_post_request(
url_postfix=ControlPostfixEnm.GET_SPENDING_STATS,
payload={"clientKey": self.create_task_payload.clientKey, **kwargs},
)
@ -431,8 +429,7 @@ class Control(CaptchaParams):
Notes:
https://anti-captcha.com/apidoc/methods/getAppStats
"""
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
return await self._captcha_handling_instrument.send_post_request(
return await AIOCaptchaInstrument.send_post_request(
url_postfix=ControlPostfixEnm.GET_APP_STATS,
payload={"clientKey": self.create_task_payload.clientKey, "softId": softId, "mode": mode},
)
@ -480,8 +477,7 @@ class Control(CaptchaParams):
Notes:
https://anti-captcha.com/apidoc/methods/reportIncorrectImageCaptcha
"""
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
return await self._captcha_handling_instrument.send_post_request(
return await AIOCaptchaInstrument.send_post_request(
url_postfix=ControlPostfixEnm.REPORT_INCORRECT_IMAGE_CAPTCHA,
payload={"clientKey": self.create_task_payload.clientKey, "taskId": taskId},
)
@ -529,8 +525,7 @@ class Control(CaptchaParams):
Notes:
https://anti-captcha.com/apidoc/methods/reportIncorrectRecaptcha
"""
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
return await self._captcha_handling_instrument.send_post_request(
return await AIOCaptchaInstrument.send_post_request(
url_postfix=ControlPostfixEnm.REPORT_INCORRECT_RECAPTCHA,
payload={"clientKey": self.create_task_payload.clientKey, "taskId": taskId},
)
@ -578,8 +573,7 @@ class Control(CaptchaParams):
Notes:
https://anti-captcha.com/apidoc/methods/reportCorrectRecaptcha
"""
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
return await self._captcha_handling_instrument.send_post_request(
return await AIOCaptchaInstrument.send_post_request(
url_postfix=ControlPostfixEnm.REPORT_CORRECT_RECAPTCHA,
payload={"clientKey": self.create_task_payload.clientKey, "taskId": taskId},
)
@ -627,8 +621,7 @@ class Control(CaptchaParams):
Notes:
https://anti-captcha.com/apidoc/methods/reportIncorrectHcaptcha
"""
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
return await self._captcha_handling_instrument.send_post_request(
return await AIOCaptchaInstrument.send_post_request(
url_postfix=ControlPostfixEnm.REPORT_INCORRECT_HCAPTCHA,
payload={"clientKey": self.create_task_payload.clientKey, "taskId": taskId},
)

View File

@ -101,16 +101,6 @@ class AIOCaptchaInstrument(CaptchaInstrument):
self.result.errorId = 12
self.result.errorCode = self.NO_CAPTCHA_ERR
async def _url_read(self, url: str, **kwargs) -> bytes:
"""
Async method read bytes from link
"""
async with aiohttp.ClientSession() as session:
async for attempt in ASYNC_RETRIES:
with attempt:
async with session.get(url=url, **kwargs) as resp:
return await resp.content.read()
async def _create_task(self, url_postfix: str = CREATE_TASK_POSTFIX) -> CreateTaskResponseSer:
"""
Function send SYNC request to service and wait for result
@ -128,23 +118,6 @@ class AIOCaptchaInstrument(CaptchaInstrument):
logging.exception(error)
raise
@staticmethod
async def send_post_request(payload: Optional[dict] = None, url_postfix: str = CREATE_TASK_POSTFIX) -> dict:
"""
Function send ASYNC request to service and wait for result
"""
async with aiohttp.ClientSession() as session:
try:
async with session.post(parse.urljoin(BASE_REQUEST_URL, url_postfix), json=payload) as resp:
if resp.status == 200:
return await resp.json()
else:
raise ValueError(resp.reason)
except Exception as error:
logging.exception(error)
raise
async def _get_result(self, url_response: str = GET_RESULT_POSTFIX) -> dict:
attempts = attempts_generator()
# Send request for status of captcha solution.
@ -166,3 +139,31 @@ class AIOCaptchaInstrument(CaptchaInstrument):
else:
json_result.update({"taskId": self.captcha_params.get_result_params.taskId})
return json_result
@staticmethod
async def _url_read(url: str, **kwargs) -> bytes:
"""
Async method read bytes from link
"""
async with aiohttp.ClientSession() as session:
async for attempt in ASYNC_RETRIES:
with attempt:
async with session.get(url=url, **kwargs) as resp:
return await resp.content.read()
@staticmethod
async def send_post_request(payload: Optional[dict] = None, url_postfix: str = CREATE_TASK_POSTFIX) -> dict:
"""
Function send ASYNC request to service and wait for result
"""
async with aiohttp.ClientSession() as session:
try:
async with session.post(parse.urljoin(BASE_REQUEST_URL, url_postfix), json=payload) as resp:
if resp.status == 200:
return await resp.json()
else:
raise ValueError(resp.reason)
except Exception as error:
logging.exception(error)
raise

View File

@ -123,25 +123,6 @@ class SIOCaptchaInstrument(CaptchaInstrument):
logging.exception(error)
raise
@staticmethod
def send_post_request(
payload: Optional[dict] = None,
session: requests.Session = requests.Session(),
url_postfix: str = CREATE_TASK_POSTFIX,
) -> dict:
"""
Function send SYNC request to service and wait for result
"""
try:
resp = session.post(parse.urljoin(BASE_REQUEST_URL, url_postfix), json=payload)
if resp.status_code == 200:
return resp.json()
else:
raise ValueError(resp.raise_for_status())
except Exception as error:
logging.exception(error)
raise
def _url_read(self, url: str, **kwargs):
"""
Method open links
@ -166,3 +147,22 @@ class SIOCaptchaInstrument(CaptchaInstrument):
else:
self.session.close()
return captcha_response.to_dict()
@staticmethod
def send_post_request(
payload: Optional[dict] = None,
session: requests.Session = requests.Session(),
url_postfix: str = CREATE_TASK_POSTFIX,
) -> dict:
"""
Function send SYNC request to service and wait for result
"""
try:
resp = session.post(parse.urljoin(BASE_REQUEST_URL, url_postfix), json=payload)
if resp.status_code == 200:
return resp.json()
else:
raise ValueError(resp.raise_for_status())
except Exception as error:
logging.exception(error)
raise

View File

@ -3,6 +3,8 @@ from typing import Optional
from .core.base import CaptchaParams
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
__all__ = ("CustomTask",)
class CustomTask(CaptchaParams):
def __init__(

View File

@ -3,6 +3,8 @@ from typing import Union, Optional
from .core.base import CaptchaParams
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
__all__ = ("FunCaptcha",)
class FunCaptcha(CaptchaParams):
def __init__(

View File

@ -3,6 +3,8 @@ from typing import Union, Optional
from .core.base import CaptchaParams
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
__all__ = ("GeeTest",)
class GeeTest(CaptchaParams):
def __init__(

View File

@ -3,6 +3,8 @@ from typing import Union, Optional
from .core.base import CaptchaParams
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
__all__ = ("ReCaptchaV2",)
class ReCaptchaV2(CaptchaParams):
def __init__(

View File

@ -3,6 +3,8 @@ from typing import Optional
from .core.base import CaptchaParams
from .core.enum import CaptchaTypeEnm
__all__ = ("ReCaptchaV3",)
class ReCaptchaV3(CaptchaParams):
def __init__(

View File

@ -3,6 +3,8 @@ from typing import Union, Optional
from .core.base import CaptchaParams
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
__all__ = ("Turnstile",)
class Turnstile(CaptchaParams):
def __init__(