-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptcha_strategies.py
More file actions
67 lines (56 loc) · 1.91 KB
/
captcha_strategies.py
File metadata and controls
67 lines (56 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from __future__ import annotations
import inspect
from typing import Callable
from .captcha import CaptchaContext, CaptchaHandler, CaptchaResolution
def HumanHandoffSolver(
*,
message: str | None = None,
handled_by: str | None = "human",
timeout_ms: int | None = None,
poll_ms: int | None = None,
) -> CaptchaHandler:
async def _handler(_ctx: CaptchaContext) -> CaptchaResolution:
return CaptchaResolution(
action="wait_until_cleared",
message=message or "Solve CAPTCHA in the live session, then resume.",
handled_by=handled_by,
timeout_ms=timeout_ms,
poll_ms=poll_ms,
)
return _handler
def VisionSolver(
*,
message: str | None = None,
handled_by: str | None = "customer_system",
timeout_ms: int | None = None,
poll_ms: int | None = None,
) -> CaptchaHandler:
async def _handler(_ctx: CaptchaContext) -> CaptchaResolution:
return CaptchaResolution(
action="wait_until_cleared",
message=message or "Waiting for CAPTCHA to clear (vision verification).",
handled_by=handled_by,
timeout_ms=timeout_ms,
poll_ms=poll_ms,
)
return _handler
def ExternalSolver(
resolver: Callable[[CaptchaContext], None | bool | dict],
*,
message: str | None = None,
handled_by: str | None = "customer_system",
timeout_ms: int | None = None,
poll_ms: int | None = None,
) -> CaptchaHandler:
async def _handler(ctx: CaptchaContext) -> CaptchaResolution:
result = resolver(ctx)
if inspect.isawaitable(result):
await result
return CaptchaResolution(
action="wait_until_cleared",
message=message or "External solver invoked; waiting for clearance.",
handled_by=handled_by,
timeout_ms=timeout_ms,
poll_ms=poll_ms,
)
return _handler