tls-client-python 1.16.0.1__py3-none-win_arm64.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.
tls_client/__init__.py ADDED
@@ -0,0 +1,81 @@
1
+ """
2
+ tls_client – High-performance Python binding for
3
+ github.com/bogdanfinn/tls-client via CFFI + platform-native shared library.
4
+
5
+ The package auto‑detects the host OS and architecture at import time,
6
+ selecting the correct pre‑compiled binary from the bundled ``bin/``
7
+ directory. A ``TLS_CLIENT_LIB`` environment variable may be used to
8
+ override automatic discovery.
9
+ """
10
+
11
+ from tls_client._core import (
12
+ AsyncSession,
13
+ ClientIdentifiers,
14
+ SUPPORTED_CLIENT_IDENTIFIERS,
15
+ clear_client_pool,
16
+ )
17
+ from tls_client._core import Request as TLSRequest
18
+ from tls_client._core import Response as NativeResponse
19
+ from tls_client._core import Session as NativeSession
20
+ from tls_client.requests_compat import (
21
+ PreparedRequest,
22
+ Request,
23
+ Response,
24
+ Session,
25
+ TLSClientAdapter,
26
+ delete,
27
+ get,
28
+ head,
29
+ options,
30
+ patch,
31
+ post,
32
+ put,
33
+ request,
34
+ )
35
+
36
+ from tls_client import adapters, auth, cookies, exceptions, models, status_codes, structures
37
+ from tls_client import context as request_context
38
+ from tls_client import ech, fingerprints
39
+ from tls_client import fingerprints
40
+ from tls_client._multipart_boundary import blink_boundary, boundary, gecko_boundary
41
+ from tls_client.context import RequestContext
42
+ from tls_client.status_codes import codes
43
+
44
+ __all__ = [
45
+ "Session",
46
+ "AsyncSession",
47
+ "Request",
48
+ "PreparedRequest",
49
+ "Response",
50
+ "TLSClientAdapter",
51
+ "NativeSession",
52
+ "NativeResponse",
53
+ "TLSRequest",
54
+ "ClientIdentifiers",
55
+ "SUPPORTED_CLIENT_IDENTIFIERS",
56
+ "clear_client_pool",
57
+ "request",
58
+ "get",
59
+ "options",
60
+ "head",
61
+ "post",
62
+ "put",
63
+ "patch",
64
+ "delete",
65
+ "adapters",
66
+ "auth",
67
+ "codes",
68
+ "cookies",
69
+ "exceptions",
70
+ "ech",
71
+ "fingerprints",
72
+ "models",
73
+ "request_context",
74
+ "RequestContext",
75
+ "blink_boundary",
76
+ "boundary",
77
+ "gecko_boundary",
78
+ "status_codes",
79
+ "structures",
80
+ ]
81
+ __version__ = "1.16.0.1"
@@ -0,0 +1,162 @@
1
+ """High-entropy Client Hints for Chromium-family browsers.
2
+
3
+ Chrome emits these only after a host advertises ``Accept-CH`` (and the user
4
+ opts in), but impersonation libraries ship them so the header block is
5
+ complete and coherent when the target expects them. Values mirror Chromium
6
+ (verified against httpcloak's captured header logic):
7
+
8
+ - ``sec-ch-ua-full-version-list`` — each brand's exact build for real brands,
9
+ ``<major>.0.0.0`` for the GREASE brand;
10
+ - ``sec-ch-ua-platform-version`` / ``-arch`` / ``-bitness`` / ``-model`` /
11
+ ``-wow64`` — per-platform defaults.
12
+
13
+ The exact builds come from live handshakes (``tools/_chrome_captures.json``).
14
+ """
15
+
16
+ from typing import Dict
17
+
18
+ # Exact Chrome build per major, captured from live handshakes.
19
+ CHROME_FULL_VERSIONS: Dict[int, str] = {
20
+ 99: "99.0.4844.84",
21
+ 100: "100.0.4896.127",
22
+ 101: "101.0.4951.67",
23
+ 102: "102.0.5005.115",
24
+ 103: "103.0.5060.134",
25
+ 104: "104.0.5112.102",
26
+ 105: "105.0.5195.127",
27
+ 106: "106.0.5249.119",
28
+ 107: "107.0.5304.122",
29
+ 108: "108.0.5359.125",
30
+ 109: "109.0.5414.120",
31
+ 110: "110.0.5481.178",
32
+ 111: "111.0.5563.147",
33
+ 112: "112.0.5615.138",
34
+ 113: "113.0.5672.127",
35
+ 114: "114.0.5735.199",
36
+ 115: "115.0.5790.171",
37
+ 116: "116.0.5845.188",
38
+ 117: "117.0.5938.150",
39
+ 118: "118.0.5993.118",
40
+ 119: "119.0.6045.200",
41
+ 120: "120.0.6099.225",
42
+ 121: "121.0.6167.185",
43
+ 122: "122.0.6261.129",
44
+ 123: "123.0.6312.123",
45
+ 124: "124.0.6367.208",
46
+ 125: "125.0.6422.142",
47
+ 126: "126.0.6478.183",
48
+ 127: "127.0.6533.120",
49
+ 128: "128.0.6613.138",
50
+ 129: "129.0.6668.101",
51
+ 130: "130.0.6723.117",
52
+ 131: "131.0.6778.265",
53
+ 132: "132.0.6834.160",
54
+ 133: "133.0.6943.142",
55
+ 134: "134.0.6998.178",
56
+ 135: "135.0.7049.115",
57
+ 136: "136.0.7103.114",
58
+ 137: "137.0.7151.120",
59
+ 138: "138.0.7204.184",
60
+ 139: "139.0.7258.155",
61
+ 140: "140.0.7339.208",
62
+ 141: "141.0.7390.123",
63
+ 142: "142.0.7444.176",
64
+ 143: "143.0.7499.193",
65
+ 144: "144.0.7559.133",
66
+ 145: "145.0.7632.160",
67
+ 146: "146.0.7680.178",
68
+ 147: "147.0.7727.138",
69
+ 148: "148.0.7778.168",
70
+ 149: "149.0.7827.201",
71
+ 150: "150.0.7871.187",
72
+ 151: "151.0.7922.174",
73
+ 152: "152.0.7977.83",
74
+ 153: "153.0.8010.37",
75
+ }
76
+
77
+ # Brands that carry the real build; everything else is the GREASE token.
78
+ _REAL_BRANDS = {"Chromium", "Google Chrome", "Microsoft Edge", "Brave", "Opera"}
79
+
80
+ # Per-platform defaults, mirroring Chromium (httpcloak-verified).
81
+ PLATFORM_VERSION: Dict[str, str] = {
82
+ "windows": '"15.0.0"',
83
+ "macos": '"14.5.0"',
84
+ "linux": '""',
85
+ "android": '"14.0.0"',
86
+ "ios": '""',
87
+ }
88
+
89
+ PLATFORM_ARCH: Dict[str, str] = {
90
+ "windows": '"x86"',
91
+ "macos": '"arm"',
92
+ "linux": '"x86"',
93
+ "android": '""',
94
+ "ios": '""',
95
+ }
96
+
97
+
98
+ def full_version_for(major: int) -> str:
99
+ """Return the exact Chrome build for *major*, or a ``<major>.0.0.0`` fallback."""
100
+ return CHROME_FULL_VERSIONS.get(int(major), "%d.0.0.0" % int(major))
101
+
102
+
103
+ def full_version_list(sec_ch_ua: str, full_version: str) -> str:
104
+ """Expand a low-entropy ``sec-ch-ua`` into ``sec-ch-ua-full-version-list``.
105
+
106
+ Brand names, order and the GREASE token are preserved verbatim. When
107
+ *full_version* is given, real brands get the exact build while the GREASE
108
+ brand keeps its major expanded to ``<major>.0.0.0``; when it is empty,
109
+ every brand is expanded to ``<major>.0.0.0`` (the ``ua_full_version=None``
110
+ fallback of ``context.expand_client_hints``). Example::
111
+
112
+ "Chromium";v="99", "Not?A_Brand";v="24", "Google Chrome";v="99"
113
+
114
+ becomes (with ``full_version="99.0.4844.84"``)::
115
+
116
+ "Chromium";v="99.0.4844.84", "Not?A_Brand";v="24.0.0.0",
117
+ "Google Chrome";v="99.0.4844.84"
118
+ """
119
+ out = []
120
+ for part in sec_ch_ua.split(","):
121
+ part = part.strip()
122
+ if not part:
123
+ continue
124
+ brand, sep, ver = part.partition(";v=")
125
+ brand = brand.strip().strip('"')
126
+ ver = ver.strip().strip('"')
127
+ if not sep:
128
+ out.append(part)
129
+ elif not ver or "." in ver:
130
+ out.append(part) # empty or already a full version — leave as-is
131
+ elif full_version and brand in _REAL_BRANDS:
132
+ out.append('"%s";v="%s"' % (brand, full_version))
133
+ else:
134
+ out.append('"%s";v="%s.0.0.0"' % (brand, ver))
135
+ return ", ".join(out)
136
+
137
+
138
+ def high_entropy_hints(platform: str, sec_ch_ua: str, full_version: str) -> Dict[str, str]:
139
+ """Return the six high-entropy Client Hints for a Chromium platform."""
140
+ platform = (platform or "").lower()
141
+ is_mobile = platform in ("android", "ios")
142
+ return {
143
+ "sec-ch-ua-full-version-list": full_version_list(sec_ch_ua, full_version),
144
+ "sec-ch-ua-platform-version": PLATFORM_VERSION.get(platform, '""'),
145
+ "sec-ch-ua-arch": PLATFORM_ARCH.get(platform, '""'),
146
+ "sec-ch-ua-bitness": '""' if is_mobile else '"64"',
147
+ "sec-ch-ua-model": '""',
148
+ "sec-ch-ua-wow64": "?0",
149
+ }
150
+
151
+
152
+ # Wire order Chromium uses when it emits the high-entropy block, following the
153
+ # low-entropy trio. Kept here so both the preset generator and the default
154
+ # headers use one canonical order.
155
+ HIGH_ENTROPY_ORDER = [
156
+ "sec-ch-ua-platform-version",
157
+ "sec-ch-ua-arch",
158
+ "sec-ch-ua-bitness",
159
+ "sec-ch-ua-model",
160
+ "sec-ch-ua-full-version-list",
161
+ "sec-ch-ua-wow64",
162
+ ]