KeyisBClient-mmbp 0.0.0.1.1__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.
- KeyisBClient_mmbp/Client.py +114 -0
- KeyisBClient_mmbp/__init__.py +57 -0
- KeyisBClient_mmbp-0.0.0.1.1.dist-info/LICENSE +21 -0
- KeyisBClient_mmbp-0.0.0.1.1.dist-info/METADATA +16 -0
- KeyisBClient_mmbp-0.0.0.1.1.dist-info/RECORD +7 -0
- KeyisBClient_mmbp-0.0.0.1.1.dist-info/WHEEL +5 -0
- KeyisBClient_mmbp-0.0.0.1.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,114 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
import os
|
8
|
+
import httpx
|
9
|
+
from KeyisBLogging import logging
|
10
|
+
from KeyisBClient import Exceptions
|
11
|
+
from KeyisBClient.models import Request, Response
|
12
|
+
|
13
|
+
class Client:
|
14
|
+
def __init__(self):
|
15
|
+
self.protocols = {
|
16
|
+
'mmbp': {'versions': ['0.0.0.0.1']},
|
17
|
+
'mmbps': {'versions': ['0.0.0.0.1']}
|
18
|
+
}
|
19
|
+
crt_path = os.path.join(os.path.dirname(__file__), 'gw_certs', 'v0.0.1.crt')
|
20
|
+
self.__httpAsyncClient = httpx.AsyncClient(verify=crt_path, follow_redirects=True)
|
21
|
+
self.__httpClient = httpx.Client(verify=crt_path, follow_redirects=True)
|
22
|
+
|
23
|
+
|
24
|
+
async def requestAsync(self, request: Request) -> Response:
|
25
|
+
if request.dnsObject.host() is None:
|
26
|
+
logging.debug("No DNS record found")
|
27
|
+
raise Exceptions.DNS.InvalidDNSError()
|
28
|
+
|
29
|
+
request.url.hostname = request.dnsObject.host() # type: ignore
|
30
|
+
request.url.scheme = request.dnsObject.protocolInfo()['connection_protocol']
|
31
|
+
|
32
|
+
try:
|
33
|
+
response = await self.__httpAsyncClient.request(
|
34
|
+
method=request.method,
|
35
|
+
url=request.url.getUrl(),
|
36
|
+
content=request.content,
|
37
|
+
data=request.data,
|
38
|
+
files=request.files,
|
39
|
+
json=request.json,
|
40
|
+
params=request.params,
|
41
|
+
headers=request.headers,
|
42
|
+
cookies=request.cookies,
|
43
|
+
auth=request.auth,
|
44
|
+
follow_redirects=request.follow_redirects,
|
45
|
+
timeout=request.timeout,
|
46
|
+
extensions=request.extensions
|
47
|
+
)
|
48
|
+
return Response(
|
49
|
+
status_code=response.status_code,
|
50
|
+
headers=response.headers,
|
51
|
+
content=response.content,
|
52
|
+
text=response.text,
|
53
|
+
json=response.json(),
|
54
|
+
stream=response.aiter_bytes(),
|
55
|
+
request=request,
|
56
|
+
extensions=response.extensions,
|
57
|
+
history=None,
|
58
|
+
default_encoding=response.encoding or "utf-8"
|
59
|
+
)
|
60
|
+
except httpx.TimeoutException:
|
61
|
+
logging.debug("HTTPS request timed out")
|
62
|
+
raise Exceptions.ServerTimeoutError()
|
63
|
+
except httpx.ConnectError:
|
64
|
+
logging.debug("Failed to connect to server")
|
65
|
+
raise Exceptions.ErrorConnection()
|
66
|
+
except httpx.HTTPStatusError as e:
|
67
|
+
logging.debug(f"HTTP error occurred: {e.response.status_code} - {e.response.text}")
|
68
|
+
raise Exceptions.InvalidServerResponseError(message=f"Некорректный ответ от сервера: {e.response.status_code}")
|
69
|
+
except httpx.RequestError as e:
|
70
|
+
logging.debug(f"HTTPS request failed: {e}")
|
71
|
+
raise Exceptions.UnexpectedError(message=f"Неожиданная ошибка запроса HTTPS: {str(e)}")
|
72
|
+
|
73
|
+
def request(self, request: Request) -> Response:
|
74
|
+
try:
|
75
|
+
|
76
|
+
response = self.__httpClient.request(
|
77
|
+
method=request.method,
|
78
|
+
url=request.url.getUrl(),
|
79
|
+
content=request.content,
|
80
|
+
data=request.data,
|
81
|
+
files=request.files,
|
82
|
+
json=request.json,
|
83
|
+
params=request.params,
|
84
|
+
headers=request.headers,
|
85
|
+
cookies=request.cookies,
|
86
|
+
auth=request.auth,
|
87
|
+
follow_redirects=request.follow_redirects,
|
88
|
+
timeout=request.timeout,
|
89
|
+
extensions=request.extensions
|
90
|
+
)
|
91
|
+
return Response(
|
92
|
+
status_code=response.status_code,
|
93
|
+
headers=response.headers,
|
94
|
+
content=response.content,
|
95
|
+
text=response.text,
|
96
|
+
json=response.json(),
|
97
|
+
stream=response.aiter_bytes(),
|
98
|
+
request=request,
|
99
|
+
extensions=response.extensions,
|
100
|
+
history=None,
|
101
|
+
default_encoding=response.encoding or "utf-8"
|
102
|
+
)
|
103
|
+
except httpx.TimeoutException:
|
104
|
+
logging.debug("HTTPS request timed out")
|
105
|
+
raise Exceptions.ServerTimeoutError()
|
106
|
+
except httpx.ConnectError:
|
107
|
+
logging.debug("Failed to connect to server")
|
108
|
+
raise Exceptions.ErrorConnection()
|
109
|
+
except httpx.HTTPStatusError as e:
|
110
|
+
logging.debug(f"HTTP error occurred: {e.response.status_code} - {e.response.text}")
|
111
|
+
raise Exceptions.InvalidServerResponseError(message=f"Некорректный ответ от сервера: {e.response.status_code}")
|
112
|
+
except httpx.RequestError as e:
|
113
|
+
logging.debug(f"HTTPS request failed: {e}")
|
114
|
+
raise Exceptions.UnexpectedError(message=f"Неожиданная ошибка запроса HTTPS: {str(e)}")
|
@@ -0,0 +1,57 @@
|
|
1
|
+
"""
|
2
|
+
GW Client
|
3
|
+
************
|
4
|
+
|
5
|
+
- mmbp
|
6
|
+
|
7
|
+
- mmbps
|
8
|
+
|
9
|
+
*created by KeyisB*
|
10
|
+
|
11
|
+
-==============================-
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
|
16
|
+
Copyright (C) 2024 KeyisB. All rights reserved.
|
17
|
+
|
18
|
+
Permission is hereby granted, free of charge, to any person
|
19
|
+
obtaining a copy of this software and associated documentation
|
20
|
+
files (the "Software"), to use the Software exclusively for
|
21
|
+
projects related to the MMB or GW systems, including personal,
|
22
|
+
educational, and commercial purposes, subject to the following
|
23
|
+
conditions:
|
24
|
+
|
25
|
+
1. Copying, modification, merging, publishing, distribution,
|
26
|
+
sublicensing, and/or selling copies of the Software are
|
27
|
+
strictly prohibited.
|
28
|
+
2. The licensee may use the Software only in its original,
|
29
|
+
unmodified form.
|
30
|
+
3. All copies or substantial portions of the Software must
|
31
|
+
remain unaltered and include this copyright notice and these terms of use.
|
32
|
+
4. Use of the Software for projects not related to GW or
|
33
|
+
MMB systems is strictly prohibited.
|
34
|
+
|
35
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
36
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
37
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR
|
38
|
+
A PARTICULAR PURPOSE, AND NON-INFRINGEMENT. IN NO EVENT
|
39
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
40
|
+
CLAIM, DAMAGES, OR OTHER LIABILITY, WHETHER IN AN ACTION
|
41
|
+
OF CONTRACT, TORT, OR OTHERWISE, ARISING FROM, OUT OF, OR
|
42
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
43
|
+
DEALINGS IN THE SOFTWARE.
|
44
|
+
"""
|
45
|
+
__GW_VERSION__ = "0.0.0.0.4"
|
46
|
+
__version__ = "1.4.0.0.12"
|
47
|
+
|
48
|
+
__all__ = [
|
49
|
+
"Client"
|
50
|
+
]
|
51
|
+
|
52
|
+
from .Client import Client
|
53
|
+
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
|
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 KeyisB
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Metadata-Version: 2.1
|
2
|
+
Name: KeyisBClient-mmbp
|
3
|
+
Version: 0.0.0.1.1
|
4
|
+
Summary: KeyisBClient-mmbp
|
5
|
+
Home-page: https://github.com/KeyisB/libs/tree/main/KeyisBClient-mmbp
|
6
|
+
Author: KeyisB
|
7
|
+
Author-email: keyisb.pip@gmail.com
|
8
|
+
License: MMB License v1.0
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
10
|
+
Classifier: Operating System :: OS Independent
|
11
|
+
Requires-Python: >=3.12
|
12
|
+
Description-Content-Type: text/markdown
|
13
|
+
License-File: LICENSE
|
14
|
+
Requires-Dist: KeyisBClient
|
15
|
+
Requires-Dist: httpx
|
16
|
+
|
@@ -0,0 +1,7 @@
|
|
1
|
+
KeyisBClient_mmbp/Client.py,sha256=T2txfnghEyp_uWZuGFpnVxhS38Bc2slvhsC8oqIcgGU,4937
|
2
|
+
KeyisBClient_mmbp/__init__.py,sha256=y8gLgE6Z2VvJFPnXGVeO7P_OYRoRZufvurQrR5RG1jg,1562
|
3
|
+
KeyisBClient_mmbp-0.0.0.1.1.dist-info/LICENSE,sha256=WH_t7dKZyWJ5Ld07eYIkUG4Tv6zZWXtAdsUqYAUesn0,1084
|
4
|
+
KeyisBClient_mmbp-0.0.0.1.1.dist-info/METADATA,sha256=x-nR550PJ-5vj_z3okrYRwJDP8zaU4IOX_fH-brBNVk,485
|
5
|
+
KeyisBClient_mmbp-0.0.0.1.1.dist-info/WHEEL,sha256=P9jw-gEje8ByB7_hXoICnHtVCrEwMQh-630tKvQWehc,91
|
6
|
+
KeyisBClient_mmbp-0.0.0.1.1.dist-info/top_level.txt,sha256=h6s4YlLhQ13xiqaDqhXJamhuez9D23BmPTwQvMr54FA,18
|
7
|
+
KeyisBClient_mmbp-0.0.0.1.1.dist-info/RECORD,,
|
@@ -0,0 +1 @@
|
|
1
|
+
KeyisBClient_mmbp
|