diff --git a/docs/conf.py b/docs/conf.py index aa8a3722..aab6223a 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -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 --------------------------------------------------- @@ -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)} diff --git a/pyproject.toml b/pyproject.toml index 75fd0d34..e2d23fdc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [tool.black] -line-length = 120 +line-length = 110 target-version = ['py311'] exclude = ''' /( @@ -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] diff --git a/src/python_rucaptcha/amazon_waf.py b/src/python_rucaptcha/amazon_waf.py index 1b35957c..eddc6623 100644 --- a/src/python_rucaptcha/amazon_waf.py +++ b/src/python_rucaptcha/amazon_waf.py @@ -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( { diff --git a/src/python_rucaptcha/atb_captcha.py b/src/python_rucaptcha/atb_captcha.py index 10355108..d3efd0a6 100644 --- a/src/python_rucaptcha/atb_captcha.py +++ b/src/python_rucaptcha/atb_captcha.py @@ -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(): diff --git a/src/python_rucaptcha/capy_puzzle.py b/src/python_rucaptcha/capy_puzzle.py index 75a9dfc7..e1de1e82 100644 --- a/src/python_rucaptcha/capy_puzzle.py +++ b/src/python_rucaptcha/capy_puzzle.py @@ -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: """ diff --git a/src/python_rucaptcha/core/base.py b/src/python_rucaptcha/core/base.py index b312a8a1..44f32be5 100644 --- a/src/python_rucaptcha/core/base.py +++ b/src/python_rucaptcha/core/base.py @@ -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 @@ -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): @@ -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: @@ -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: diff --git a/src/python_rucaptcha/core/result_handler.py b/src/python_rucaptcha/core/result_handler.py index 936c1e70..f7114291 100644 --- a/src/python_rucaptcha/core/result_handler.py +++ b/src/python_rucaptcha/core/result_handler.py @@ -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 """ @@ -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) diff --git a/src/python_rucaptcha/cutcaptcha.py b/src/python_rucaptcha/cutcaptcha.py index 7f1e3a7f..070cb9d4 100644 --- a/src/python_rucaptcha/cutcaptcha.py +++ b/src/python_rucaptcha/cutcaptcha.py @@ -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: """ diff --git a/src/python_rucaptcha/fun_captcha.py b/src/python_rucaptcha/fun_captcha.py index 5e36e893..354a4bbb 100644 --- a/src/python_rucaptcha/fun_captcha.py +++ b/src/python_rucaptcha/fun_captcha.py @@ -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(): diff --git a/src/python_rucaptcha/hcaptcha.py b/src/python_rucaptcha/hcaptcha.py index 22dcbfc2..25aadb8c 100644 --- a/src/python_rucaptcha/hcaptcha.py +++ b/src/python_rucaptcha/hcaptcha.py @@ -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: """ diff --git a/src/python_rucaptcha/key_captcha.py b/src/python_rucaptcha/key_captcha.py index f4c609a7..28a31d1d 100644 --- a/src/python_rucaptcha/key_captcha.py +++ b/src/python_rucaptcha/key_captcha.py @@ -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: """ diff --git a/src/python_rucaptcha/lemin_captcha.py b/src/python_rucaptcha/lemin_captcha.py index bd133246..d5e6121b 100644 --- a/src/python_rucaptcha/lemin_captcha.py +++ b/src/python_rucaptcha/lemin_captcha.py @@ -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: """ diff --git a/src/python_rucaptcha/mt_captcha.py b/src/python_rucaptcha/mt_captcha.py index ed208ed2..25b6a43f 100644 --- a/src/python_rucaptcha/mt_captcha.py +++ b/src/python_rucaptcha/mt_captcha.py @@ -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: """ diff --git a/src/python_rucaptcha/re_captcha.py b/src/python_rucaptcha/re_captcha.py index 0204974c..2ecfbada 100644 --- a/src/python_rucaptcha/re_captcha.py +++ b/src/python_rucaptcha/re_captcha.py @@ -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: """ diff --git a/src/python_rucaptcha/tencent.py b/src/python_rucaptcha/tencent.py index 3cadc275..1b92c507 100644 --- a/src/python_rucaptcha/tencent.py +++ b/src/python_rucaptcha/tencent.py @@ -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: """ diff --git a/src/python_rucaptcha/turnstile.py b/src/python_rucaptcha/turnstile.py index cbf62888..a1aa3786 100644 --- a/src/python_rucaptcha/turnstile.py +++ b/src/python_rucaptcha/turnstile.py @@ -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: """ diff --git a/tests/test_audio.py b/tests/test_audio.py index a63018fb..d1fae5f6 100644 --- a/tests/test_audio.py +++ b/tests/test_audio.py @@ -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) diff --git a/tests/test_bounding_box.py b/tests/test_bounding_box.py index 07a05a5a..66015a5d 100644 --- a/tests/test_bounding_box.py +++ b/tests/test_bounding_box.py @@ -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 diff --git a/tests/test_coordinates.py b/tests/test_coordinates.py index 3114bf40..65b44ecf 100644 --- a/tests/test_coordinates.py +++ b/tests/test_coordinates.py @@ -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 diff --git a/tests/test_draw_around.py b/tests/test_draw_around.py index 3098b414..925e2a7c 100644 --- a/tests/test_draw_around.py +++ b/tests/test_draw_around.py @@ -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 diff --git a/tests/test_funcaptcha.py b/tests/test_funcaptcha.py index dcab4039..290dede2 100644 --- a/tests/test_funcaptcha.py +++ b/tests/test_funcaptcha.py @@ -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", diff --git a/tests/test_geetest.py b/tests/test_geetest.py index 26394ecd..5c690c68 100644 --- a/tests/test_geetest.py +++ b/tests/test_geetest.py @@ -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): diff --git a/tests/test_grid.py b/tests/test_grid.py index 27feb6cb..1b8b5d66 100644 --- a/tests/test_grid.py +++ b/tests/test_grid.py @@ -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 diff --git a/tests/test_image.py b/tests/test_image.py index 2e0b91f2..54691550 100644 --- a/tests/test_image.py +++ b/tests/test_image.py @@ -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 diff --git a/tests/test_mtcaptcha.py b/tests/test_mtcaptcha.py index 0650205a..8566fced 100644 --- a/tests/test_mtcaptcha.py +++ b/tests/test_mtcaptcha.py @@ -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 diff --git a/tests/test_rotate.py b/tests/test_rotate.py index 2eb4107a..5d57ffa6 100644 --- a/tests/test_rotate.py +++ b/tests/test_rotate.py @@ -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) @@ -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