Skip to content

Commit

Permalink
Merge pull request #313 from AndreiDrang/master
Browse files Browse the repository at this point in the history
Upd docs building process
  • Loading branch information
AndreiDrang authored Nov 29, 2024
2 parents cdc95ae + a3105f8 commit 4c34359
Show file tree
Hide file tree
Showing 26 changed files with 85 additions and 58 deletions.
7 changes: 4 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@

# -- Project information -----------------------------------------------------
project = "python-rucaptcha"
copyright = (f"{date.today().year}, " +
f"AndreiDrang; Release - {__version__};" +
f"Last update - {date.today()}")
copyright = (
f"{date.today().year}, " + f"AndreiDrang; Release - {__version__};" + f"Last update - {date.today()}"
)
author = "AndreiDrang"

# -- General configuration ---------------------------------------------------
Expand All @@ -44,6 +44,7 @@
"pallets_sphinx_themes",
"sphinxcontrib.autodoc_pydantic",
"enum_tools.autoenum",
"notfound.extension",
)
myst_enable_extensions = ["deflist"]
intersphinx_mapping = {"python": ("https://docs.python.org/3.10/", None)}
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tool.black]
line-length = 120
line-length = 110
target-version = ['py311']
exclude = '''
/(
Expand All @@ -18,7 +18,7 @@ exclude = '''
[tool.isort]
profile = "black"
skip_glob = "examples/**"
line_length = 120
line_length = 110
length_sort = true

[tool.pytest.ini_options]
Expand Down
3 changes: 1 addition & 2 deletions src/python_rucaptcha/amazon_waf.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ def __init__(

# check user params
if method not in AmazonWAFCaptchaEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {AmazonWAFCaptchaEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {AmazonWAFCaptchaEnm.list_values()}")
# insert `gt` param to payload
self.create_task_payload["task"].update(
{
Expand Down
4 changes: 3 additions & 1 deletion src/python_rucaptcha/atb_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def __init__(
"""
super().__init__(method=method, *args, **kwargs)

self.create_task_payload["task"].update({"websiteURL": websiteURL, "appId": appId, "apiServer": apiServer})
self.create_task_payload["task"].update(
{"websiteURL": websiteURL, "appId": appId, "apiServer": apiServer}
)

# check user params
if method not in atbCaptchaEnm.list_values():
Expand Down
6 changes: 2 additions & 4 deletions src/python_rucaptcha/capy_puzzle.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,11 @@ def __init__(
"""
super().__init__(method=method, *args, **kwargs)

self.create_task_payload["task"].update({"websiteURL": websiteURL,
"websiteKey": websiteKey})
self.create_task_payload["task"].update({"websiteURL": websiteURL, "websiteKey": websiteKey})

# check user params
if method not in CapyPuzzleEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {CapyPuzzleEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {CapyPuzzleEnm.list_values()}")

def captcha_handler(self, **kwargs) -> dict:
"""
Expand Down
20 changes: 16 additions & 4 deletions src/python_rucaptcha/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@

from .enums import ServiceEnm, SaveFormatsEnm
from .config import RETRIES, ASYNC_RETRIES
from .serializer import TaskSer, CaptchaOptionsSer, CreateTaskBaseSer, GetTaskResultRequestSer, GetTaskResultResponseSer
from .serializer import (
TaskSer,
CaptchaOptionsSer,
CreateTaskBaseSer,
GetTaskResultRequestSer,
GetTaskResultResponseSer,
)
from .result_handler import get_sync_result, get_async_result


Expand Down Expand Up @@ -79,7 +85,9 @@ def _processing_response(self, **kwargs: dict) -> dict:
time.sleep(self.params.sleep_time)

return get_sync_result(
get_payload=self.get_task_payload, sleep_time=self.params.sleep_time, url_response=self.params.url_response
get_payload=self.get_task_payload,
sleep_time=self.params.sleep_time,
url_response=self.params.url_response,
)

def url_open(self, url: str, **kwargs):
Expand Down Expand Up @@ -174,7 +182,9 @@ def _body_file_processing(
)
# if the file is transferred in base64 encoding
elif captcha_base64:
self.create_task_payload["task"].update({"body": base64.b64encode(captcha_base64).decode("utf-8")})
self.create_task_payload["task"].update(
{"body": base64.b64encode(captcha_base64).decode("utf-8")}
)
# if a URL is passed
elif captcha_link:
try:
Expand Down Expand Up @@ -209,7 +219,9 @@ async def _aio_body_file_processing(
)
# if the file is transferred in base64 encoding
elif captcha_base64:
self.create_task_payload["task"].update({"body": base64.b64encode(captcha_base64).decode("utf-8")})
self.create_task_payload["task"].update(
{"body": base64.b64encode(captcha_base64).decode("utf-8")}
)
# if a URL is passed
elif captcha_link:
try:
Expand Down
8 changes: 6 additions & 2 deletions src/python_rucaptcha/core/result_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
from .serializer import GetTaskResultRequestSer, GetTaskResultResponseSer


def get_sync_result(get_payload: GetTaskResultRequestSer, sleep_time: int, url_response: str) -> Union[dict, Exception]:
def get_sync_result(
get_payload: GetTaskResultRequestSer, sleep_time: int, url_response: str
) -> Union[dict, Exception]:
"""
Function periodically send the SYNC request to service and wait for captcha solving result
"""
Expand Down Expand Up @@ -48,7 +50,9 @@ async def get_async_result(
for _ in attempts:
try:
# send a request for the result of solving the captcha
async with session.post(url_response, json=get_payload.to_dict(), raise_for_status=True) as resp:
async with session.post(
url_response, json=get_payload.to_dict(), raise_for_status=True
) as resp:
captcha_response = await resp.json(content_type=None)
captcha_response = GetTaskResultResponseSer(**captcha_response, taskId=get_payload.taskId)

Expand Down
9 changes: 4 additions & 5 deletions src/python_rucaptcha/cutcaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,13 @@ def __init__(
"""
super().__init__(method=method, *args, **kwargs)

self.create_task_payload["task"].update({"websiteURL": websiteURL,
"miseryKey": miseryKey,
"apiKey": apiKey})
self.create_task_payload["task"].update(
{"websiteURL": websiteURL, "miseryKey": miseryKey, "apiKey": apiKey}
)

# check user params
if method not in CutCaptchaEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {CutCaptchaEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {CutCaptchaEnm.list_values()}")

def captcha_handler(self, **kwargs) -> dict:
"""
Expand Down
4 changes: 3 additions & 1 deletion src/python_rucaptcha/fun_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ def __init__(
"""
super().__init__(method=method, *args, **kwargs)

self.create_task_payload["task"].update({"websiteURL": websiteURL, "websitePublicKey": websitePublicKey})
self.create_task_payload["task"].update(
{"websiteURL": websiteURL, "websitePublicKey": websitePublicKey}
)

# check user params
if method not in FunCaptchaEnm.list_values():
Expand Down
6 changes: 2 additions & 4 deletions src/python_rucaptcha/hcaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,11 @@ def __init__(
"""
super().__init__(method=method, *args, **kwargs)

self.create_task_payload["task"].update({"websiteURL": websiteURL,
"websiteKey": websiteKey})
self.create_task_payload["task"].update({"websiteURL": websiteURL, "websiteKey": websiteKey})

# check user params
if method not in HCaptchaEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {HCaptchaEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {HCaptchaEnm.list_values()}")

def captcha_handler(self, **kwargs) -> dict:
"""
Expand Down
3 changes: 1 addition & 2 deletions src/python_rucaptcha/key_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ def __init__(

# check user params
if method not in KeyCaptchaEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {KeyCaptchaEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {KeyCaptchaEnm.list_values()}")

def captcha_handler(self, **kwargs) -> dict:
"""
Expand Down
9 changes: 4 additions & 5 deletions src/python_rucaptcha/lemin_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,14 +78,13 @@ def __init__(
"""
super().__init__(method=method, *args, **kwargs)

self.create_task_payload["task"].update({"websiteURL": websiteURL,
"captchaId": captchaId,
"div_id": div_id})
self.create_task_payload["task"].update(
{"websiteURL": websiteURL, "captchaId": captchaId, "div_id": div_id}
)

# check user params
if method not in LeminCaptchaEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {LeminCaptchaEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {LeminCaptchaEnm.list_values()}")

def captcha_handler(self, **kwargs) -> dict:
"""
Expand Down
6 changes: 2 additions & 4 deletions src/python_rucaptcha/mt_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,10 @@ def __init__(
"""
super().__init__(method=method, *args, **kwargs)

self.create_task_payload["task"].update({"websiteURL": websiteURL,
"websiteKey": websiteKey})
self.create_task_payload["task"].update({"websiteURL": websiteURL, "websiteKey": websiteKey})
# check user params
if method not in MTCaptchaEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {MTCaptchaEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {MTCaptchaEnm.list_values()}")

def captcha_handler(self, **kwargs) -> dict:
"""
Expand Down
3 changes: 1 addition & 2 deletions src/python_rucaptcha/re_captcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ def __init__(

# check user params
if method not in ReCaptchaEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {ReCaptchaEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {ReCaptchaEnm.list_values()}")

def captcha_handler(self, **kwargs) -> dict:
"""
Expand Down
3 changes: 1 addition & 2 deletions src/python_rucaptcha/tencent.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ def __init__(

# check user params
if method not in TencentEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {TencentEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {TencentEnm.list_values()}")

def captcha_handler(self, **kwargs) -> dict:
"""
Expand Down
3 changes: 1 addition & 2 deletions src/python_rucaptcha/turnstile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def __init__(

# check user params
if method not in TurnstileCaptchaEnm.list_values():
raise ValueError(
f"Invalid method parameter set, available - {TurnstileCaptchaEnm.list_values()}")
raise ValueError(f"Invalid method parameter set, available - {TurnstileCaptchaEnm.list_values()}")

def captcha_handler(self, **kwargs) -> dict:
"""
Expand Down
4 changes: 3 additions & 1 deletion tests/test_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def test_wrong_path(self):
def test_wrong_base64(self):
instance = AudioCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)

result = instance.captcha_handler(captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8"))
result = instance.captcha_handler(
captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8")
)

assert isinstance(result, dict) is True
assert result["errorId"] in (12, 5)
Expand Down
4 changes: 3 additions & 1 deletion tests/test_bounding_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def test_wrong_link(self):

def test_wrong_base64(self):
instance = BoundingBoxCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
result = instance.captcha_handler(captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8"))
result = instance.captcha_handler(
captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8")
)
assert isinstance(result, dict) is True
assert result["errorId"] == 15
assert result["taskId"] is None
Expand Down
4 changes: 3 additions & 1 deletion tests/test_coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def test_wrong_link(self):

def test_wrong_base64(self):
instance = CoordinatesCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
result = instance.captcha_handler(captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8"))
result = instance.captcha_handler(
captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8")
)
assert isinstance(result, dict) is True
assert result["errorId"] == 15
assert result["taskId"] is None
Expand Down
4 changes: 3 additions & 1 deletion tests/test_draw_around.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ def test_wrong_link(self):

def test_wrong_base64(self):
instance = DrawAroundCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
result = instance.captcha_handler(captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8"))
result = instance.captcha_handler(
captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8")
)
assert isinstance(result, dict) is True
assert result["errorId"] == 15
assert result["taskId"] is None
Expand Down
4 changes: 1 addition & 3 deletions tests/test_funcaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@

class TestFunCaptcha(BaseTest):
publickey = "69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC"
pageurl = (
"https://api.funcaptcha.com/tile-game-lite-mode/fc/api/nojs/?pkey=69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC&lang=en"
)
pageurl = "https://api.funcaptcha.com/tile-game-lite-mode/fc/api/nojs/?pkey=69A21A01-CC7B-B9C6-0F9A-E7FA06677FFC&lang=en"
surl = "https://client-api.arkoselabs.com"
kwargs_params = {
"funcaptchaApiJSSubdomain": "sample-api.arkoselabs.com",
Expand Down
4 changes: 3 additions & 1 deletion tests/test_geetest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ class TestGeeTestBase(BaseTest):

@property
def challenge(self):
return requests.get("https://www.geetest.com/demo/gt/register-enFullpage-official").json()["challenge"]
return requests.get("https://www.geetest.com/demo/gt/register-enFullpage-official").json()[
"challenge"
]


class TestGeeTestCore(TestGeeTestBase):
Expand Down
4 changes: 3 additions & 1 deletion tests/test_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ def test_wrong_link(self):

def test_wrong_base64(self):
instance = GridCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
result = instance.captcha_handler(captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8"))
result = instance.captcha_handler(
captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8")
)
assert isinstance(result, dict) is True
assert result["errorId"] == 15
assert result["taskId"] is None
Expand Down
4 changes: 3 additions & 1 deletion tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def test_wrong_link(self):

def test_wrong_base64(self):
instance = ImageCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)
result = instance.captcha_handler(captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8"))
result = instance.captcha_handler(
captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8")
)
assert isinstance(result, dict) is True
assert result["errorId"] == 15
assert result["taskId"] is None
Expand Down
5 changes: 4 additions & 1 deletion tests/test_mtcaptcha.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def test_methods_exists(self):
@pytest.mark.parametrize("method", MTCaptchaEnm.list_values())
def test_args(self, method: str):
instance = MTCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY, websiteURL=self.websiteURL, websiteKey=self.websiteKey, method=method
rucaptcha_key=self.RUCAPTCHA_KEY,
websiteURL=self.websiteURL,
websiteKey=self.websiteKey,
method=method,
)
assert instance.create_task_payload["clientKey"] == self.RUCAPTCHA_KEY
assert instance.create_task_payload["task"]["type"] == method
Expand Down
8 changes: 6 additions & 2 deletions tests/test_rotate.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,9 @@ async def test_aio_basic_data_base64(self):
@pytest.mark.parametrize("save_format", SaveFormatsEnm.list_values())
@pytest.mark.parametrize("img_clearing", (True, False))
def test_const_data_link(self, save_format: str, img_clearing: bool):
instance = RotateCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY, save_format=save_format, img_clearing=img_clearing)
instance = RotateCaptcha(
rucaptcha_key=self.RUCAPTCHA_KEY, save_format=save_format, img_clearing=img_clearing
)

result = instance.captcha_handler(captcha_link=self.captcha_url)

Expand Down Expand Up @@ -199,7 +201,9 @@ async def test_aio_wrong_link(self):
def test_wrong_base64(self):
instance = RotateCaptcha(rucaptcha_key=self.RUCAPTCHA_KEY)

result = instance.captcha_handler(captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8"))
result = instance.captcha_handler(
captcha_base64=self.get_random_string(length=50).encode(encoding="UTF-8")
)

assert isinstance(result, dict) is True
assert result["errorId"] != 0
Expand Down

0 comments on commit 4c34359

Please sign in to comment.