Skip to content

Commit bba9458

Browse files
committed
added __all__ fields
1 parent 9dffd3b commit bba9458

File tree

9 files changed

+66
-60
lines changed

9 files changed

+66
-60
lines changed

src/python3_anticaptcha/control.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,7 @@ async def aio_get_balance(self) -> dict:
158158
Notes:
159159
https://anti-captcha.com/apidoc/methods/getBalance
160160
"""
161-
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
162-
return await self._captcha_handling_instrument.send_post_request(
161+
return await AIOCaptchaInstrument.send_post_request(
163162
url_postfix=ControlPostfixEnm.GET_BALANCE, payload={"clientKey": self.create_task_payload.clientKey}
164163
)
165164

@@ -346,8 +345,7 @@ async def aio_get_spending_stats(self, **kwargs) -> dict:
346345
Notes:
347346
https://anti-captcha.com/apidoc/methods/getSpendingStats
348347
"""
349-
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
350-
return await self._captcha_handling_instrument.send_post_request(
348+
return await AIOCaptchaInstrument.send_post_request(
351349
url_postfix=ControlPostfixEnm.GET_SPENDING_STATS,
352350
payload={"clientKey": self.create_task_payload.clientKey, **kwargs},
353351
)
@@ -431,8 +429,7 @@ async def aio_get_app_stats(self, softId: int, mode: Optional[str] = None) -> di
431429
Notes:
432430
https://anti-captcha.com/apidoc/methods/getAppStats
433431
"""
434-
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
435-
return await self._captcha_handling_instrument.send_post_request(
432+
return await AIOCaptchaInstrument.send_post_request(
436433
url_postfix=ControlPostfixEnm.GET_APP_STATS,
437434
payload={"clientKey": self.create_task_payload.clientKey, "softId": softId, "mode": mode},
438435
)
@@ -480,8 +477,7 @@ async def aio_report_incorrect_image(self, taskId: int) -> dict:
480477
Notes:
481478
https://anti-captcha.com/apidoc/methods/reportIncorrectImageCaptcha
482479
"""
483-
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
484-
return await self._captcha_handling_instrument.send_post_request(
480+
return await AIOCaptchaInstrument.send_post_request(
485481
url_postfix=ControlPostfixEnm.REPORT_INCORRECT_IMAGE_CAPTCHA,
486482
payload={"clientKey": self.create_task_payload.clientKey, "taskId": taskId},
487483
)
@@ -529,8 +525,7 @@ async def aio_report_incorrect_recaptcha(self, taskId: int) -> dict:
529525
Notes:
530526
https://anti-captcha.com/apidoc/methods/reportIncorrectRecaptcha
531527
"""
532-
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
533-
return await self._captcha_handling_instrument.send_post_request(
528+
return await AIOCaptchaInstrument.send_post_request(
534529
url_postfix=ControlPostfixEnm.REPORT_INCORRECT_RECAPTCHA,
535530
payload={"clientKey": self.create_task_payload.clientKey, "taskId": taskId},
536531
)
@@ -578,8 +573,7 @@ async def aio_report_correct_recaptcha(self, taskId: int) -> dict:
578573
Notes:
579574
https://anti-captcha.com/apidoc/methods/reportCorrectRecaptcha
580575
"""
581-
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
582-
return await self._captcha_handling_instrument.send_post_request(
576+
return await AIOCaptchaInstrument.send_post_request(
583577
url_postfix=ControlPostfixEnm.REPORT_CORRECT_RECAPTCHA,
584578
payload={"clientKey": self.create_task_payload.clientKey, "taskId": taskId},
585579
)
@@ -627,8 +621,7 @@ async def aio_report_incorrect_hcaptcha(self, taskId: int) -> dict:
627621
Notes:
628622
https://anti-captcha.com/apidoc/methods/reportIncorrectHcaptcha
629623
"""
630-
self._captcha_handling_instrument = AIOCaptchaInstrument(captcha_params=self)
631-
return await self._captcha_handling_instrument.send_post_request(
624+
return await AIOCaptchaInstrument.send_post_request(
632625
url_postfix=ControlPostfixEnm.REPORT_INCORRECT_HCAPTCHA,
633626
payload={"clientKey": self.create_task_payload.clientKey, "taskId": taskId},
634627
)

src/python3_anticaptcha/core/aio_captcha_instrument.py

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,6 @@ async def __body_file_processing(
101101
self.result.errorId = 12
102102
self.result.errorCode = self.NO_CAPTCHA_ERR
103103

104-
async def _url_read(self, url: str, **kwargs) -> bytes:
105-
"""
106-
Async method read bytes from link
107-
"""
108-
async with aiohttp.ClientSession() as session:
109-
async for attempt in ASYNC_RETRIES:
110-
with attempt:
111-
async with session.get(url=url, **kwargs) as resp:
112-
return await resp.content.read()
113-
114104
async def _create_task(self, url_postfix: str = CREATE_TASK_POSTFIX) -> CreateTaskResponseSer:
115105
"""
116106
Function send SYNC request to service and wait for result
@@ -128,23 +118,6 @@ async def _create_task(self, url_postfix: str = CREATE_TASK_POSTFIX) -> CreateTa
128118
logging.exception(error)
129119
raise
130120

131-
@staticmethod
132-
async def send_post_request(payload: Optional[dict] = None, url_postfix: str = CREATE_TASK_POSTFIX) -> dict:
133-
"""
134-
Function send ASYNC request to service and wait for result
135-
"""
136-
137-
async with aiohttp.ClientSession() as session:
138-
try:
139-
async with session.post(parse.urljoin(BASE_REQUEST_URL, url_postfix), json=payload) as resp:
140-
if resp.status == 200:
141-
return await resp.json()
142-
else:
143-
raise ValueError(resp.reason)
144-
except Exception as error:
145-
logging.exception(error)
146-
raise
147-
148121
async def _get_result(self, url_response: str = GET_RESULT_POSTFIX) -> dict:
149122
attempts = attempts_generator()
150123
# Send request for status of captcha solution.
@@ -166,3 +139,31 @@ async def _get_result(self, url_response: str = GET_RESULT_POSTFIX) -> dict:
166139
else:
167140
json_result.update({"taskId": self.captcha_params.get_result_params.taskId})
168141
return json_result
142+
143+
@staticmethod
144+
async def _url_read(url: str, **kwargs) -> bytes:
145+
"""
146+
Async method read bytes from link
147+
"""
148+
async with aiohttp.ClientSession() as session:
149+
async for attempt in ASYNC_RETRIES:
150+
with attempt:
151+
async with session.get(url=url, **kwargs) as resp:
152+
return await resp.content.read()
153+
154+
@staticmethod
155+
async def send_post_request(payload: Optional[dict] = None, url_postfix: str = CREATE_TASK_POSTFIX) -> dict:
156+
"""
157+
Function send ASYNC request to service and wait for result
158+
"""
159+
160+
async with aiohttp.ClientSession() as session:
161+
try:
162+
async with session.post(parse.urljoin(BASE_REQUEST_URL, url_postfix), json=payload) as resp:
163+
if resp.status == 200:
164+
return await resp.json()
165+
else:
166+
raise ValueError(resp.reason)
167+
except Exception as error:
168+
logging.exception(error)
169+
raise

src/python3_anticaptcha/core/sio_captcha_instrument.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,6 @@ def _create_task(self, url_postfix: str = CREATE_TASK_POSTFIX) -> CreateTaskResp
123123
logging.exception(error)
124124
raise
125125

126-
@staticmethod
127-
def send_post_request(
128-
payload: Optional[dict] = None,
129-
session: requests.Session = requests.Session(),
130-
url_postfix: str = CREATE_TASK_POSTFIX,
131-
) -> dict:
132-
"""
133-
Function send SYNC request to service and wait for result
134-
"""
135-
try:
136-
resp = session.post(parse.urljoin(BASE_REQUEST_URL, url_postfix), json=payload)
137-
if resp.status_code == 200:
138-
return resp.json()
139-
else:
140-
raise ValueError(resp.raise_for_status())
141-
except Exception as error:
142-
logging.exception(error)
143-
raise
144-
145126
def _url_read(self, url: str, **kwargs):
146127
"""
147128
Method open links
@@ -166,3 +147,22 @@ def _get_result(self, url_response: str = GET_RESULT_POSTFIX) -> dict:
166147
else:
167148
self.session.close()
168149
return captcha_response.to_dict()
150+
151+
@staticmethod
152+
def send_post_request(
153+
payload: Optional[dict] = None,
154+
session: requests.Session = requests.Session(),
155+
url_postfix: str = CREATE_TASK_POSTFIX,
156+
) -> dict:
157+
"""
158+
Function send SYNC request to service and wait for result
159+
"""
160+
try:
161+
resp = session.post(parse.urljoin(BASE_REQUEST_URL, url_postfix), json=payload)
162+
if resp.status_code == 200:
163+
return resp.json()
164+
else:
165+
raise ValueError(resp.raise_for_status())
166+
except Exception as error:
167+
logging.exception(error)
168+
raise

src/python3_anticaptcha/custom_task.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from .core.base import CaptchaParams
44
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
55

6+
__all__ = ("CustomTask",)
7+
68

79
class CustomTask(CaptchaParams):
810
def __init__(

src/python3_anticaptcha/fun_captcha.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from .core.base import CaptchaParams
44
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
55

6+
__all__ = ("FunCaptcha",)
7+
68

79
class FunCaptcha(CaptchaParams):
810
def __init__(

src/python3_anticaptcha/gee_test.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from .core.base import CaptchaParams
44
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
55

6+
__all__ = ("GeeTest",)
7+
68

79
class GeeTest(CaptchaParams):
810
def __init__(

src/python3_anticaptcha/recaptcha_v2.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from .core.base import CaptchaParams
44
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
55

6+
__all__ = ("ReCaptchaV2",)
7+
68

79
class ReCaptchaV2(CaptchaParams):
810
def __init__(

src/python3_anticaptcha/recaptcha_v3.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from .core.base import CaptchaParams
44
from .core.enum import CaptchaTypeEnm
55

6+
__all__ = ("ReCaptchaV3",)
7+
68

79
class ReCaptchaV3(CaptchaParams):
810
def __init__(

src/python3_anticaptcha/turnstile.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from .core.base import CaptchaParams
44
from .core.enum import ProxyTypeEnm, CaptchaTypeEnm
55

6+
__all__ = ("Turnstile",)
7+
68

79
class Turnstile(CaptchaParams):
810
def __init__(

0 commit comments

Comments
 (0)