reqrio 0.0.4__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.
reqrio/__init__.py ADDED
@@ -0,0 +1,203 @@
1
+ import json
2
+ import os
3
+ from ctypes import *
4
+ from enum import Enum
5
+
6
+ from reqrio.response import Response
7
+
8
+
9
+ def _load_dll() -> CDLL:
10
+ base = os.path.dirname(__file__)
11
+ dll_path = os.path.join(base, 'reqrio.dll')
12
+ os.add_dll_directory(base)
13
+ return cdll.LoadLibrary(dll_path)
14
+
15
+
16
+ class ALPN(Enum):
17
+ HTTP10 = "http/1.0"
18
+ HTTP11 = "http/1.1"
19
+ HTTP20 = "h2"
20
+
21
+
22
+ class Session:
23
+ # alpn值是字符串['http/1.1','h2']
24
+ def __init__(self, alpn: ALPN = ALPN.HTTP11):
25
+ self.dll = _load_dll()
26
+ # self.dll = cdll.LoadLibrary(r"D:\projects\rust\reqrio\target\debug\reqrio.dll")
27
+ # 初始化函数
28
+ self.dll.init_http.restype = c_int
29
+
30
+ self.dll.set_header_json.argtypes = [c_int, c_char_p]
31
+ self.dll.set_header_json.restype = c_int
32
+
33
+ self.dll.add_header.argtypes = [c_int, c_char_p, c_char_p]
34
+ self.dll.add_header.restype = c_int
35
+
36
+ self.dll.set_alpn.argtypes = [c_int, c_char_p]
37
+ self.dll.set_alpn.restype = c_int
38
+
39
+ self.dll.set_fingerprint.argtypes = [c_int, c_char_p]
40
+ self.dll.set_fingerprint.restype = c_int
41
+
42
+ self.dll.set_ja3.argtypes = [c_int, c_char_p]
43
+ self.dll.set_ja3.restype = c_int
44
+
45
+ self.dll.set_proxy.argtypes = [c_int, c_char_p]
46
+ self.dll.set_proxy = c_int
47
+
48
+ self.dll.set_url.argtypes = [c_int, c_char_p]
49
+ self.dll.set_url.restype = c_int
50
+
51
+ self.dll.set_data.argtypes = [c_int, c_char_p]
52
+ self.dll.set_data.restype = c_int
53
+
54
+ self.dll.set_json.argtypes = [c_int, c_char_p]
55
+ self.dll.set_json.restype = c_int
56
+
57
+ self.dll.add_param.argtypes = [c_int, c_char_p]
58
+ self.dll.add_param.restype = c_int
59
+
60
+ self.dll.get.argtypes = [c_int]
61
+ self.dll.get.restype = c_void_p
62
+
63
+ self.dll.post.argtypes = [c_int]
64
+ self.dll.post.restype = c_void_p
65
+
66
+ self.dll.options.argtypes = [c_int]
67
+ self.dll.options.restype = c_void_p
68
+
69
+ self.dll.put.argtypes = [c_int]
70
+ self.dll.put.restype = c_void_p
71
+
72
+ self.dll.head.argtypes = [c_int]
73
+ self.dll.head.restype = c_void_p
74
+
75
+ self.dll.trach.argtypes = [c_int]
76
+ self.dll.trach.restype = c_void_p
77
+
78
+ self.dll.destroy.argtypes = [c_int]
79
+
80
+ self.dll.free_pointer.argtypes = [c_void_p]
81
+
82
+ self.hid = self.dll.init_http()
83
+ if self.hid == -1: raise Exception('init fail')
84
+ r = self.dll.set_alpn(self.hid, alpn.value.encode('utf-8'))
85
+ if r == -1: raise Exception('set alpn error')
86
+
87
+ def set_header_json(self, header: dict):
88
+ r = self.dll.set_header_json(self.hid, json.dumps(header).encode('utf-8'))
89
+ if r == -1: raise Exception('set header error')
90
+
91
+ def add_header(self, name: str, value: str):
92
+ r = self.dll.set_header_json(self.hid, name.encode('utf-8'), value.encode('utf-8'))
93
+ if r == -1: raise Exception('add header error')
94
+
95
+ def set_fingerprint(self, fingerprint: str):
96
+ """指纹数据,是tls握手过程中客户端发出的数据(转十六进制),包含:
97
+
98
+ 1.client_hello
99
+
100
+ 2.client_key_exchange
101
+
102
+ 3.change_cipher_spec"""
103
+ r = self.dll.set_fingerprint(self.hid, fingerprint.encode('utf-8'))
104
+ if r == -1: raise Exception('set fingerprint error')
105
+
106
+ def set_ja3(self, ja3: str):
107
+ r = self.dll.set_ja3(self.hid, ja3.encode('utf-8'))
108
+ if r == -1: raise Exception('set ja3 error')
109
+
110
+ def set_proxy(self, proxy: str):
111
+ """设置代理,格式:http://127.0.0.1:10000、socks5://127.0.0.1:10001"""
112
+ r = self.dll.set_proxy(self.hid, proxy.encode('utf-8'))
113
+ if r == -1: raise Exception('set proxy error')
114
+
115
+ def set_url(self, url: str):
116
+ r = self.dll.set_url(self.hid, url.encode('utf-8'))
117
+ if r == -1: raise Exception('set url error')
118
+
119
+ def set_data(self, data: dict):
120
+ r = self.dll.set_data(self.hid, json.dumps(data).encode('utf-8'))
121
+ if r == -1: raise Exception('set data error')
122
+
123
+ def set_json(self, data: dict):
124
+ r = self.dll.set_json(self.hid, json.dumps(data).encode('utf-8'))
125
+ if r == -1: raise Exception('set json error')
126
+
127
+ def add_param(self, name: str, value: str):
128
+ r = self.dll.add_param(self.hid, name.encode('utf-8'), value.encode('utf-8'))
129
+ if r == -1: raise Exception('add param error')
130
+
131
+ def get(self) -> Response:
132
+ resp = self.dll.get(self.hid)
133
+ bs = string_at(resp).decode('utf-8')
134
+ self.dll.free_pointer(resp)
135
+ try:
136
+ resp = json.loads(bytes.fromhex(bs))
137
+ return Response(resp)
138
+ except Exception as _:
139
+ raise Exception(bs)
140
+
141
+ def post(self) -> Response:
142
+ resp = self.dll.post(self.hid)
143
+ bs = string_at(resp).decode('utf-8')
144
+ self.dll.free_pointer(resp)
145
+ try:
146
+ resp = json.loads(bytes.fromhex(bs))
147
+ return Response(resp)
148
+ except Exception as _:
149
+ raise Exception(bs)
150
+
151
+ def options(self) -> Response:
152
+ resp = self.dll.options(self.hid)
153
+ bs = string_at(resp).decode('utf-8')
154
+ self.dll.free_pointer(resp)
155
+ try:
156
+ resp = json.loads(bytes.fromhex(bs))
157
+ return Response(resp)
158
+ except Exception as _:
159
+ raise Exception(bs)
160
+
161
+ def put(self) -> Response:
162
+ resp = self.dll.put(self.hid)
163
+ bs = string_at(resp).decode('utf-8')
164
+ self.dll.free_pointer(resp)
165
+ try:
166
+ resp = json.loads(bytes.fromhex(bs))
167
+ return Response(resp)
168
+ except Exception as _:
169
+ raise Exception(bs)
170
+
171
+ def head(self) -> Response:
172
+ resp = self.dll.head(self.hid)
173
+ bs = string_at(resp).decode('utf-8')
174
+ self.dll.free_pointer(resp)
175
+ try:
176
+ resp = json.loads(bytes.fromhex(bs))
177
+ return Response(resp)
178
+ except Exception as _:
179
+ raise Exception(bs)
180
+
181
+ def delete(self) -> Response:
182
+ resp = self.dll.delete(self.hid)
183
+ bs = string_at(resp).decode('utf-8')
184
+ self.dll.free_pointer(resp)
185
+ try:
186
+ resp = json.loads(bytes.fromhex(bs))
187
+ return Response(resp)
188
+ except Exception as _:
189
+ raise Exception(bs)
190
+
191
+ def trach(self) -> Response:
192
+ resp = self.dll.trach(self.hid)
193
+ bs = string_at(resp).decode('utf-8')
194
+ self.dll.free_pointer(resp)
195
+ try:
196
+ resp = json.loads(bytes.fromhex(bs))
197
+ return Response(resp)
198
+ except Exception as _:
199
+ raise Exception(bs)
200
+
201
+ def close(self):
202
+ """记得关闭资源,否则容易造成内存溢出"""
203
+ self.dll.destroy(self.hid)
reqrio/header.py ADDED
@@ -0,0 +1,36 @@
1
+ class Cookie:
2
+ def __init__(self, cookie: dict):
3
+ self.cookie = cookie['name']
4
+ self.value = cookie['value']
5
+ self.age = cookie['age']
6
+ self.domain = cookie['domain']
7
+ self.path = cookie['path']
8
+ self.httpOnly = cookie['http_only']
9
+ self.secure = cookie['secure']
10
+ self.expires = cookie['expires']
11
+ self.sameSite = cookie['same_site']
12
+ self.icpsp = cookie['icpsp']
13
+ del cookie
14
+ return
15
+
16
+
17
+ class Header:
18
+ def __init__(self, header: dict):
19
+ self.uri = header["uri"]
20
+ self.method = header["method"]
21
+ self.status = header["status"]
22
+ self.agreement = header["agreement"]
23
+ self.keys: dict = header["keys"]
24
+ self.cookies = []
25
+ for cookie in self.keys.get('set-cookie', []):
26
+ self.cookies.append(Cookie(cookie))
27
+ del header
28
+ if self.keys.get("set-cookie") is not None:
29
+ del self.keys['set-cookie']
30
+ return
31
+
32
+ def get(self, key: str):
33
+ return self.keys.get(key, None)
34
+
35
+ def location(self):
36
+ return self.keys.get("location")
reqrio/reqrio.dll ADDED
Binary file
reqrio/response.py ADDED
@@ -0,0 +1,18 @@
1
+ import json
2
+
3
+ from reqrio.header import Header
4
+
5
+
6
+ class Response:
7
+ def __init__(self, resp: dict):
8
+ self.header = Header(resp["header"])
9
+ self.raw = bytes.fromhex(resp["body"])
10
+ del resp
11
+ return
12
+
13
+ def json(self) -> dict:
14
+ return json.loads(self.raw.decode('utf-8'))
15
+
16
+ def text(self) -> str:
17
+ return self.raw.decode('utf-8')
18
+
@@ -0,0 +1,55 @@
1
+ Metadata-Version: 2.4
2
+ Name: reqrio
3
+ Version: 0.0.4
4
+ Summary: A http lib
5
+ Author-email: xllgl2017 <xinlanxi2017@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/xllgl2017/reqrio
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+
11
+ #### hls是http请求库,目标是可以使用rust快速、简单、便捷使用http请求
12
+
13
+ * hls支持tls指纹,可以通过tls握手的十六禁止或ja3设置,仅cls_sync和cls_async支持,例如:
14
+
15
+ ```python
16
+ import reqrio
17
+
18
+ # 默认使用http/1.1
19
+ # * 同一个Session使用同一个tcp连接,断开时会默认字段重连
20
+ session = reqrio.Session(alpn=reqrio.ALPN.HTTP20)
21
+ tls_fingerprint = "16030106b2010006ae0303f0aed3d4d9fac0e8d4ff98981a90257765d203b4ce089c591e86d8e7ec8ab90a204803c2150a14429bfe6536328fe11cfd4034264fa2a3a443c5972eeeb93d427100206a6a130113021303c02bc02fc02cc030cca9cca8c013c014009c009d002f0035010006453a3a000000230000001b0003020002ff010001000000000e000c0000093338686d7a672e636e0005000501000000000017000044cd00050003026832fe0d00ba00000100010900208e3fc249e1ce71ff4aefb0970b38167b6b7de98537b874130ba4e284e15f1c4f00909540fc3a77fcc8f96d51ff9144785ccf114d3618d9a77b0e88f54d4dd1279083483e0ad83a4f25e55951194048709bf0842651d940c291569b9cfe1323d6fc2d31348ccaaa7b79271fc41af0975d94f7a826819154e05f6f90bdaa4e2b215894ccd36f748ded2bcae0a61aa101a7187588c2b45b51d076356d0e47728974d6d1cdd2b3ce4a8e5e8f70a79fb8f288c868000b00020100002d00020101000a000c000a3a3a11ec001d00170018001200000010000e000c02683208687474702f312e31003304ef04ed3a3a00010011ec04c05b20439ba8b50e3a5800981889512ab253cd2f1ba1488613fbd79f43813c08e34ed45330a62991a6b37890d54d2d0c089251b146acace84512c031c74ac6a2ac6345b6668629aa143357b45921916de02ac5cc8d57e1ca9882ccad900640a1b51c587de3291a2f15ad67e180b79b442fe4606de978f7a27591a41ffcd91116c50703c45531999c9d377a173c249ef747a60a81158c0d3ef709b9b5a38af61b6b5c9740c343f7322b6510a60797cb39148ba310413b688354bb0b2e395dbf3935fd0a797d7b5e94acab23a95c163238dd1bc9b8b420599a0efd4726e85a0783fc8506436c3eb89ee96008b0c9c5a2047a2415bbb5a2768d7c8d58384644d5473de96721b24a3fc82ee68cc0a3a43cc73467ec515a3ac1a79b9070f4e4aad61ac50c7b4e9b125f66cba026807cdad5a43e4a5cfa2ac521801616bb58ea068689c15afd4592b26545c3a8c638800a3429c32237a902f1a605458935391c4d352a211cb2122203f9ea38e3d44b29741502bb57c7850ffaf36ab0db72ac9c0fc0ba309661096bc550d86b442beca080c0602e02a54ed2171e58b0b82582c568a5b1407d8d35448cf907a43575aed4c5371595d1456f29778c892325d4d785a3a384a30b838e6b0d59990ca54ba52369c4faf835a2f50cbd504f7d38cdc4047bf7acae92090cf121180096a513dc4cadf290641ab6e4375aa477395b8902b74c39e62b945a09438d83b1d41ac2f204c4614425bed86e221c60c8520e1c3233e5ccb53c228c0d525fb7823d9d9c4337e36785eb61590794f9565b3dd2722a2834b536be157a307d928d7f910167a314b8705bdddc1b4c9c139a5320380910b1263b40a6c6065c84266a2c036a19d3a51f5edbb8eaf3cb1e8295ef1ab978f5306da9b11a5a3df473bbd2acca084a4c4bba0bc478630283b0e6910bde3052c6f58300703a6e9524381b4cc1b247236acc1c0bae6cb69c463c29811b04d93a589ba36d30c9b4d1fb234368a9b3e94abaf419a220af730917488bc9be585f7111c9a13a8544969bf3e397b1f2ceba0ca7f21785531a3f7856248f54a5bd854124b21e1e75c366e8b5293130bdb902db0a05e9803c3d7827d5cc26046815102c3713b4a14ef63aed3163319244995a6524dbabfaf93ed8a95e08641377683dd6b3b05084bf48f77d47904d09656d4a19b457d84bcfd77a4c433393bbb43f09931cf4896cf891990c9363202467b6193ea6b8bd493733235c93c118feb808b1d9b38cc7862c744342e2baeeec6299d0a21898aa9576ae61b2703a5b072521166f6693aa4b5e6148ad4e7c21a21a7972a0c8c3f986e95392ed2b15e51a5f2e5b90e4766320513e3bfa4d67688fb6c547147c47aa71c04095336b11b32b52a6c9d047a1357eece2688efb2045184653a480ef15a3fb8c4851d8c0407b24a87b55fd36af59b18fff38b183b6256e15c161395a46f62ce1b0af240319dec84d3aa04e2773ac289b393160683e901b2b622d615b2719b06cc12bae79fca101e737a91434c8e0828cc6a71b740216964a06a9952d9c54f24743b1b9c4fc9475554aa8a87719ccd7ae40374c87d8018937c7b6007e028b348e884d201087416396ec3237b61319e0f40e436a6a1dc75f2486a68c60c27f719d251a9d73b3de3bd91858d3f3d4043384f7ad42422b47b96bdd03b5556f8107232953dad801970157aa95971638e2908d55001d0020552cb65392fdab1ff61dd3b43c895fdf782c61bb6f05519f2b7d9e28facfd25e000d0012001004030804040105030805050108060601002b000706dada030403031a1a0001001603030046100000424104ff635373fbbfbc37444a2026372f57fd06c5205bacfe32b61261a9d29bf1fca57f91ef22cb2ba46af8cf9ae7c3123f56634099af297dcd30835cd81664005fb9140303000101"
22
+ session.set_fingerprint(tls_fingerprint)
23
+ # session.set_ja3("771,4865-4866-4867-49195-49199-49196-49200-52393-52392-49171-49172-156-157-47-53,45-11-5-51-0-43-10-35-27-17513-23-65037-16-18-13-65281,4588-29-23-24,0")
24
+ headers = {
25
+ "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
26
+ "Accept-Encoding": "gzip, deflate, br, zstd",
27
+ "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6",
28
+ "Cache-Control": "no-cache",
29
+ "Connection": "keep-alive",
30
+ # "Cookie": "__guid=15015764.1071255116101212729.1764940193317.2156; env_webp=1; _S=pvc5q7leemba50e4kn4qis4b95; QiHooGUID=4C8051464B2D97668E3B21198B9CA207.1766289287750; count=1; so-like-red=2; webp=1; so_huid=114r0SZFiQcJKtA38GZgwZg%2Fdit1cjUGuRcsIL2jTn4%2FE%3D; __huid=114r0SZFiQcJKtA38GZgwZg%2Fdit1cjUGuRcsIL2jTn4%2FE%3D; gtHuid=1",
31
+ "Host": "m.so.com",
32
+ "Pragma": "no-cache",
33
+ "Sec-Fetch-Dest": "document",
34
+ "Sec-Fetch-Mode": "navigate",
35
+ "Sec-Fetch-Site": "none",
36
+ "Sec-Fetch-User": "?1",
37
+ "Upgrade-Insecure-Requests": 1,
38
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0",
39
+ "sec-ch-ua": '"Microsoft Edge";v="143", "Chromium";v="143", "Not A(Brand";v="24"',
40
+ "sec-ch-ua-mobile": "?0",
41
+ "sec-ch-ua-platform": '"Windows"'
42
+ }
43
+ # 默认没有任何请求头,需要自己设置
44
+ session.set_header_json(headers)
45
+ session.set_url('https://m.so.com')
46
+ resp = session.get()
47
+ # 获取响应头
48
+ print(resp.header.__dict__)
49
+ # 获取响应体
50
+ print(resp.text())
51
+ # 尝试解码到json
52
+ print(resp.json())
53
+ # 关闭连接资源,记得调用
54
+ session.close()
55
+ ```
@@ -0,0 +1,8 @@
1
+ reqrio/__init__.py,sha256=a8hG8xVX-BvVN6_qsNf0jQQqVg5P13KbtRbERlhQRL8,6837
2
+ reqrio/header.py,sha256=c_-4RD2HTKEzqvJAJe5YcmI99gMvKQRK60wRlTLgIHg,1150
3
+ reqrio/reqrio.dll,sha256=5Hqq7PctaJp6P7jkgt-zZTTSnV6SDRfhXAWJAjOHhzc,5641216
4
+ reqrio/response.py,sha256=WWUtclKL5tuYj8Ffl51LDnC7Ne9DXppw8PDgVcjmQ98,392
5
+ reqrio-0.0.4.dist-info/METADATA,sha256=5jW-ojj68PeH2Mx9VxCu2o4Fu1xXH02TMAMBND90GyU,6068
6
+ reqrio-0.0.4.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
7
+ reqrio-0.0.4.dist-info/top_level.txt,sha256=sar8YfIK_Wd3CptOLKnaoeAfu2pUllgPE5hz433K0hw,7
8
+ reqrio-0.0.4.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ reqrio