chrome-client 0.1.7__py3-none-win32.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.
- chrome_client/__init__.py +101 -0
- chrome_client/__init__.pyi +352 -0
- chrome_client/_api_async.py +89 -0
- chrome_client/_api_sync.py +113 -0
- chrome_client/_async_session.py +753 -0
- chrome_client/_client.py +558 -0
- chrome_client/_cookies.py +409 -0
- chrome_client/_native_loader.py +192 -0
- chrome_client/_response.py +466 -0
- chrome_client/_session.py +808 -0
- chrome_client/_types.py +15 -0
- chrome_client/_typing.py +4 -0
- chrome_client/_typing.pyi +20 -0
- chrome_client/_utils.py +162 -0
- chrome_client/_websocket.py +177 -0
- chrome_client/cronet.144.0.7506.0.dll +0 -0
- chrome_client/cronet_cloak.pyd +0 -0
- chrome_client/py.typed +1 -0
- chrome_client/requests.py +22 -0
- chrome_client/requests.pyi +113 -0
- chrome_client/tls_profiles.json +3059 -0
- chrome_client-0.1.7.dist-info/METADATA +1034 -0
- chrome_client-0.1.7.dist-info/RECORD +26 -0
- chrome_client-0.1.7.dist-info/WHEEL +5 -0
- chrome_client-0.1.7.dist-info/licenses/LICENSE +21 -0
- chrome_client-0.1.7.dist-info/sboms/cronet-cloak.cyclonedx.json +3921 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Chrome Client - Python Client for Cronet-Cloak
|
|
3
|
+
|
|
4
|
+
使用方式:
|
|
5
|
+
import chrome_client
|
|
6
|
+
|
|
7
|
+
# 同步模式 - 模块级函数
|
|
8
|
+
response = chrome_client.get("https://example.com", verify=False)
|
|
9
|
+
|
|
10
|
+
# 同步模式 - Session
|
|
11
|
+
session = chrome_client.Client(verify=False)
|
|
12
|
+
response = session.get("https://example.com")
|
|
13
|
+
|
|
14
|
+
# 异步模式 - 模块级函数
|
|
15
|
+
import asyncio
|
|
16
|
+
response = await chrome_client.async_get("https://example.com", verify=False)
|
|
17
|
+
|
|
18
|
+
# 异步模式 - AsyncSession
|
|
19
|
+
async with chrome_client.AsyncClient(verify=False) as session:
|
|
20
|
+
response = await session.get("https://example.com")
|
|
21
|
+
|
|
22
|
+
# 使用代理
|
|
23
|
+
session = chrome_client.Client(
|
|
24
|
+
verify=False,
|
|
25
|
+
proxies={"https": "http://127.0.0.1:8080"}
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
# Response 对象
|
|
29
|
+
print(response.status_code)
|
|
30
|
+
print(response.text)
|
|
31
|
+
print(response.json())
|
|
32
|
+
"""
|
|
33
|
+
|
|
34
|
+
import sys
|
|
35
|
+
import os
|
|
36
|
+
|
|
37
|
+
# Load native libraries first (must be before importing Rust extension)
|
|
38
|
+
from ._native_loader import load_native_libraries
|
|
39
|
+
load_native_libraries()
|
|
40
|
+
|
|
41
|
+
# Import Rust extension module
|
|
42
|
+
try:
|
|
43
|
+
from . import cronet_cloak as _cronet_cloak
|
|
44
|
+
except ImportError as e:
|
|
45
|
+
# If import fails, provide helpful error message
|
|
46
|
+
if sys.platform == "linux" and "libcronet" in str(e):
|
|
47
|
+
package_dir = os.path.dirname(__file__)
|
|
48
|
+
raise ImportError(
|
|
49
|
+
f"Failed to load libcronet.so: {e}\n\n"
|
|
50
|
+
f"Quick fix: Run this command before starting Python:\n"
|
|
51
|
+
f" export LD_LIBRARY_PATH={package_dir}:$LD_LIBRARY_PATH\n\n"
|
|
52
|
+
f"See LINUX_INSTALL_GUIDE.md for more solutions."
|
|
53
|
+
) from e
|
|
54
|
+
else:
|
|
55
|
+
raise
|
|
56
|
+
|
|
57
|
+
# Import public API
|
|
58
|
+
from ._types import HeadersType, CookiesType, DataType
|
|
59
|
+
from ._typing import BrowserTypeLiteral
|
|
60
|
+
from ._cookies import Cookie, CookieJar
|
|
61
|
+
from ._response import (
|
|
62
|
+
Request, PreparedRequest, Response, StreamResponse, HTTPStatusError, RequestError,
|
|
63
|
+
Timeout, ConnectionError, ProxyError, SSLError,
|
|
64
|
+
)
|
|
65
|
+
from ._client import (
|
|
66
|
+
Client, AsyncClient, Session, AsyncSession,
|
|
67
|
+
set_tls_profiles, add_tls_profile, get_tls_profiles, clear_tls_profiles_cache,
|
|
68
|
+
_TLS_PROFILES_CACHE
|
|
69
|
+
)
|
|
70
|
+
from ._api_sync import (
|
|
71
|
+
request, session, get, post, put, delete, patch, head, options, trace, query,
|
|
72
|
+
upload_file, download_file
|
|
73
|
+
)
|
|
74
|
+
from ._api_async import (
|
|
75
|
+
async_request, async_get, async_post, async_put, async_delete, async_patch,
|
|
76
|
+
async_head, async_options, async_upload_file, async_download_file
|
|
77
|
+
)
|
|
78
|
+
from ._websocket import WebSocketApp
|
|
79
|
+
from . import requests as requests
|
|
80
|
+
|
|
81
|
+
RequestException = RequestError
|
|
82
|
+
HTTPError = HTTPStatusError
|
|
83
|
+
|
|
84
|
+
__all__ = [
|
|
85
|
+
"Client", "Session", "Request", "PreparedRequest", "Response", "StreamResponse", "HTTPStatusError", "RequestError",
|
|
86
|
+
"Cookie", "CookieJar",
|
|
87
|
+
"requests", "request", "session", "get", "post", "put", "delete", "patch", "head", "options", "trace", "query",
|
|
88
|
+
"upload_file", "download_file",
|
|
89
|
+
"AsyncClient", "AsyncSession",
|
|
90
|
+
"async_request", "async_get", "async_post", "async_put", "async_delete", "async_patch",
|
|
91
|
+
"async_head", "async_options", "async_upload_file", "async_download_file",
|
|
92
|
+
"set_tls_profiles", "add_tls_profile", "get_tls_profiles", "clear_tls_profiles_cache",
|
|
93
|
+
"WebSocketApp"
|
|
94
|
+
]
|
|
95
|
+
|
|
96
|
+
__all__ += ["BrowserTypeLiteral"]
|
|
97
|
+
|
|
98
|
+
__all__ += [
|
|
99
|
+
"RequestException", "HTTPError", "Timeout", "ConnectionError",
|
|
100
|
+
"ProxyError", "SSLError",
|
|
101
|
+
]
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
from typing import Any, AsyncIterator, Dict, Iterable, Iterator, List, Mapping, Optional, Sequence, Tuple, Union
|
|
2
|
+
from datetime import timedelta
|
|
3
|
+
from ._typing import BrowserTypeLiteral as BrowserTypeLiteral
|
|
4
|
+
|
|
5
|
+
HeadersType = Union[Mapping[str, Optional[str]], Sequence[Tuple[str, Optional[str]]]]
|
|
6
|
+
CookiesType = Union[Mapping[str, str], "CookieJar"]
|
|
7
|
+
DataType = Union[str, bytes, bytearray, Mapping[str, Any], Sequence[Tuple[str, Any]], None]
|
|
8
|
+
|
|
9
|
+
class Cookie:
|
|
10
|
+
name: str
|
|
11
|
+
value: str
|
|
12
|
+
domain: str
|
|
13
|
+
path: str
|
|
14
|
+
seq: int
|
|
15
|
+
creation_seq: int
|
|
16
|
+
expires: Optional[float]
|
|
17
|
+
host_only: bool
|
|
18
|
+
secure: bool
|
|
19
|
+
def __init__(self, name: str, value: str, domain: str = ..., path: str = ..., seq: int = ..., expires: Optional[float] = ..., host_only: bool = ..., secure: bool = ..., creation_seq: Optional[int] = ...) -> None: ...
|
|
20
|
+
def is_expired(self, now: Optional[float] = ...) -> bool: ...
|
|
21
|
+
def matches(self, domain: str, path: str = ..., secure: bool = ...) -> bool: ...
|
|
22
|
+
|
|
23
|
+
class CookieJar:
|
|
24
|
+
default_domain: str
|
|
25
|
+
def __init__(self, default_domain: Optional[str] = ...) -> None: ...
|
|
26
|
+
def set(self, name: str, value: str, domain: Optional[str] = ..., path: str = ..., expires: Optional[float] = ..., max_age: Optional[int] = ..., host_only: Optional[bool] = ..., secure: bool = ...) -> None: ...
|
|
27
|
+
def set_cookie(self, name: str, value: str, domain: Optional[str] = ..., path: str = ..., expires: Optional[float] = ..., max_age: Optional[int] = ..., host_only: Optional[bool] = ..., secure: bool = ...) -> None: ...
|
|
28
|
+
def update_from_set_cookie(self, values: Iterable[str], request_url: str) -> None: ...
|
|
29
|
+
def cookies_for_request(self, url: str) -> List[Cookie]: ...
|
|
30
|
+
def get(self, name: str, default: Optional[str] = ..., domain: Optional[str] = ..., path: Optional[str] = ...) -> Optional[str]: ...
|
|
31
|
+
def get_dict(self, domain: Optional[str] = ..., path: Optional[str] = ...) -> Dict[str, str]: ...
|
|
32
|
+
def update(self, cookies: CookiesType, domain: Optional[str] = ...) -> None: ...
|
|
33
|
+
def clear(self, domain: Optional[str] = ..., path: Optional[str] = ...) -> None: ...
|
|
34
|
+
def clear_expired_cookies(self) -> None: ...
|
|
35
|
+
def clear_session_cookies(self) -> None: ...
|
|
36
|
+
def set_default_domain(self, domain: Optional[str]) -> None: ...
|
|
37
|
+
def delete(self, name: Optional[str] = ..., domain: Optional[str] = ..., path: Optional[str] = ...) -> None: ...
|
|
38
|
+
def remove(self, name: str, domain: Optional[str] = ..., path: Optional[str] = ...) -> None: ...
|
|
39
|
+
def copy(self) -> "CookieJar": ...
|
|
40
|
+
def list_domains(self) -> List[str]: ...
|
|
41
|
+
def items_for_domain(self, domain: str, path: str = ...) -> Iterator[Tuple[str, str]]: ...
|
|
42
|
+
def iter_cookies(self) -> Iterator[Cookie]: ...
|
|
43
|
+
def items(self) -> Iterator[Tuple[str, str]]: ...
|
|
44
|
+
def keys(self) -> Iterator[str]: ...
|
|
45
|
+
def values(self) -> Iterator[str]: ...
|
|
46
|
+
def __setitem__(self, name: str, value: str) -> None: ...
|
|
47
|
+
def __getitem__(self, name: str) -> str: ...
|
|
48
|
+
def __contains__(self, name: str) -> bool: ...
|
|
49
|
+
def __bool__(self) -> bool: ...
|
|
50
|
+
def __iter__(self) -> Iterator[Cookie]: ...
|
|
51
|
+
def __len__(self) -> int: ...
|
|
52
|
+
|
|
53
|
+
class Request:
|
|
54
|
+
method: Optional[str]
|
|
55
|
+
url: Optional[str]
|
|
56
|
+
headers: Dict[str, str]
|
|
57
|
+
files: Any
|
|
58
|
+
data: Any
|
|
59
|
+
params: Any
|
|
60
|
+
auth: Any
|
|
61
|
+
cookies: Any
|
|
62
|
+
hooks: Any
|
|
63
|
+
json: Any
|
|
64
|
+
def __init__(self, method: Optional[str] = ..., url: Optional[str] = ..., headers: Any = ..., files: Any = ..., data: Any = ..., params: Any = ..., auth: Any = ..., cookies: Any = ..., hooks: Any = ..., json: Any = ...) -> None: ...
|
|
65
|
+
|
|
66
|
+
class PreparedRequest:
|
|
67
|
+
method: str
|
|
68
|
+
url: str
|
|
69
|
+
headers: Dict[str, str]
|
|
70
|
+
body: Any
|
|
71
|
+
def __init__(self, method: str, url: str, headers: Optional[Dict[str, str]] = ..., body: Any = ...) -> None: ...
|
|
72
|
+
|
|
73
|
+
class RequestError(Exception): ...
|
|
74
|
+
class Timeout(RequestError): ...
|
|
75
|
+
class ConnectionError(RequestError): ...
|
|
76
|
+
class ProxyError(ConnectionError): ...
|
|
77
|
+
class SSLError(ConnectionError): ...
|
|
78
|
+
class HTTPStatusError(RequestError):
|
|
79
|
+
response: Union["Response", "StreamResponse"]
|
|
80
|
+
request: Optional[PreparedRequest]
|
|
81
|
+
|
|
82
|
+
RequestException = RequestError
|
|
83
|
+
HTTPError = HTTPStatusError
|
|
84
|
+
|
|
85
|
+
class Response:
|
|
86
|
+
status_code: int
|
|
87
|
+
content: bytes
|
|
88
|
+
url: str
|
|
89
|
+
encoding: Optional[str]
|
|
90
|
+
reason: str
|
|
91
|
+
history: List["Response"]
|
|
92
|
+
request: Optional[PreparedRequest]
|
|
93
|
+
elapsed: timedelta
|
|
94
|
+
raw: Any
|
|
95
|
+
def __init__(self, status_code: int, _headers: Dict[str, List[str]], content: bytes, url: str = ..., _cookies: Optional[CookieJar] = ..., encoding: Optional[str] = ..., reason: str = ..., history: Optional[List["Response"]] = ..., request: Optional[PreparedRequest] = ..., elapsed: Optional[timedelta] = ..., raw: Any = ...) -> None: ...
|
|
96
|
+
@property
|
|
97
|
+
def headers(self) -> Dict[str, str]: ...
|
|
98
|
+
@property
|
|
99
|
+
def cookies(self) -> CookieJar: ...
|
|
100
|
+
@property
|
|
101
|
+
def text(self) -> str: ...
|
|
102
|
+
@property
|
|
103
|
+
def ok(self) -> bool: ...
|
|
104
|
+
@property
|
|
105
|
+
def is_redirect(self) -> bool: ...
|
|
106
|
+
def json(self, **kwargs: Any) -> Any: ...
|
|
107
|
+
def raise_for_status(self) -> None: ...
|
|
108
|
+
def iter_content(self, chunk_size: Optional[int] = ..., decode_unicode: bool = ...) -> Iterable[Union[bytes, str]]: ...
|
|
109
|
+
def iter_lines(self, chunk_size: int = ..., decode_unicode: bool = ..., delimiter: Any = ...) -> Iterable[Union[bytes, str]]: ...
|
|
110
|
+
def close(self) -> None: ...
|
|
111
|
+
def __bool__(self) -> bool: ...
|
|
112
|
+
|
|
113
|
+
class StreamResponse:
|
|
114
|
+
status_code: int
|
|
115
|
+
url: str
|
|
116
|
+
encoding: Optional[str]
|
|
117
|
+
reason: str
|
|
118
|
+
history: List[Response]
|
|
119
|
+
request: Optional[PreparedRequest]
|
|
120
|
+
elapsed: timedelta
|
|
121
|
+
raw: Any
|
|
122
|
+
def __init__(self, reader: Any, url: str = ..., cookies: Optional[CookieJar] = ..., encoding: Optional[str] = ..., session: Any = ...) -> None: ...
|
|
123
|
+
@property
|
|
124
|
+
def headers(self) -> Dict[str, str]: ...
|
|
125
|
+
@property
|
|
126
|
+
def cookies(self) -> CookieJar: ...
|
|
127
|
+
@property
|
|
128
|
+
def content(self) -> bytes: ...
|
|
129
|
+
@property
|
|
130
|
+
def text(self) -> str: ...
|
|
131
|
+
@property
|
|
132
|
+
def ok(self) -> bool: ...
|
|
133
|
+
@property
|
|
134
|
+
def is_redirect(self) -> bool: ...
|
|
135
|
+
def json(self, **kwargs: Any) -> Any: ...
|
|
136
|
+
def raise_for_status(self) -> None: ...
|
|
137
|
+
def iter_content(self, chunk_size: Optional[int] = ...) -> Iterable[bytes]: ...
|
|
138
|
+
def iter_lines(self, chunk_size: int = ..., decode_unicode: bool = ..., delimiter: Optional[str] = ...) -> Iterable[Union[bytes, str]]: ...
|
|
139
|
+
def aiter_content(self, chunk_size: Optional[int] = ...) -> AsyncIterator[bytes]: ...
|
|
140
|
+
def aiter_lines(self, chunk_size: int = ..., decode_unicode: bool = ..., delimiter: Optional[str] = ...) -> AsyncIterator[Union[bytes, str]]: ...
|
|
141
|
+
async def acontent(self) -> bytes: ...
|
|
142
|
+
async def atext(self) -> str: ...
|
|
143
|
+
def close(self) -> None: ...
|
|
144
|
+
async def aclose(self) -> None: ...
|
|
145
|
+
def __enter__(self) -> "StreamResponse": ...
|
|
146
|
+
def __exit__(self, *args: Any) -> None: ...
|
|
147
|
+
async def __aenter__(self) -> "StreamResponse": ...
|
|
148
|
+
async def __aexit__(self, *args: Any) -> None: ...
|
|
149
|
+
def __bool__(self) -> bool: ...
|
|
150
|
+
|
|
151
|
+
class Client:
|
|
152
|
+
headers: Dict[str, str]
|
|
153
|
+
params: Dict[str, Any]
|
|
154
|
+
auth: Optional[Tuple[str, str]]
|
|
155
|
+
proxies: Union[str, Dict[str, str]]
|
|
156
|
+
verify: bool
|
|
157
|
+
stream: bool
|
|
158
|
+
cert: Any
|
|
159
|
+
max_redirects: int
|
|
160
|
+
timeout: Any
|
|
161
|
+
allow_redirects: bool
|
|
162
|
+
impersonate: Optional[BrowserTypeLiteral]
|
|
163
|
+
base_url: str
|
|
164
|
+
@property
|
|
165
|
+
def cookies(self) -> CookieJar: ...
|
|
166
|
+
@cookies.setter
|
|
167
|
+
def cookies(self, value: CookiesType) -> None: ...
|
|
168
|
+
def __init__(
|
|
169
|
+
self, verify: bool = ..., proxies: Optional[Union[str, Dict[str, str]]] = ...,
|
|
170
|
+
timeout: Any = ..., impersonate: Optional[BrowserTypeLiteral] = ...,
|
|
171
|
+
headers: Optional[Dict[str, str]] = ..., cookies: Optional[CookiesType] = ...,
|
|
172
|
+
auth: Optional[Tuple[str, str]] = ..., proxy: Optional[str] = ...,
|
|
173
|
+
base_url: Optional[str] = ..., params: Optional[Dict[str, Any]] = ...,
|
|
174
|
+
allow_redirects: bool = ..., max_redirects: int = ...,
|
|
175
|
+
default_headers: bool = ..., timeout_ms: Optional[int] = ...,
|
|
176
|
+
default_domain: Optional[str] = ...
|
|
177
|
+
) -> None: ...
|
|
178
|
+
def request(
|
|
179
|
+
self, method: str, url: str, params: Any = ..., headers: Optional[HeadersType] = ...,
|
|
180
|
+
cookies: Optional[CookiesType] = ..., data: DataType = ..., content: Any = ...,
|
|
181
|
+
json: Any = ..., files: Any = ..., auth: Any = ..., timeout: Any = ...,
|
|
182
|
+
verify: Optional[bool] = ..., allow_redirects: Optional[bool] = ...,
|
|
183
|
+
proxies: Any = ..., proxy: Optional[str] = ..., hooks: Any = ...,
|
|
184
|
+
stream: Optional[bool] = ..., cert: Any = ..., impersonate: Optional[BrowserTypeLiteral] = ...,
|
|
185
|
+
max_redirects: Optional[int] = ..., **kwargs: Any
|
|
186
|
+
) -> Union[Response, StreamResponse]: ...
|
|
187
|
+
def get(
|
|
188
|
+
self, url: str, params: Any = ..., *, headers: Optional[HeadersType] = ...,
|
|
189
|
+
cookies: Optional[CookiesType] = ..., data: DataType = ..., content: Any = ...,
|
|
190
|
+
json: Any = ..., auth: Any = ..., timeout: Any = ..., verify: Optional[bool] = ...,
|
|
191
|
+
allow_redirects: Optional[bool] = ..., proxies: Any = ..., proxy: Optional[str] = ...,
|
|
192
|
+
hooks: Any = ..., stream: Optional[bool] = ...,
|
|
193
|
+
impersonate: Optional[BrowserTypeLiteral] = ..., max_redirects: Optional[int] = ...
|
|
194
|
+
) -> Union[Response, StreamResponse]: ...
|
|
195
|
+
def options(
|
|
196
|
+
self, url: str, *, params: Any = ..., headers: Optional[HeadersType] = ...,
|
|
197
|
+
cookies: Optional[CookiesType] = ..., data: DataType = ..., content: Any = ...,
|
|
198
|
+
json: Any = ..., auth: Any = ..., timeout: Any = ..., verify: Optional[bool] = ...,
|
|
199
|
+
allow_redirects: Optional[bool] = ..., proxies: Any = ..., proxy: Optional[str] = ...,
|
|
200
|
+
hooks: Any = ..., stream: Optional[bool] = ...,
|
|
201
|
+
impersonate: Optional[BrowserTypeLiteral] = ..., max_redirects: Optional[int] = ...
|
|
202
|
+
) -> Union[Response, StreamResponse]: ...
|
|
203
|
+
def head(
|
|
204
|
+
self, url: str, *, params: Any = ..., headers: Optional[HeadersType] = ...,
|
|
205
|
+
cookies: Optional[CookiesType] = ..., auth: Any = ..., timeout: Any = ...,
|
|
206
|
+
verify: Optional[bool] = ..., allow_redirects: Optional[bool] = ...,
|
|
207
|
+
proxies: Any = ..., proxy: Optional[str] = ..., hooks: Any = ...,
|
|
208
|
+
stream: Optional[bool] = ..., impersonate: Optional[BrowserTypeLiteral] = ...,
|
|
209
|
+
max_redirects: Optional[int] = ...
|
|
210
|
+
) -> Union[Response, StreamResponse]: ...
|
|
211
|
+
def post(
|
|
212
|
+
self, url: str, data: DataType = ..., json: Any = ..., *, params: Any = ...,
|
|
213
|
+
headers: Optional[HeadersType] = ..., cookies: Optional[CookiesType] = ...,
|
|
214
|
+
content: Any = ..., auth: Any = ..., timeout: Any = ..., verify: Optional[bool] = ...,
|
|
215
|
+
allow_redirects: Optional[bool] = ..., proxies: Any = ..., proxy: Optional[str] = ...,
|
|
216
|
+
hooks: Any = ..., stream: Optional[bool] = ...,
|
|
217
|
+
impersonate: Optional[BrowserTypeLiteral] = ..., max_redirects: Optional[int] = ...
|
|
218
|
+
) -> Union[Response, StreamResponse]: ...
|
|
219
|
+
def put(
|
|
220
|
+
self, url: str, data: DataType = ..., *, params: Any = ...,
|
|
221
|
+
headers: Optional[HeadersType] = ..., cookies: Optional[CookiesType] = ...,
|
|
222
|
+
content: Any = ..., json: Any = ..., auth: Any = ..., timeout: Any = ...,
|
|
223
|
+
verify: Optional[bool] = ..., allow_redirects: Optional[bool] = ...,
|
|
224
|
+
proxies: Any = ..., proxy: Optional[str] = ..., hooks: Any = ...,
|
|
225
|
+
stream: Optional[bool] = ..., impersonate: Optional[BrowserTypeLiteral] = ...,
|
|
226
|
+
max_redirects: Optional[int] = ...
|
|
227
|
+
) -> Union[Response, StreamResponse]: ...
|
|
228
|
+
def patch(
|
|
229
|
+
self, url: str, data: DataType = ..., *, params: Any = ...,
|
|
230
|
+
headers: Optional[HeadersType] = ..., cookies: Optional[CookiesType] = ...,
|
|
231
|
+
content: Any = ..., json: Any = ..., auth: Any = ..., timeout: Any = ...,
|
|
232
|
+
verify: Optional[bool] = ..., allow_redirects: Optional[bool] = ...,
|
|
233
|
+
proxies: Any = ..., proxy: Optional[str] = ..., hooks: Any = ...,
|
|
234
|
+
stream: Optional[bool] = ..., impersonate: Optional[BrowserTypeLiteral] = ...,
|
|
235
|
+
max_redirects: Optional[int] = ...
|
|
236
|
+
) -> Union[Response, StreamResponse]: ...
|
|
237
|
+
def delete(
|
|
238
|
+
self, url: str, *, params: Any = ..., headers: Optional[HeadersType] = ...,
|
|
239
|
+
cookies: Optional[CookiesType] = ..., data: DataType = ..., content: Any = ...,
|
|
240
|
+
json: Any = ..., auth: Any = ..., timeout: Any = ..., verify: Optional[bool] = ...,
|
|
241
|
+
allow_redirects: Optional[bool] = ..., proxies: Any = ..., proxy: Optional[str] = ...,
|
|
242
|
+
hooks: Any = ..., stream: Optional[bool] = ...,
|
|
243
|
+
impersonate: Optional[BrowserTypeLiteral] = ..., max_redirects: Optional[int] = ...
|
|
244
|
+
) -> Union[Response, StreamResponse]: ...
|
|
245
|
+
def trace(
|
|
246
|
+
self, url: str, *, params: Any = ..., headers: Optional[HeadersType] = ...,
|
|
247
|
+
cookies: Optional[CookiesType] = ..., data: DataType = ..., content: Any = ...,
|
|
248
|
+
json: Any = ..., auth: Any = ..., timeout: Any = ..., verify: Optional[bool] = ...,
|
|
249
|
+
allow_redirects: Optional[bool] = ..., proxies: Any = ..., proxy: Optional[str] = ...,
|
|
250
|
+
hooks: Any = ..., stream: Optional[bool] = ...,
|
|
251
|
+
impersonate: Optional[BrowserTypeLiteral] = ..., max_redirects: Optional[int] = ...
|
|
252
|
+
) -> Union[Response, StreamResponse]: ...
|
|
253
|
+
def query(
|
|
254
|
+
self, url: str, *, params: Any = ..., headers: Optional[HeadersType] = ...,
|
|
255
|
+
cookies: Optional[CookiesType] = ..., data: DataType = ..., content: Any = ...,
|
|
256
|
+
json: Any = ..., auth: Any = ..., timeout: Any = ..., verify: Optional[bool] = ...,
|
|
257
|
+
allow_redirects: Optional[bool] = ..., proxies: Any = ..., proxy: Optional[str] = ...,
|
|
258
|
+
hooks: Any = ..., stream: Optional[bool] = ...,
|
|
259
|
+
impersonate: Optional[BrowserTypeLiteral] = ..., max_redirects: Optional[int] = ...
|
|
260
|
+
) -> Union[Response, StreamResponse]: ...
|
|
261
|
+
def prepare_request(self, request: Request) -> PreparedRequest: ...
|
|
262
|
+
def send(self, request: PreparedRequest, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
263
|
+
def upload_file(self, url: str, file_path: str, **kwargs: Any) -> Response: ...
|
|
264
|
+
def download_file(self, url: str, save_path: str, **kwargs: Any) -> Dict[str, Any]: ...
|
|
265
|
+
def websocket(self, url: str, **kwargs: Any) -> "WebSocketApp": ...
|
|
266
|
+
def close(self) -> None: ...
|
|
267
|
+
def __enter__(self) -> "Client": ...
|
|
268
|
+
def __exit__(self, *args: Any) -> None: ...
|
|
269
|
+
|
|
270
|
+
class Session(Client):
|
|
271
|
+
def __init__(self, verify: bool = ..., proxies: Any = ..., timeout: Any = ..., impersonate: Optional[BrowserTypeLiteral] = ..., headers: Any = ..., cookies: Any = ..., auth: Any = ..., proxy: Optional[str] = ..., base_url: Optional[str] = ..., params: Any = ..., allow_redirects: bool = ..., max_redirects: int = ..., default_headers: bool = ..., timeout_ms: Optional[int] = ..., default_domain: Optional[str] = ...) -> None: ...
|
|
272
|
+
|
|
273
|
+
class AsyncClient:
|
|
274
|
+
headers: Dict[str, str]
|
|
275
|
+
params: Dict[str, Any]
|
|
276
|
+
auth: Optional[Tuple[str, str]]
|
|
277
|
+
proxies: Union[str, Dict[str, str]]
|
|
278
|
+
verify: bool
|
|
279
|
+
stream: bool
|
|
280
|
+
cert: Any
|
|
281
|
+
max_redirects: int
|
|
282
|
+
timeout: Any
|
|
283
|
+
allow_redirects: bool
|
|
284
|
+
impersonate: Optional[BrowserTypeLiteral]
|
|
285
|
+
base_url: str
|
|
286
|
+
@property
|
|
287
|
+
def cookies(self) -> CookieJar: ...
|
|
288
|
+
@cookies.setter
|
|
289
|
+
def cookies(self, value: CookiesType) -> None: ...
|
|
290
|
+
def __init__(self, verify: bool = ..., proxies: Any = ..., timeout: Any = ..., impersonate: Optional[BrowserTypeLiteral] = ..., headers: Any = ..., cookies: Any = ..., auth: Any = ..., proxy: Optional[str] = ..., base_url: Optional[str] = ..., params: Any = ..., allow_redirects: bool = ..., max_redirects: int = ..., default_headers: bool = ..., timeout_ms: Optional[int] = ..., default_domain: Optional[str] = ...) -> None: ...
|
|
291
|
+
async def request(self, method: str, url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
292
|
+
async def get(self, url: str, params: Any = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
293
|
+
async def options(self, url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
294
|
+
async def head(self, url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
295
|
+
async def post(self, url: str, data: DataType = ..., json: Any = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
296
|
+
async def put(self, url: str, data: DataType = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
297
|
+
async def patch(self, url: str, data: DataType = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
298
|
+
async def delete(self, url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
299
|
+
async def trace(self, url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
300
|
+
async def query(self, url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
301
|
+
def prepare_request(self, request: Request) -> PreparedRequest: ...
|
|
302
|
+
async def send(self, request: PreparedRequest, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
303
|
+
async def upload_file(self, url: str, file_path: str, **kwargs: Any) -> Response: ...
|
|
304
|
+
async def download_file(self, url: str, save_path: str, **kwargs: Any) -> Dict[str, Any]: ...
|
|
305
|
+
def websocket(self, url: str, **kwargs: Any) -> "WebSocketApp": ...
|
|
306
|
+
async def close(self) -> None: ...
|
|
307
|
+
async def __aenter__(self) -> "AsyncClient": ...
|
|
308
|
+
async def __aexit__(self, *args: Any) -> None: ...
|
|
309
|
+
|
|
310
|
+
class AsyncSession(AsyncClient): ...
|
|
311
|
+
|
|
312
|
+
class WebSocketApp:
|
|
313
|
+
def __init__(self, session: Union[Client, AsyncClient], url: str, on_open: Any = ..., on_message: Any = ..., on_close: Any = ..., on_error: Any = ..., sub_protocols: Optional[Union[str, Sequence[str]]] = ..., origin: Optional[str] = ..., headers: Optional[HeadersType] = ...) -> None: ...
|
|
314
|
+
@property
|
|
315
|
+
def connected(self) -> bool: ...
|
|
316
|
+
def send(self, message: str) -> None: ...
|
|
317
|
+
def send_bytes(self, data: bytes) -> None: ...
|
|
318
|
+
def close(self, code: int = ..., reason: str = ...) -> None: ...
|
|
319
|
+
def run_forever(self, blocking: bool = ...) -> Any: ...
|
|
320
|
+
def run_in_background(self) -> Any: ...
|
|
321
|
+
|
|
322
|
+
def request(method: str, url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
323
|
+
def session(**kwargs: Any) -> Session: ...
|
|
324
|
+
def get(url: str, params: Any = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
325
|
+
def options(url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
326
|
+
def head(url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
327
|
+
def post(url: str, data: DataType = ..., json: Any = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
328
|
+
def put(url: str, data: DataType = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
329
|
+
def patch(url: str, data: DataType = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
330
|
+
def delete(url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
331
|
+
def trace(url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
332
|
+
def query(url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
333
|
+
def upload_file(url: str, file_path: str, **kwargs: Any) -> Response: ...
|
|
334
|
+
def download_file(url: str, save_path: str, **kwargs: Any) -> Dict[str, Any]: ...
|
|
335
|
+
|
|
336
|
+
async def async_request(method: str, url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
337
|
+
async def async_get(url: str, params: Any = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
338
|
+
async def async_options(url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
339
|
+
async def async_head(url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
340
|
+
async def async_post(url: str, data: DataType = ..., json: Any = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
341
|
+
async def async_put(url: str, data: DataType = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
342
|
+
async def async_patch(url: str, data: DataType = ..., **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
343
|
+
async def async_delete(url: str, **kwargs: Any) -> Union[Response, StreamResponse]: ...
|
|
344
|
+
async def async_upload_file(url: str, file_path: str, **kwargs: Any) -> Response: ...
|
|
345
|
+
async def async_download_file(url: str, save_path: str, **kwargs: Any) -> Dict[str, Any]: ...
|
|
346
|
+
|
|
347
|
+
def set_tls_profiles(profiles: Dict[str, Dict[str, Any]]) -> None: ...
|
|
348
|
+
def add_tls_profile(name: str, profile: Dict[str, Any]) -> None: ...
|
|
349
|
+
def get_tls_profiles() -> Dict[str, Dict[str, Any]]: ...
|
|
350
|
+
def clear_tls_profiles_cache() -> None: ...
|
|
351
|
+
|
|
352
|
+
from . import requests as requests
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"""Asynchronous convenience API; AsyncSession remains the primary interface."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional, Dict, Any
|
|
4
|
+
|
|
5
|
+
from ._response import Response, StreamResponse
|
|
6
|
+
from ._client import AsyncSession
|
|
7
|
+
|
|
8
|
+
_SESSION_KEYS = {
|
|
9
|
+
"verify", "proxies", "proxy", "timeout", "impersonate", "timeout_ms",
|
|
10
|
+
"base_url", "default_domain", "default_headers",
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
async def _async_send(method, url, **kwargs):
|
|
15
|
+
session_kwargs = {
|
|
16
|
+
key: kwargs.pop(key) for key in tuple(kwargs) if key in _SESSION_KEYS
|
|
17
|
+
}
|
|
18
|
+
session = AsyncSession(**session_kwargs)
|
|
19
|
+
try:
|
|
20
|
+
response = await session.request(method, url, **kwargs)
|
|
21
|
+
if isinstance(response, StreamResponse):
|
|
22
|
+
response._session = session
|
|
23
|
+
else:
|
|
24
|
+
await session.close()
|
|
25
|
+
return response
|
|
26
|
+
except Exception:
|
|
27
|
+
await session.close()
|
|
28
|
+
raise
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
async def async_request(method, url, **kwargs):
|
|
32
|
+
return await _async_send(method, url, **kwargs)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
async def async_get(url, params=None, **kwargs):
|
|
36
|
+
return await async_request("GET", url, params=params, **kwargs)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
async def async_options(url, **kwargs):
|
|
40
|
+
return await async_request("OPTIONS", url, **kwargs)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
async def async_head(url, **kwargs):
|
|
44
|
+
kwargs.setdefault("allow_redirects", False)
|
|
45
|
+
return await async_request("HEAD", url, **kwargs)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
async def async_post(url, data=None, json=None, **kwargs):
|
|
49
|
+
return await async_request("POST", url, data=data, json=json, **kwargs)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async def async_put(url, data=None, **kwargs):
|
|
53
|
+
return await async_request("PUT", url, data=data, **kwargs)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
async def async_patch(url, data=None, **kwargs):
|
|
57
|
+
return await async_request("PATCH", url, data=data, **kwargs)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
async def async_delete(url, **kwargs):
|
|
61
|
+
return await async_request("DELETE", url, **kwargs)
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
async def async_upload_file(
|
|
65
|
+
url: str, file_path: str, *, field_name: str = "file",
|
|
66
|
+
additional_fields: Optional[Dict[str, str]] = None,
|
|
67
|
+
verify: bool = True, timeout: Optional[float] = None,
|
|
68
|
+
impersonate: Optional[str] = "chrome_150", **kwargs,
|
|
69
|
+
) -> Response:
|
|
70
|
+
async with AsyncSession(
|
|
71
|
+
verify=verify, timeout=timeout, impersonate=impersonate
|
|
72
|
+
) as session:
|
|
73
|
+
return await session.upload_file(
|
|
74
|
+
url, file_path, field_name=field_name,
|
|
75
|
+
additional_fields=additional_fields, **kwargs
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
async def async_download_file(
|
|
80
|
+
url: str, save_path: str, *, verify: bool = True,
|
|
81
|
+
timeout: Optional[float] = None, chunk_size: int = 8192,
|
|
82
|
+
impersonate: Optional[str] = "chrome_150", **kwargs,
|
|
83
|
+
) -> Dict[str, Any]:
|
|
84
|
+
async with AsyncSession(
|
|
85
|
+
verify=verify, timeout=timeout, impersonate=impersonate
|
|
86
|
+
) as session:
|
|
87
|
+
return await session.download_file(
|
|
88
|
+
url, save_path, chunk_size=chunk_size, **kwargs
|
|
89
|
+
)
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"""Requests-first synchronous module API."""
|
|
2
|
+
|
|
3
|
+
from typing import Optional, Dict, Any
|
|
4
|
+
|
|
5
|
+
from ._types import HeadersType, CookiesType
|
|
6
|
+
from ._response import Response, StreamResponse
|
|
7
|
+
from ._client import Session
|
|
8
|
+
|
|
9
|
+
_SESSION_KEYS = {
|
|
10
|
+
"verify", "proxies", "proxy", "timeout", "impersonate", "timeout_ms",
|
|
11
|
+
"base_url", "default_domain", "default_headers",
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _send(method, url, **kwargs):
|
|
16
|
+
"""Create one temporary Session, preserving it only for streamed responses."""
|
|
17
|
+
session_kwargs = {
|
|
18
|
+
key: kwargs.pop(key) for key in tuple(kwargs) if key in _SESSION_KEYS
|
|
19
|
+
}
|
|
20
|
+
session = Session(**session_kwargs)
|
|
21
|
+
try:
|
|
22
|
+
response = session.request(method, url, **kwargs)
|
|
23
|
+
if isinstance(response, StreamResponse):
|
|
24
|
+
response._session = session
|
|
25
|
+
else:
|
|
26
|
+
session.close()
|
|
27
|
+
return response
|
|
28
|
+
except Exception:
|
|
29
|
+
session.close()
|
|
30
|
+
raise
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def request(method, url, **kwargs):
|
|
34
|
+
return _send(method, url, **kwargs)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def session(**kwargs):
|
|
38
|
+
return Session(**kwargs)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def get(url, params=None, **kwargs):
|
|
42
|
+
return request("GET", url, params=params, **kwargs)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def options(url, **kwargs):
|
|
46
|
+
return request("OPTIONS", url, **kwargs)
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def head(url, **kwargs):
|
|
50
|
+
kwargs.setdefault("allow_redirects", False)
|
|
51
|
+
return request("HEAD", url, **kwargs)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def post(url, data=None, json=None, **kwargs):
|
|
55
|
+
return request("POST", url, data=data, json=json, **kwargs)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def put(url, data=None, **kwargs):
|
|
59
|
+
return request("PUT", url, data=data, **kwargs)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def patch(url, data=None, **kwargs):
|
|
63
|
+
return request("PATCH", url, data=data, **kwargs)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def delete(url, **kwargs):
|
|
67
|
+
return request("DELETE", url, **kwargs)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def trace(url, **kwargs):
|
|
71
|
+
return request("TRACE", url, **kwargs)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def query(url, **kwargs):
|
|
75
|
+
return request("QUERY", url, **kwargs)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def upload_file(
|
|
79
|
+
url: str,
|
|
80
|
+
file_path: str,
|
|
81
|
+
*,
|
|
82
|
+
field_name: str = "file",
|
|
83
|
+
additional_fields: Optional[Dict[str, str]] = None,
|
|
84
|
+
headers: Optional[HeadersType] = None,
|
|
85
|
+
cookies: Optional[CookiesType] = None,
|
|
86
|
+
timeout: Optional[float] = None,
|
|
87
|
+
verify: bool = True,
|
|
88
|
+
impersonate: Optional[str] = "chrome_150",
|
|
89
|
+
**kwargs: Any
|
|
90
|
+
) -> Response:
|
|
91
|
+
with Session(verify=verify, timeout=timeout, impersonate=impersonate, **kwargs) as session:
|
|
92
|
+
return session.upload_file(
|
|
93
|
+
url, file_path, field_name=field_name,
|
|
94
|
+
additional_fields=additional_fields, headers=headers, cookies=cookies,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def download_file(
|
|
99
|
+
url: str,
|
|
100
|
+
save_path: str,
|
|
101
|
+
*,
|
|
102
|
+
headers: Optional[HeadersType] = None,
|
|
103
|
+
cookies: Optional[CookiesType] = None,
|
|
104
|
+
timeout: Optional[float] = None,
|
|
105
|
+
verify: bool = True,
|
|
106
|
+
chunk_size: int = 8192,
|
|
107
|
+
impersonate: Optional[str] = "chrome_150",
|
|
108
|
+
**kwargs: Any
|
|
109
|
+
) -> Dict[str, Any]:
|
|
110
|
+
with Session(verify=verify, timeout=timeout, impersonate=impersonate, **kwargs) as session:
|
|
111
|
+
return session.download_file(
|
|
112
|
+
url, save_path, headers=headers, cookies=cookies, chunk_size=chunk_size,
|
|
113
|
+
)
|