js-captcha 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- js_captcha/__init__.py +9 -0
- js_captcha/_protocol.py +155 -0
- js_captcha/_version.py +1 -0
- js_captcha/client.py +340 -0
- js_captcha/cloudflare.py +20 -0
- js_captcha/errors.py +42 -0
- js_captcha/models.py +33 -0
- js_captcha/py.typed +0 -0
- js_captcha-1.0.0.dist-info/METADATA +116 -0
- js_captcha-1.0.0.dist-info/RECORD +14 -0
- js_captcha-1.0.0.dist-info/WHEEL +5 -0
- js_captcha-1.0.0.dist-info/licenses/LICENSE +202 -0
- js_captcha-1.0.0.dist-info/licenses/NOTICE +5 -0
- js_captcha-1.0.0.dist-info/top_level.txt +1 -0
js_captcha/__init__.py
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"""Customer SDK for jsCaptchaSolver's synchronous V2 Gateway."""
|
|
2
|
+
from ._version import __version__
|
|
3
|
+
from .cloudflare import compact_cloudflare_html
|
|
4
|
+
from .client import DEFAULT_BASE_URL, AsyncJsCaptchaSolver, JsCaptchaSolver
|
|
5
|
+
from .errors import APIError, ProductError, ProtocolError, SolverError, TransportError, ValidationError
|
|
6
|
+
from .models import Balance, SolveResponse
|
|
7
|
+
|
|
8
|
+
__all__ = ["compact_cloudflare_html", "DEFAULT_BASE_URL", "__version__", "JsCaptchaSolver", "AsyncJsCaptchaSolver", "SolveResponse", "Balance", "APIError",
|
|
9
|
+
"ProductError", "ProtocolError", "TransportError", "ValidationError", "SolverError"]
|
js_captcha/_protocol.py
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import ipaddress
|
|
2
|
+
import json
|
|
3
|
+
import re
|
|
4
|
+
from collections.abc import Mapping
|
|
5
|
+
from urllib.parse import urlsplit, urlunsplit
|
|
6
|
+
from uuid import UUID, uuid4
|
|
7
|
+
from typing import Any
|
|
8
|
+
from .errors import APIError, ProductError, ProtocolError, ValidationError
|
|
9
|
+
from .models import Balance, SolveResponse
|
|
10
|
+
from .cloudflare import compact_cloudflare_html
|
|
11
|
+
|
|
12
|
+
MAX_REQUEST_BYTES = 1024 * 1024
|
|
13
|
+
MAX_INCAPSULA_REQUEST_BYTES = 8 * 1024 * 1024
|
|
14
|
+
MAX_RESPONSE_BYTES = 2 * 1024 * 1024
|
|
15
|
+
_IDENTIFIER = re.compile(r"[A-Za-z0-9_-]{1,64}\Z")
|
|
16
|
+
_ACTION = re.compile(r"[A-Za-z0-9_:-]{1,64}\Z")
|
|
17
|
+
_CODE = re.compile(r"[A-Z][A-Z0-9_]{1,63}\Z")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def base_url(value: str) -> str:
|
|
21
|
+
try:
|
|
22
|
+
if not isinstance(value, str) or not value or '?' in value or '#' in value or any(ord(c) <= 32 or ord(c) == 127 for c in value):
|
|
23
|
+
raise ValueError()
|
|
24
|
+
parts = urlsplit(value)
|
|
25
|
+
if parts.scheme not in ("http", "https") or not parts.hostname or parts.username is not None or parts.password is not None or parts.query or parts.fragment:
|
|
26
|
+
raise ValueError()
|
|
27
|
+
if parts.port is not None and not 1 <= parts.port <= 65535:
|
|
28
|
+
raise ValueError()
|
|
29
|
+
if parts.scheme == "http" and parts.hostname.lower() != "localhost":
|
|
30
|
+
if not ipaddress.ip_address(parts.hostname).is_loopback:
|
|
31
|
+
raise ValueError()
|
|
32
|
+
return urlunsplit((parts.scheme, parts.netloc, parts.path.rstrip("/") + "/", "", ""))
|
|
33
|
+
except (ValueError, TypeError):
|
|
34
|
+
raise ValidationError("Use an absolute HTTPS base URL, or loopback HTTP, without credentials/query/fragment") from None
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def header_value(value: str, name: str, maximum: int = 512) -> str:
|
|
38
|
+
if not isinstance(value, str) or not value or len(value) > maximum or any(ord(c) < 33 or ord(c) > 126 for c in value):
|
|
39
|
+
raise ValidationError(f"Invalid {name}")
|
|
40
|
+
return value
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def timeout_ms(value: int) -> int:
|
|
44
|
+
if type(value) is not int or not 1 <= value <= 120000:
|
|
45
|
+
raise ValidationError("timeout_ms must be an integer from 1 to 120000")
|
|
46
|
+
return value
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def request_id(value: str | UUID | None) -> str:
|
|
50
|
+
try:
|
|
51
|
+
return str(uuid4() if value is None else UUID(str(value)))
|
|
52
|
+
except (ValueError, TypeError, AttributeError):
|
|
53
|
+
raise ValidationError("request_id must be a UUID") from None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def route(product: str, action: str) -> str:
|
|
57
|
+
if not isinstance(product, str) or not _IDENTIFIER.fullmatch(product) or not isinstance(action, str) or not _ACTION.fullmatch(action):
|
|
58
|
+
raise ValidationError("product/action must be 1–64 letters, digits, underscores or hyphens; actions also allow colons")
|
|
59
|
+
if product not in ("cloudflare", "kasada", "incapsula"):
|
|
60
|
+
raise ValidationError("SDK 1.0.0 supports cloudflare, kasada and incapsula")
|
|
61
|
+
return f"v1/{product}/{action}"
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def payload_bytes(payload: Mapping[str, Any], product: str | None = None, action: str | None = None) -> bytes:
|
|
65
|
+
maximum = MAX_INCAPSULA_REQUEST_BYTES if product == "incapsula" else MAX_REQUEST_BYTES
|
|
66
|
+
try:
|
|
67
|
+
if not isinstance(payload, Mapping) or any(not isinstance(k, str) for k in payload):
|
|
68
|
+
raise ValueError()
|
|
69
|
+
prepared = dict(payload)
|
|
70
|
+
if product == "cloudflare" and action in ("challenge", "challenge_fast") and isinstance(prepared.get("html"), str):
|
|
71
|
+
prepared["html"] = compact_cloudflare_html(prepared["html"])
|
|
72
|
+
body = json.dumps(prepared, ensure_ascii=False, allow_nan=False, separators=(",", ":")).encode("utf-8")
|
|
73
|
+
if len(body) > maximum:
|
|
74
|
+
raise ValueError()
|
|
75
|
+
return body
|
|
76
|
+
except (ValueError, TypeError, RecursionError, OverflowError):
|
|
77
|
+
raise ValidationError(f"payload must be a finite JSON object no larger than {maximum // (1024 * 1024)} MiB") from None
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def decode(raw: bytes, status: int, sent_id: str, *, correlate: bool,
|
|
81
|
+
product: str | None = None) -> SolveResponse:
|
|
82
|
+
def invalid() -> ProtocolError:
|
|
83
|
+
return ProtocolError("Invalid gateway response envelope", request_id=sent_id, http_status=status)
|
|
84
|
+
try:
|
|
85
|
+
if len(raw) > MAX_RESPONSE_BYTES or 300 <= status < 400:
|
|
86
|
+
raise ValueError()
|
|
87
|
+
data = json.loads(raw, parse_constant=lambda _: (_ for _ in ()).throw(ValueError()))
|
|
88
|
+
if not isinstance(data, dict) or any(not isinstance(data.get(k), str) for k in ("code", "message_key", "message", "request_id", "trace_id")):
|
|
89
|
+
raise ValueError()
|
|
90
|
+
if not _CODE.fullmatch(data["code"]) or not data["trace_id"] or type(data.get("cost_time")) is not int or not 0 <= data["cost_time"] <= 2**63 - 1:
|
|
91
|
+
raise ValueError()
|
|
92
|
+
received_id = str(UUID(data["request_id"]))
|
|
93
|
+
if correlate and received_id != sent_id:
|
|
94
|
+
raise ValueError()
|
|
95
|
+
success = data["code"] == "OK"
|
|
96
|
+
if success != ("result" in data) or success and not 200 <= status < 300:
|
|
97
|
+
raise ValueError()
|
|
98
|
+
public_error = None
|
|
99
|
+
if "product_error" in data:
|
|
100
|
+
pe = data["product_error"]
|
|
101
|
+
if data["code"] in ("OK", "CANCELLED", "DEADLINE_EXCEEDED") or not isinstance(pe, dict) or any(not isinstance(pe.get(k), str) for k in ("product", "code", "message_key", "message")):
|
|
102
|
+
raise ValueError()
|
|
103
|
+
if not _CODE.fullmatch(pe["code"]) or product is not None and pe["product"] != product:
|
|
104
|
+
raise ValueError()
|
|
105
|
+
public_error = ProductError(**{k: pe[k] for k in ("product", "code", "message_key", "message")})
|
|
106
|
+
if not success:
|
|
107
|
+
raise APIError(code=data["code"], message_key=data["message_key"], message=data["message"],
|
|
108
|
+
request_id=received_id, trace_id=data["trace_id"], cost_time=data["cost_time"],
|
|
109
|
+
http_status=status, product_error=public_error)
|
|
110
|
+
return SolveResponse(code=data["code"], message_key=data["message_key"], message=data["message"],
|
|
111
|
+
request_id=received_id, trace_id=data["trace_id"], cost_time=data["cost_time"],
|
|
112
|
+
result=data["result"], http_status=status)
|
|
113
|
+
except APIError:
|
|
114
|
+
raise
|
|
115
|
+
except (ValueError, TypeError, KeyError, UnicodeError, RecursionError):
|
|
116
|
+
raise invalid() from None
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def balance_response(response: SolveResponse) -> Balance:
|
|
120
|
+
try:
|
|
121
|
+
value = response.result
|
|
122
|
+
if not isinstance(value, dict) or value.get("asset") != "USDT" or type(value.get("decimals")) is not int or value["decimals"] != 6:
|
|
123
|
+
raise ValueError()
|
|
124
|
+
amounts = []
|
|
125
|
+
for field in ("balance", "reserved", "available"):
|
|
126
|
+
s = value.get(field)
|
|
127
|
+
if not isinstance(s, str) or not re.fullmatch(r"[0-9]{1,19}", s) or int(s) > 2**63 - 1:
|
|
128
|
+
raise ValueError()
|
|
129
|
+
amounts.append(int(s))
|
|
130
|
+
if amounts[0] - amounts[1] != amounts[2]:
|
|
131
|
+
raise ValueError()
|
|
132
|
+
return Balance(**{k: value[k] for k in ("asset", "decimals", "balance", "reserved", "available")})
|
|
133
|
+
except (TypeError, ValueError, KeyError):
|
|
134
|
+
raise ProtocolError("Invalid balance result", request_id=response.request_id,
|
|
135
|
+
http_status=response.http_status) from None
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def accounting_response(response: SolveResponse, expected_id: str) -> None:
|
|
139
|
+
value = response.result
|
|
140
|
+
try:
|
|
141
|
+
if not isinstance(value, dict) or value.get("request_id") != expected_id:
|
|
142
|
+
raise ValueError
|
|
143
|
+
if value.get("state") not in ("reserved", "succeeded", "failed", "cancelled") or value.get("settlement") not in ("pending", "compensation_pending", "settled"):
|
|
144
|
+
raise ValueError
|
|
145
|
+
for field in ("charged_amount", "refunded_amount", "net_amount", "charged_units", "refunded_units", "net_units"):
|
|
146
|
+
number = value.get(field)
|
|
147
|
+
if not isinstance(number, str) or not number.isascii() or not number.isdigit() or int(number) > 9223372036854775807:
|
|
148
|
+
raise ValueError
|
|
149
|
+
for suffix in ("amount", "units"):
|
|
150
|
+
if int(value["charged_" + suffix]) - int(value["refunded_" + suffix]) != int(value["net_" + suffix]):
|
|
151
|
+
raise ValueError
|
|
152
|
+
if type(value.get("detail_expired")) is not bool or value.get("asset") != "USDT" or value.get("decimals") != 6:
|
|
153
|
+
raise ValueError
|
|
154
|
+
except (ValueError, TypeError, KeyError):
|
|
155
|
+
raise ProtocolError("Invalid accounting result", request_id=response.request_id, http_status=response.http_status) from None
|
js_captcha/_version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "1.0.0"
|
js_captcha/client.py
ADDED
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
from datetime import timedelta
|
|
2
|
+
from typing import Any
|
|
3
|
+
from collections.abc import Mapping
|
|
4
|
+
from uuid import UUID
|
|
5
|
+
import inspect
|
|
6
|
+
import wreq
|
|
7
|
+
from . import _protocol as wire
|
|
8
|
+
from ._version import __version__
|
|
9
|
+
from .errors import ProtocolError, SolverError, TransportError, ValidationError
|
|
10
|
+
from .models import Balance, SolveResponse
|
|
11
|
+
|
|
12
|
+
DEFAULT_BASE_URL = "https://api.js-captcha.com"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _Configuration:
|
|
16
|
+
def __init__(self, *, api_key: str, base_url: str = DEFAULT_BASE_URL, timeout_ms: int = 30000,
|
|
17
|
+
locale: str | None = None) -> None:
|
|
18
|
+
self._base = wire.base_url(base_url)
|
|
19
|
+
self._key = wire.header_value(api_key, "API key", 505)
|
|
20
|
+
self._timeout = wire.timeout_ms(timeout_ms)
|
|
21
|
+
self._locale = wire.header_value(locale, "locale", 35) if locale is not None else None
|
|
22
|
+
self._closed = False
|
|
23
|
+
|
|
24
|
+
def __repr__(self) -> str:
|
|
25
|
+
return f"{type(self).__name__}(credentials=<redacted>)"
|
|
26
|
+
|
|
27
|
+
def _prepare(self, method: str, path: str, payload: Mapping[str, Any] | None,
|
|
28
|
+
timeout_ms: int | None, request_id: str | UUID | None,
|
|
29
|
+
product: str | None = None) -> tuple[str, dict[str, Any], str]:
|
|
30
|
+
if self._closed:
|
|
31
|
+
raise ValidationError("Client is closed")
|
|
32
|
+
budget = wire.timeout_ms(self._timeout if timeout_ms is None else timeout_ms)
|
|
33
|
+
rid = wire.request_id(request_id)
|
|
34
|
+
headers = {"Authorization": f"Bearer {self._key}", "Accept": "application/json",
|
|
35
|
+
"X-Request-ID": rid, "X-JsCaptchaSolver-SDK": f"python/{__version__}"}
|
|
36
|
+
if self._locale:
|
|
37
|
+
headers["X-Locale"] = self._locale
|
|
38
|
+
kwargs: dict[str, Any] = {"headers": headers, "timeout": timedelta(milliseconds=budget + 15000),
|
|
39
|
+
"redirect": wreq.redirect.Policy.none()}
|
|
40
|
+
if method == "POST":
|
|
41
|
+
headers["Content-Type"] = "application/json"
|
|
42
|
+
headers["X-Timeout-Ms"] = str(budget)
|
|
43
|
+
kwargs["body"] = wire.payload_bytes(payload, product, path.rsplit("/", 1)[-1]) # type: ignore[arg-type]
|
|
44
|
+
return self._base + path, kwargs, rid
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _wreq_options(emulation: Any, ca_certs: Any) -> dict[str, Any]:
|
|
48
|
+
return {"emulation": emulation, "no_proxy": True, "redirect": wreq.redirect.Policy.none(),
|
|
49
|
+
"tls_verify": ca_certs if ca_certs is not None else True, "raise_for_status": False,
|
|
50
|
+
"connect_timeout": timedelta(seconds=10)}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _status(response: Any) -> int:
|
|
54
|
+
return response.status.as_int() if hasattr(response.status, "as_int") else int(response.status)
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
class JsCaptchaSolver(_Configuration):
|
|
58
|
+
"""Blocking wreq client. One call submits one new Gateway request."""
|
|
59
|
+
def __init__(self, *, api_key: str, base_url: str = DEFAULT_BASE_URL, timeout_ms: int = 30000,
|
|
60
|
+
locale: str | None = None, emulation: Any = wreq.Emulation.Chrome146,
|
|
61
|
+
ca_certs: Any = None, transport: Any = None) -> None:
|
|
62
|
+
super().__init__(api_key=api_key, base_url=base_url, timeout_ms=timeout_ms, locale=locale)
|
|
63
|
+
if ca_certs is False:
|
|
64
|
+
raise ValidationError("Certificate verification must remain enabled")
|
|
65
|
+
self._owns_transport = transport is None
|
|
66
|
+
try:
|
|
67
|
+
self._transport = transport if transport is not None else wreq.blocking.Client(**_wreq_options(emulation, ca_certs))
|
|
68
|
+
except Exception:
|
|
69
|
+
raise ValidationError("Unable to configure wreq TLS transport") from None
|
|
70
|
+
|
|
71
|
+
def _call(self, method: str, path: str, payload: Mapping[str, Any] | None = None,
|
|
72
|
+
*, timeout_ms: int | None = None, request_id: str | UUID | None = None,
|
|
73
|
+
product: str | None = None) -> SolveResponse:
|
|
74
|
+
url, kwargs, rid = self._prepare(method, path, payload, timeout_ms, request_id, product)
|
|
75
|
+
try:
|
|
76
|
+
response = self._transport.request(getattr(wreq.Method, method), url, **kwargs)
|
|
77
|
+
status = _status(response)
|
|
78
|
+
with response.stream() as stream:
|
|
79
|
+
body = bytearray()
|
|
80
|
+
for chunk in stream:
|
|
81
|
+
if isinstance(chunk, bytes):
|
|
82
|
+
if len(body) + len(chunk) > wire.MAX_RESPONSE_BYTES:
|
|
83
|
+
raise ProtocolError("Gateway response exceeds 2 MiB", request_id=rid,
|
|
84
|
+
http_status=status)
|
|
85
|
+
body.extend(chunk)
|
|
86
|
+
return wire.decode(bytes(body), status, rid, correlate=method == "POST", product=product)
|
|
87
|
+
except SolverError:
|
|
88
|
+
raise
|
|
89
|
+
except Exception:
|
|
90
|
+
raise TransportError("Gateway transport failed; execution outcome may be unknown", request_id=rid) from None
|
|
91
|
+
|
|
92
|
+
def solve(self, product: str, action: str, payload: Mapping[str, Any], *,
|
|
93
|
+
timeout_ms: int | None = None, request_id: str | UUID | None = None) -> SolveResponse:
|
|
94
|
+
return self._call("POST", wire.route(product, action), payload, timeout_ms=timeout_ms,
|
|
95
|
+
request_id=request_id, product=product)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def cloudflare_challenge_fast(self, payload: Mapping[str, Any], *,
|
|
101
|
+
timeout_ms: int | None = None,
|
|
102
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
103
|
+
"""Submit cloudflare/challenge_fast; payload follows the product schema."""
|
|
104
|
+
return self.solve("cloudflare", "challenge_fast", payload,
|
|
105
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
106
|
+
|
|
107
|
+
def cloudflare_challenge(self, payload: Mapping[str, Any], *,
|
|
108
|
+
timeout_ms: int | None = None,
|
|
109
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
110
|
+
"""Submit cloudflare/challenge; payload follows the product schema."""
|
|
111
|
+
return self.solve("cloudflare", "challenge", payload,
|
|
112
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
113
|
+
|
|
114
|
+
def cloudflare_passive(self, payload: Mapping[str, Any], *,
|
|
115
|
+
timeout_ms: int | None = None,
|
|
116
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
117
|
+
"""Submit cloudflare/passive; payload follows the product schema."""
|
|
118
|
+
return self.solve("cloudflare", "passive", payload,
|
|
119
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
120
|
+
|
|
121
|
+
def cloudflare_turnstile_proxyless(self, payload: Mapping[str, Any], *,
|
|
122
|
+
timeout_ms: int | None = None,
|
|
123
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
124
|
+
"""Submit cloudflare/turnstile_proxyless; payload follows the product schema."""
|
|
125
|
+
return self.solve("cloudflare", "turnstile_proxyless", payload,
|
|
126
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
127
|
+
|
|
128
|
+
def cloudflare_turnstile(self, payload: Mapping[str, Any], *,
|
|
129
|
+
timeout_ms: int | None = None,
|
|
130
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
131
|
+
"""Submit cloudflare/turnstile; payload follows the product schema."""
|
|
132
|
+
return self.solve("cloudflare", "turnstile", payload,
|
|
133
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def incapsula_execute(self, payload: Mapping[str, Any], *,
|
|
138
|
+
timeout_ms: int | None = None,
|
|
139
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
140
|
+
"""Submit incapsula/execute; payload follows the product schema."""
|
|
141
|
+
return self.solve("incapsula", "execute", payload,
|
|
142
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def kasada_tl(self, payload: Mapping[str, Any], *,
|
|
150
|
+
timeout_ms: int | None = None,
|
|
151
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
152
|
+
"""Submit kasada/tl; payload follows the product schema."""
|
|
153
|
+
return self.solve("kasada", "tl", payload,
|
|
154
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
155
|
+
|
|
156
|
+
def kasada_cd(self, payload: Mapping[str, Any], *,
|
|
157
|
+
timeout_ms: int | None = None,
|
|
158
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
159
|
+
"""Submit kasada/cd; payload follows the product schema."""
|
|
160
|
+
return self.solve("kasada", "cd", payload,
|
|
161
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
162
|
+
|
|
163
|
+
def kasada_payload(self, payload: Mapping[str, Any], *,
|
|
164
|
+
timeout_ms: int | None = None,
|
|
165
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
166
|
+
"""Submit kasada/payload; payload follows the product schema."""
|
|
167
|
+
return self.solve("kasada", "payload", payload,
|
|
168
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def accounting(self, request_id: str | UUID) -> SolveResponse:
|
|
175
|
+
"""Read authoritative charges after a lost response; does not rerun a solve."""
|
|
176
|
+
if request_id is None:
|
|
177
|
+
raise ValidationError("request_id is required")
|
|
178
|
+
rid = wire.request_id(request_id)
|
|
179
|
+
response = self._call("GET", f"v1/requests/{rid}/accounting", timeout_ms=5000)
|
|
180
|
+
wire.accounting_response(response, rid)
|
|
181
|
+
return response
|
|
182
|
+
|
|
183
|
+
def balance(self) -> tuple[SolveResponse, Balance]:
|
|
184
|
+
response = self._call("GET", "v1/balance", timeout_ms=5000)
|
|
185
|
+
return response, wire.balance_response(response)
|
|
186
|
+
|
|
187
|
+
def close(self) -> None:
|
|
188
|
+
if not self._closed and self._owns_transport:
|
|
189
|
+
self._transport.close()
|
|
190
|
+
self._closed = True
|
|
191
|
+
|
|
192
|
+
def __enter__(self) -> "JsCaptchaSolver":
|
|
193
|
+
return self
|
|
194
|
+
|
|
195
|
+
def __exit__(self, *_: Any) -> None:
|
|
196
|
+
self.close()
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
class AsyncJsCaptchaSolver(_Configuration):
|
|
200
|
+
"""Async wreq client; task cancellation propagates to the HTTP request."""
|
|
201
|
+
def __init__(self, *, api_key: str, base_url: str = DEFAULT_BASE_URL, timeout_ms: int = 30000,
|
|
202
|
+
locale: str | None = None, emulation: Any = wreq.Emulation.Chrome146,
|
|
203
|
+
ca_certs: Any = None, transport: Any = None) -> None:
|
|
204
|
+
super().__init__(api_key=api_key, base_url=base_url, timeout_ms=timeout_ms, locale=locale)
|
|
205
|
+
if ca_certs is False:
|
|
206
|
+
raise ValidationError("Certificate verification must remain enabled")
|
|
207
|
+
self._owns_transport = transport is None
|
|
208
|
+
try:
|
|
209
|
+
self._transport = transport if transport is not None else wreq.Client(**_wreq_options(emulation, ca_certs))
|
|
210
|
+
except Exception:
|
|
211
|
+
raise ValidationError("Unable to configure wreq TLS transport") from None
|
|
212
|
+
|
|
213
|
+
async def _call(self, method: str, path: str, payload: Mapping[str, Any] | None = None,
|
|
214
|
+
*, timeout_ms: int | None = None, request_id: str | UUID | None = None,
|
|
215
|
+
product: str | None = None) -> SolveResponse:
|
|
216
|
+
url, kwargs, rid = self._prepare(method, path, payload, timeout_ms, request_id, product)
|
|
217
|
+
try:
|
|
218
|
+
response = await self._transport.request(getattr(wreq.Method, method), url, **kwargs)
|
|
219
|
+
status = _status(response)
|
|
220
|
+
async with response.stream() as stream:
|
|
221
|
+
body = bytearray()
|
|
222
|
+
async for chunk in stream:
|
|
223
|
+
if isinstance(chunk, bytes):
|
|
224
|
+
if len(body) + len(chunk) > wire.MAX_RESPONSE_BYTES:
|
|
225
|
+
raise ProtocolError("Gateway response exceeds 2 MiB", request_id=rid,
|
|
226
|
+
http_status=status)
|
|
227
|
+
body.extend(chunk)
|
|
228
|
+
return wire.decode(bytes(body), status, rid, correlate=method == "POST", product=product)
|
|
229
|
+
except SolverError:
|
|
230
|
+
raise
|
|
231
|
+
except Exception:
|
|
232
|
+
raise TransportError("Gateway transport failed; execution outcome may be unknown", request_id=rid) from None
|
|
233
|
+
|
|
234
|
+
async def solve(self, product: str, action: str, payload: Mapping[str, Any], *,
|
|
235
|
+
timeout_ms: int | None = None, request_id: str | UUID | None = None) -> SolveResponse:
|
|
236
|
+
return await self._call("POST", wire.route(product, action), payload, timeout_ms=timeout_ms,
|
|
237
|
+
request_id=request_id, product=product)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+
async def cloudflare_challenge_fast(self, payload: Mapping[str, Any], *,
|
|
243
|
+
timeout_ms: int | None = None,
|
|
244
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
245
|
+
"""Submit cloudflare/challenge_fast; payload follows the product schema."""
|
|
246
|
+
return await self.solve("cloudflare", "challenge_fast", payload,
|
|
247
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
248
|
+
|
|
249
|
+
async def cloudflare_challenge(self, payload: Mapping[str, Any], *,
|
|
250
|
+
timeout_ms: int | None = None,
|
|
251
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
252
|
+
"""Submit cloudflare/challenge; payload follows the product schema."""
|
|
253
|
+
return await self.solve("cloudflare", "challenge", payload,
|
|
254
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
255
|
+
|
|
256
|
+
async def cloudflare_passive(self, payload: Mapping[str, Any], *,
|
|
257
|
+
timeout_ms: int | None = None,
|
|
258
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
259
|
+
"""Submit cloudflare/passive; payload follows the product schema."""
|
|
260
|
+
return await self.solve("cloudflare", "passive", payload,
|
|
261
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
262
|
+
|
|
263
|
+
async def cloudflare_turnstile_proxyless(self, payload: Mapping[str, Any], *,
|
|
264
|
+
timeout_ms: int | None = None,
|
|
265
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
266
|
+
"""Submit cloudflare/turnstile_proxyless; payload follows the product schema."""
|
|
267
|
+
return await self.solve("cloudflare", "turnstile_proxyless", payload,
|
|
268
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
269
|
+
|
|
270
|
+
async def cloudflare_turnstile(self, payload: Mapping[str, Any], *,
|
|
271
|
+
timeout_ms: int | None = None,
|
|
272
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
273
|
+
"""Submit cloudflare/turnstile; payload follows the product schema."""
|
|
274
|
+
return await self.solve("cloudflare", "turnstile", payload,
|
|
275
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
async def incapsula_execute(self, payload: Mapping[str, Any], *,
|
|
280
|
+
timeout_ms: int | None = None,
|
|
281
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
282
|
+
"""Submit incapsula/execute; payload follows the product schema."""
|
|
283
|
+
return await self.solve("incapsula", "execute", payload,
|
|
284
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
async def kasada_tl(self, payload: Mapping[str, Any], *,
|
|
292
|
+
timeout_ms: int | None = None,
|
|
293
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
294
|
+
"""Submit kasada/tl; payload follows the product schema."""
|
|
295
|
+
return await self.solve("kasada", "tl", payload,
|
|
296
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
297
|
+
|
|
298
|
+
async def kasada_cd(self, payload: Mapping[str, Any], *,
|
|
299
|
+
timeout_ms: int | None = None,
|
|
300
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
301
|
+
"""Submit kasada/cd; payload follows the product schema."""
|
|
302
|
+
return await self.solve("kasada", "cd", payload,
|
|
303
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
304
|
+
|
|
305
|
+
async def kasada_payload(self, payload: Mapping[str, Any], *,
|
|
306
|
+
timeout_ms: int | None = None,
|
|
307
|
+
request_id: str | UUID | None = None) -> SolveResponse:
|
|
308
|
+
"""Submit kasada/payload; payload follows the product schema."""
|
|
309
|
+
return await self.solve("kasada", "payload", payload,
|
|
310
|
+
timeout_ms=timeout_ms, request_id=request_id)
|
|
311
|
+
|
|
312
|
+
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
async def accounting(self, request_id: str | UUID) -> SolveResponse:
|
|
317
|
+
"""Read authoritative charges after a lost response; does not rerun a solve."""
|
|
318
|
+
if request_id is None:
|
|
319
|
+
raise ValidationError("request_id is required")
|
|
320
|
+
rid = wire.request_id(request_id)
|
|
321
|
+
response = await self._call("GET", f"v1/requests/{rid}/accounting", timeout_ms=5000)
|
|
322
|
+
wire.accounting_response(response, rid)
|
|
323
|
+
return response
|
|
324
|
+
|
|
325
|
+
async def balance(self) -> tuple[SolveResponse, Balance]:
|
|
326
|
+
response = await self._call("GET", "v1/balance", timeout_ms=5000)
|
|
327
|
+
return response, wire.balance_response(response)
|
|
328
|
+
|
|
329
|
+
async def close(self) -> None:
|
|
330
|
+
if not self._closed and self._owns_transport:
|
|
331
|
+
closing = self._transport.close()
|
|
332
|
+
if inspect.isawaitable(closing):
|
|
333
|
+
await closing
|
|
334
|
+
self._closed = True
|
|
335
|
+
|
|
336
|
+
async def __aenter__(self) -> "AsyncJsCaptchaSolver":
|
|
337
|
+
return self
|
|
338
|
+
|
|
339
|
+
async def __aexit__(self, *_: Any) -> None:
|
|
340
|
+
await self.close()
|
js_captcha/cloudflare.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"""Pure preparation of Cloudflare challenge HTML; no network or JS execution."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def compact_cloudflare_html(html: str) -> str:
|
|
5
|
+
"""Keep the first complete Cloudflare configuration block.
|
|
6
|
+
|
|
7
|
+
Preserve the complete selected block byte-for-byte (including unknown fields).
|
|
8
|
+
Missing markers return the original input without changing the caller's
|
|
9
|
+
request into an empty HTML value.
|
|
10
|
+
"""
|
|
11
|
+
if not isinstance(html, str):
|
|
12
|
+
raise TypeError("html must be a string")
|
|
13
|
+
marker = "window._cf_chl_opt = {"
|
|
14
|
+
start = html.find(marker)
|
|
15
|
+
if start < 0:
|
|
16
|
+
return html
|
|
17
|
+
end = html.find("};", start + len(marker))
|
|
18
|
+
if end < 0:
|
|
19
|
+
return html
|
|
20
|
+
return html[start:end + 2]
|
js_captcha/errors.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""Errors deliberately exclude credentials, request bodies and raw responses."""
|
|
2
|
+
from dataclasses import dataclass, field
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
@dataclass(frozen=True)
|
|
6
|
+
class ProductError:
|
|
7
|
+
product: str
|
|
8
|
+
code: str
|
|
9
|
+
message_key: str
|
|
10
|
+
message: str = field(repr=False)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class SolverError(Exception):
|
|
14
|
+
def __init__(self, description: str, *, request_id: str | None = None,
|
|
15
|
+
http_status: int | None = None) -> None:
|
|
16
|
+
self.request_id = request_id
|
|
17
|
+
self.http_status = http_status
|
|
18
|
+
suffix = f" (request_id={request_id}, http_status={http_status})" if request_id else ""
|
|
19
|
+
super().__init__(description + suffix)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ValidationError(SolverError):
|
|
23
|
+
"""No gateway request was dispatched."""
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class TransportError(SolverError):
|
|
27
|
+
"""An execute outcome can be unknown; do not automatically replay it."""
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class ProtocolError(SolverError):
|
|
31
|
+
"""The response could not be safely correlated or decoded."""
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class APIError(SolverError):
|
|
35
|
+
def __init__(self, *, code: str, message_key: str, message: str,
|
|
36
|
+
request_id: str, trace_id: str, cost_time: int, http_status: int,
|
|
37
|
+
product_error: ProductError | None = None) -> None:
|
|
38
|
+
self.code, self.message_key, self.message = code, message_key, message
|
|
39
|
+
self.trace_id, self.cost_time, self.product_error = trace_id, cost_time, product_error
|
|
40
|
+
product_code = f", product_code={product_error.code}" if product_error else ""
|
|
41
|
+
super().__init__(f"Gateway error {code}{product_code}", request_id=request_id,
|
|
42
|
+
http_status=http_status)
|
js_captcha/models.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
from dataclasses import dataclass, field
|
|
2
|
+
from decimal import Decimal
|
|
3
|
+
from typing import Any
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
@dataclass(frozen=True)
|
|
7
|
+
class SolveResponse:
|
|
8
|
+
code: str
|
|
9
|
+
message_key: str
|
|
10
|
+
message: str = field(repr=False)
|
|
11
|
+
request_id: str
|
|
12
|
+
trace_id: str
|
|
13
|
+
cost_time: int
|
|
14
|
+
result: Any = field(repr=False)
|
|
15
|
+
http_status: int
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@dataclass(frozen=True)
|
|
19
|
+
class Balance:
|
|
20
|
+
"""USDT values stay integer micro-unit strings, never binary floats."""
|
|
21
|
+
asset: str
|
|
22
|
+
decimals: int
|
|
23
|
+
balance: str
|
|
24
|
+
reserved: str
|
|
25
|
+
available: str
|
|
26
|
+
|
|
27
|
+
@property
|
|
28
|
+
def balance_usdt(self) -> Decimal:
|
|
29
|
+
return Decimal((0, tuple(int(c) for c in self.balance), -self.decimals))
|
|
30
|
+
|
|
31
|
+
@property
|
|
32
|
+
def available_usdt(self) -> Decimal:
|
|
33
|
+
return Decimal((0, tuple(int(c) for c in self.available), -self.decimals))
|
js_captcha/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: js-captcha
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Official Python SDK for the Js-Captcha API with blocking and async clients
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
Project-URL: Homepage, https://www.js-captcha.com
|
|
7
|
+
Project-URL: Repository, https://github.com/js-captcha/js-captcha-sdk
|
|
8
|
+
Project-URL: Documentation, https://www.js-captcha.com
|
|
9
|
+
Project-URL: Issues, https://github.com/js-captcha/js-captcha-sdk/issues
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Typing :: Typed
|
|
12
|
+
Requires-Python: >=3.11
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
License-File: NOTICE
|
|
16
|
+
Requires-Dist: wreq<0.13,>=0.12.2
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# js-captcha Python SDK
|
|
20
|
+
|
|
21
|
+
Python ≥3.11,依赖 `wreq>=0.12.2,<0.13`,包含同步 `JsCaptchaSolver` 与异步 `AsyncJsCaptchaSolver`,通过公开 HTTPS API 调用服务。
|
|
22
|
+
|
|
23
|
+
```sh
|
|
24
|
+
python -m pip install js-captcha==1.0.0
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import os
|
|
29
|
+
import wreq
|
|
30
|
+
from js_captcha import JsCaptchaSolver, APIError, TransportError
|
|
31
|
+
|
|
32
|
+
with JsCaptchaSolver(
|
|
33
|
+
api_key=os.environ["JSCAPTCHA_API_KEY"],
|
|
34
|
+
locale="zh",
|
|
35
|
+
emulation=wreq.Emulation.Chrome146,
|
|
36
|
+
) as solver:
|
|
37
|
+
response = solver.cloudflare_challenge({
|
|
38
|
+
"url": os.environ["TARGET_URL"],
|
|
39
|
+
"user_agent": os.environ["TARGET_USER_AGENT"],
|
|
40
|
+
"proxy": os.environ["TARGET_PROXY"],
|
|
41
|
+
"html": "<html>这里传授权目标页面的原文 HTML</html>",
|
|
42
|
+
})
|
|
43
|
+
# response.result 原样保留,attributes / cf_clearance 可能按实际流程出现。
|
|
44
|
+
attributes = response.result.get("attributes")
|
|
45
|
+
print(response.request_id, response.cost_time) # 不打印敏感结果
|
|
46
|
+
metadata, wallet = solver.balance()
|
|
47
|
+
balance_usdt = wallet.balance_usdt # Decimal,保持六位微单位精度
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
异步版本:
|
|
51
|
+
|
|
52
|
+
```python
|
|
53
|
+
import asyncio, os
|
|
54
|
+
from js_captcha import AsyncJsCaptchaSolver
|
|
55
|
+
|
|
56
|
+
async def main():
|
|
57
|
+
async with AsyncJsCaptchaSolver(
|
|
58
|
+
api_key=os.environ["JSCAPTCHA_API_KEY"],
|
|
59
|
+
) as solver:
|
|
60
|
+
metadata, wallet = await solver.balance()
|
|
61
|
+
print(metadata.request_id, wallet.available_usdt)
|
|
62
|
+
|
|
63
|
+
asyncio.run(main())
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`solve(..., timeout_ms=30000, request_id="UUID")` 可按调用覆盖。`balance()` 返回 `(原始 SolveResponse, 精确 Balance)`;原始结果和未来新增字段仍在 response.result。Async task cancellation 原样抛 asyncio.CancelledError;需要取消后追踪时先生成 UUID 再传入。
|
|
67
|
+
|
|
68
|
+
`APIError` 包含 code/message_key/message/request_id/trace_id/cost_time/http_status/product_error;公开 message 可供界面选择展示,但默认异常文本只显示稳定元数据。`TransportError`/`ProtocolError` 不自动重放,可能需要核对最终结果;`ValidationError` 在提交前返回。客户端和结果的默认 repr 隐藏凭据/正文,SDK 自身无业务日志。
|
|
69
|
+
|
|
70
|
+
高级配置可传入 wreq 的 `ca_certs`(证书路径/CertStore),或调用方拥有的同步/异步 `transport`。注入传输需自行保证证书校验、禁止重定向和不记录凭据;SDK 不关闭调用方拥有的传输。默认 wreq 客户端由上下文管理器释放。
|
|
71
|
+
|
|
72
|
+
源码包内的 `examples/solve.py` 和 `examples/products.py` 提供命令行调用示例。API Key 和目标参数均由调用方提供。
|
|
73
|
+
|
|
74
|
+
默认网关 `https://api.js-captcha.com`;`base_url` 可显式覆盖,常量 `DEFAULT_BASE_URL` 可导入。同步与异步客户端均有下列 9 个专用方法。例如 `solver.cloudflare_challenge(payload, timeout_ms=120000, request_id=rid)`,异步客户端使用 `await`,每个方法均返回完整 `SolveResponse`。
|
|
75
|
+
|
|
76
|
+
可运行入口(在本目录执行,先按真实目标准备 `payload.json` 并通过环境变量注入 AK):
|
|
77
|
+
|
|
78
|
+
```sh
|
|
79
|
+
python3 examples/products.py cloudflare_challenge payload.json
|
|
80
|
+
python3 examples/products.py cloudflare_challenge payload.json --async
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
`accounting(request_id)` 查询原请求的权威账务;异步客户端加 `await`。账户统一 API 语言设置优先于 `locale`;仅 `zh/en` 是有效语言提示。
|
|
84
|
+
|
|
85
|
+
| 方法 | 产品 / Action |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| `cloudflare_challenge` | `cloudflare/challenge` |
|
|
88
|
+
| `cloudflare_challenge_fast` | `cloudflare/challenge_fast` |
|
|
89
|
+
| `cloudflare_passive` | `cloudflare/passive` |
|
|
90
|
+
| `cloudflare_turnstile` | `cloudflare/turnstile` |
|
|
91
|
+
| `cloudflare_turnstile_proxyless` | `cloudflare/turnstile_proxyless` |
|
|
92
|
+
| `incapsula_execute` | `incapsula/execute` |
|
|
93
|
+
| `kasada_tl` | `kasada/tl` |
|
|
94
|
+
| `kasada_cd` | `kasada/cd` |
|
|
95
|
+
| `kasada_payload` | `kasada/payload` |
|
|
96
|
+
|
|
97
|
+
产品方法接受参数字典;可用 Action、参数要求和账户权限以服务端公开 API 文档为准。
|
|
98
|
+
|
|
99
|
+
## Cloudflare HTML
|
|
100
|
+
|
|
101
|
+
`cloudflare_challenge` 和 `cloudflare_challenge_fast` 会自动精简传入的 HTML,
|
|
102
|
+
以减少请求体大小。继续传入原始 HTML 即可。提取不到完整配置时保留原文;
|
|
103
|
+
调用方的参数字典不会被修改。其他产品和 Action 不受影响。
|
|
104
|
+
|
|
105
|
+
也可直接使用纯函数 `compact_cloudflare_html(html)`。目标页面、User-Agent、
|
|
106
|
+
代理和 Cookie 应属于同一次会话。SDK 不会替调用方获取网页或执行 JavaScript。
|
|
107
|
+
|
|
108
|
+
## Requirements
|
|
109
|
+
|
|
110
|
+
Python 3.11 or newer. Both blocking and async clients use `wreq` with TLS
|
|
111
|
+
verification enabled. Install the package on an operating system and architecture
|
|
112
|
+
supported by its `wreq` dependency. A Js-Captcha API key is required to call the service.
|
|
113
|
+
|
|
114
|
+
## License
|
|
115
|
+
|
|
116
|
+
Apache-2.0. See the included `LICENSE` and `NOTICE` files.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
js_captcha/__init__.py,sha256=Y1xkElAwqpSG4RwkRclnbJOQQ8L0BpiqClqf4CvUjzU,623
|
|
2
|
+
js_captcha/_protocol.py,sha256=PJHRQ4iMVJFBeoRAUcbKYKExjMpZM3wgA7G-ezZwLJY,8380
|
|
3
|
+
js_captcha/_version.py,sha256=J-j-u0itpEFT6irdmWmixQqYMadNl1X91TxUmoiLHMI,22
|
|
4
|
+
js_captcha/client.py,sha256=Mjud16sG0KmRkdp1BgbVdKhKz_1g9vm6cGiFpnHuQiw,17098
|
|
5
|
+
js_captcha/cloudflare.py,sha256=o4tGp1-3vAo1hRwbS86iDPEQvSUDFTNnj5T0Oa7xhA8,702
|
|
6
|
+
js_captcha/errors.py,sha256=NQRCKwgLcAFPKm7f122sjBPNNQoTPXPY_0kacGniBEw,1590
|
|
7
|
+
js_captcha/models.py,sha256=Jmjs3J7nn0PyNm6FzN2D7QXd0Mer21wK7RV_b6ZBrXo,803
|
|
8
|
+
js_captcha/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
|
+
js_captcha-1.0.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
10
|
+
js_captcha-1.0.0.dist-info/licenses/NOTICE,sha256=JlvbhIkpJWgy_iuFd_DQxdjzvrIFGCTgpDSi0tjB41M,174
|
|
11
|
+
js_captcha-1.0.0.dist-info/METADATA,sha256=De2B4yw-LnwuXqMuGc5Aj50-bzI8sYAc6dns_jADdqo,5398
|
|
12
|
+
js_captcha-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
13
|
+
js_captcha-1.0.0.dist-info/top_level.txt,sha256=O6TGAdTmqQDDjVkjC8kRR3_6D0Bc9zNHPckOXQpl4bA,11
|
|
14
|
+
js_captcha-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
js_captcha
|