cloudoll 3.0.1__tar.gz → 3.0.3__tar.gz
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.
- {cloudoll-3.0.1 → cloudoll-3.0.3}/PKG-INFO +1 -1
- cloudoll-3.0.3/cloudoll/__init__.py +1 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/cli.py +1 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/clitool/m2d.py +5 -2
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/clitool/process.py +23 -7
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/clitool/watch.py +2 -2
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/utils/common.py +2 -3
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/web/core.py +1 -1
- cloudoll-3.0.3/cloudoll/web/requests.py +86 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll.egg-info/PKG-INFO +1 -1
- {cloudoll-3.0.1 → cloudoll-3.0.3}/pyproject.toml +1 -1
- cloudoll-3.0.1/cloudoll/__init__.py +0 -1
- cloudoll-3.0.1/cloudoll/web/requests.py +0 -159
- {cloudoll-3.0.1 → cloudoll-3.0.3}/LICENSE +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/README.md +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/__main__.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/clitool/__init__.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/clitool/cli_main.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/clitool/spinner.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/logging/__init__.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/mail/__init__.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/mail/smtp.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/orm/__init__.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/orm/base.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/orm/err.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/orm/field.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/orm/model.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/orm/mysql.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/orm/parse.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/orm/postgres.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/template/__init__.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/utils/__init__.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/utils/snowflake.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/web/__init__.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/web/exception.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/web/html.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/web/jwt.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll/web/settings.py +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll.egg-info/SOURCES.txt +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll.egg-info/dependency_links.txt +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll.egg-info/entry_points.txt +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll.egg-info/requires.txt +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/cloudoll.egg-info/top_level.txt +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/setup.cfg +0 -0
- {cloudoll-3.0.1 → cloudoll-3.0.3}/setup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloudoll
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.3
|
|
4
4
|
Summary: Assist in quickly creating distributable microservices based on aiohttp, with a focus on simplicity and ease of use.
|
|
5
5
|
Home-page: https://github.com/smallerqiu/cloudoll-py
|
|
6
6
|
Author: Qiu
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "3.0.3"
|
|
@@ -27,7 +27,7 @@ async def create_model(pool, table_name) -> str:
|
|
|
27
27
|
tb = f"\nclass {snake_to_camel(table_name)}(Model):\n\n"
|
|
28
28
|
tb += f"\t__table__ = '{table_name}'\n\n"
|
|
29
29
|
for f in rows:
|
|
30
|
-
fields = get_col(f, pool.driver)
|
|
30
|
+
fields: dict = get_col(f, pool.driver)
|
|
31
31
|
# print("fields",fields)
|
|
32
32
|
name = fields["name"]
|
|
33
33
|
column_type = fields["column_type"]
|
|
@@ -193,7 +193,8 @@ async def create_tables(pool, model_name: str, tables: list):
|
|
|
193
193
|
else:
|
|
194
194
|
raise ImportError(f"Module {model_name} not found or invalid.")
|
|
195
195
|
|
|
196
|
-
|
|
196
|
+
|
|
197
|
+
def get_col(field, driver="mysql") -> dict:
|
|
197
198
|
if driver == "mysql":
|
|
198
199
|
fields = {
|
|
199
200
|
"name": field["Field"],
|
|
@@ -235,6 +236,8 @@ def get_col(field, driver="mysql"):
|
|
|
235
236
|
"comment": field["comment"],
|
|
236
237
|
}
|
|
237
238
|
return fields
|
|
239
|
+
else:
|
|
240
|
+
raise ValueError(f"Database {driver} not support.")
|
|
238
241
|
|
|
239
242
|
|
|
240
243
|
def get_col_sql(field):
|
|
@@ -27,10 +27,10 @@ class ProcessManager:
|
|
|
27
27
|
def get_run_dir():
|
|
28
28
|
home = Path.home()
|
|
29
29
|
if platform.system() == "Windows":
|
|
30
|
-
run_dir =
|
|
30
|
+
run_dir = home / f"AppData/Local/cloudoll"
|
|
31
31
|
else:
|
|
32
32
|
run_dir = home / f".cloudoll"
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
try:
|
|
35
35
|
run_dir.mkdir(parents=True, exist_ok=True, mode=0o700)
|
|
36
36
|
except (PermissionError, OSError):
|
|
@@ -41,7 +41,7 @@ class ProcessManager:
|
|
|
41
41
|
@staticmethod
|
|
42
42
|
def get_pid_path(name: str):
|
|
43
43
|
run_dir = ProcessManager.get_run_dir()
|
|
44
|
-
return run_dir / f"
|
|
44
|
+
return run_dir / f"{name}.pid"
|
|
45
45
|
|
|
46
46
|
@staticmethod
|
|
47
47
|
def save_pid(name: str, pid: int) -> None:
|
|
@@ -57,6 +57,7 @@ class ProcessManager:
|
|
|
57
57
|
|
|
58
58
|
@staticmethod
|
|
59
59
|
def safe_exit(service_name: str):
|
|
60
|
+
pid = 0
|
|
60
61
|
try:
|
|
61
62
|
pid = ProcessManager.get_running_pid(service_name)
|
|
62
63
|
if not pid:
|
|
@@ -111,8 +112,6 @@ class ProcessManager:
|
|
|
111
112
|
valid_identifiers = [
|
|
112
113
|
f"--name {service_name}",
|
|
113
114
|
f"-n {service_name}",
|
|
114
|
-
f"--name={service_name}",
|
|
115
|
-
f"-n={service_name}",
|
|
116
115
|
]
|
|
117
116
|
cmdline = " ".join(psutil.Process(os.getpid()).cmdline())
|
|
118
117
|
return (
|
|
@@ -205,7 +204,16 @@ class ProcessManager:
|
|
|
205
204
|
return
|
|
206
205
|
|
|
207
206
|
fmt = "{:<15} {:<8} {:<8} {:<12} {:<8} {:<10} {:<15}"
|
|
208
|
-
headers = [
|
|
207
|
+
headers = [
|
|
208
|
+
"Services",
|
|
209
|
+
"PID",
|
|
210
|
+
"Status",
|
|
211
|
+
"Env",
|
|
212
|
+
"RunTime",
|
|
213
|
+
"CPU%",
|
|
214
|
+
"Mem(MB)",
|
|
215
|
+
"Process",
|
|
216
|
+
]
|
|
209
217
|
rows = []
|
|
210
218
|
for pid_file in sorted(pid_dir.glob("*.pid")):
|
|
211
219
|
service = pid_file.stem
|
|
@@ -225,11 +233,19 @@ class ProcessManager:
|
|
|
225
233
|
uptime = datetime.now() - start_time
|
|
226
234
|
runtime = str(uptime).split(".")[0]
|
|
227
235
|
|
|
236
|
+
"env"
|
|
237
|
+
args = ProcessManager.load_start_args(service)
|
|
238
|
+
env_value = "-"
|
|
239
|
+
if "-env" in args:
|
|
240
|
+
index = args.index("-env")
|
|
241
|
+
if index + 1 < len(args):
|
|
242
|
+
env_value = args[index + 1]
|
|
228
243
|
rows.append(
|
|
229
244
|
[
|
|
230
245
|
service,
|
|
231
246
|
pid,
|
|
232
247
|
"🟢 Running",
|
|
248
|
+
env_value,
|
|
233
249
|
runtime,
|
|
234
250
|
f"{cpu_percent:.1f}",
|
|
235
251
|
f"{mem_mb:.1f}",
|
|
@@ -239,4 +255,4 @@ class ProcessManager:
|
|
|
239
255
|
except Exception as e:
|
|
240
256
|
rows.append([service, "???", "error", "-", "-", "-", str(e)])
|
|
241
257
|
|
|
242
|
-
click.echo(tabulate(rows, headers=headers, tablefmt="
|
|
258
|
+
click.echo(tabulate(rows, headers=headers, tablefmt="rounded_grid"))
|
|
@@ -19,7 +19,7 @@ from cloudoll.utils.common import check_port_open
|
|
|
19
19
|
|
|
20
20
|
class CloudollFilter(DefaultFilter):
|
|
21
21
|
def __init__(self, ignore_dirs: tuple = ()) -> None:
|
|
22
|
-
self.ignore_dirs = self.ignore_dirs + tuple("logs")
|
|
22
|
+
self.ignore_dirs: tuple = self.ignore_dirs + tuple("logs")
|
|
23
23
|
if ignore_dirs:
|
|
24
24
|
self.ignore_dirs = self.ignore_dirs + ignore_dirs
|
|
25
25
|
|
|
@@ -112,7 +112,7 @@ def mian_app(tty_path, config, entry, env):
|
|
|
112
112
|
|
|
113
113
|
async def create_main_app(config, entry, env):
|
|
114
114
|
await check_port_open(config["server"]["port"])
|
|
115
|
-
App = app.create(env=env, config=config, entry_model=entry)
|
|
115
|
+
App: Application = app.create(env=env, config=config, entry_model=entry)
|
|
116
116
|
return web.AppRunner(App.app, shutdown_timeout=0.1)
|
|
117
117
|
|
|
118
118
|
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import asyncio
|
|
2
2
|
from cloudoll.logging import warning
|
|
3
3
|
|
|
4
|
-
EADDRINUSE: int
|
|
5
|
-
|
|
6
4
|
|
|
7
5
|
class Object(dict):
|
|
8
6
|
# __setattr__ = dict.__setitem__
|
|
@@ -46,7 +44,8 @@ async def check_port_open(port: int, delay: float = 1) -> None:
|
|
|
46
44
|
asyncio.Protocol, host="0.0.0.0", port=port
|
|
47
45
|
)
|
|
48
46
|
except OSError as e:
|
|
49
|
-
|
|
47
|
+
print(e.errno)
|
|
48
|
+
if e.errno != 48:
|
|
50
49
|
raise
|
|
51
50
|
warning("port %d is already in use, waiting %d...", port, i)
|
|
52
51
|
await asyncio.sleep(delay)
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import aiohttp
|
|
2
|
+
import asyncio
|
|
3
|
+
from aiohttp import BasicAuth, ClientSession
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
__all__ = ("Session", "BasicAuth")
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class Session:
|
|
10
|
+
def __init__(
|
|
11
|
+
self,
|
|
12
|
+
timeout: float = 30.0,
|
|
13
|
+
max_retries: int = 1,
|
|
14
|
+
retry_delay: int = 1,
|
|
15
|
+
**kwargs,
|
|
16
|
+
):
|
|
17
|
+
self.max_retries = max_retries
|
|
18
|
+
self.retry_delay = retry_delay
|
|
19
|
+
self.session: ClientSession = ClientSession(
|
|
20
|
+
timeout=aiohttp.ClientTimeout(total=timeout), **kwargs
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
async def request(
|
|
24
|
+
self,
|
|
25
|
+
method: str,
|
|
26
|
+
url: str,
|
|
27
|
+
**kwargs,
|
|
28
|
+
):
|
|
29
|
+
last_exception = None
|
|
30
|
+
|
|
31
|
+
for attempt in range(self.max_retries):
|
|
32
|
+
try:
|
|
33
|
+
response = await self.session.request(method=method, url=url, **kwargs)
|
|
34
|
+
return response
|
|
35
|
+
|
|
36
|
+
except (aiohttp.ClientError, asyncio.TimeoutError) as e:
|
|
37
|
+
last_exception = e
|
|
38
|
+
if attempt < self.max_retries - 1:
|
|
39
|
+
await asyncio.sleep(self.retry_delay * (attempt + 1))
|
|
40
|
+
continue
|
|
41
|
+
# finally:
|
|
42
|
+
# if use_temp_session:
|
|
43
|
+
# await session.close()
|
|
44
|
+
|
|
45
|
+
raise last_exception or RuntimeError(
|
|
46
|
+
f"Request failed after {self.max_retries} attempts"
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
async def get(
|
|
50
|
+
self,
|
|
51
|
+
url: str,
|
|
52
|
+
**kwargs,
|
|
53
|
+
):
|
|
54
|
+
"""Send a GET request"""
|
|
55
|
+
return await self.request("GET", url, **kwargs)
|
|
56
|
+
|
|
57
|
+
async def post(
|
|
58
|
+
self,
|
|
59
|
+
url: str,
|
|
60
|
+
**kwargs,
|
|
61
|
+
):
|
|
62
|
+
"""Send a POST request"""
|
|
63
|
+
return await self.request("POST", url, **kwargs)
|
|
64
|
+
|
|
65
|
+
async def put(
|
|
66
|
+
self,
|
|
67
|
+
url: str,
|
|
68
|
+
**kwargs,
|
|
69
|
+
):
|
|
70
|
+
"""Send a PUT request"""
|
|
71
|
+
return await self.request("PUT", url, **kwargs)
|
|
72
|
+
|
|
73
|
+
async def delete(self, url: str, **kwargs):
|
|
74
|
+
"""Send a DELETE request"""
|
|
75
|
+
return await self.request("DELETE", url, **kwargs)
|
|
76
|
+
|
|
77
|
+
async def close(self) -> None:
|
|
78
|
+
"""Close the aiohttp session if it exists"""
|
|
79
|
+
if self.session is not None:
|
|
80
|
+
await self.session.close()
|
|
81
|
+
|
|
82
|
+
async def __aenter__(self):
|
|
83
|
+
return self
|
|
84
|
+
|
|
85
|
+
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
86
|
+
await self.close()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cloudoll
|
|
3
|
-
Version: 3.0.
|
|
3
|
+
Version: 3.0.3
|
|
4
4
|
Summary: Assist in quickly creating distributable microservices based on aiohttp, with a focus on simplicity and ease of use.
|
|
5
5
|
Home-page: https://github.com/smallerqiu/cloudoll-py
|
|
6
6
|
Author: Qiu
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "cloudoll"
|
|
7
|
-
version = "3.0.
|
|
7
|
+
version = "3.0.3"
|
|
8
8
|
description = "Assist in quickly creating distributable microservices based on aiohttp, with a focus on simplicity and ease of use."
|
|
9
9
|
authors = [
|
|
10
10
|
{name = "Qiu", email = "smallerqiu@gmail.com"},
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
__version__ = "3.0.1"
|
|
@@ -1,159 +0,0 @@
|
|
|
1
|
-
import aiohttp
|
|
2
|
-
import asyncio
|
|
3
|
-
# import ssl
|
|
4
|
-
from typing import Optional, Dict, Union, List, Any
|
|
5
|
-
|
|
6
|
-
JSONType = Union[Dict[str, Any], List[Any], str, int, float, bool, None]
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
class AsyncRequest:
|
|
10
|
-
def __init__(
|
|
11
|
-
self,
|
|
12
|
-
timeout: float = 30.0,
|
|
13
|
-
max_retries: int = 1,
|
|
14
|
-
retry_delay: float = 1.0,
|
|
15
|
-
keep_alive: bool = True,
|
|
16
|
-
use_cookies: bool = False,
|
|
17
|
-
proxy: Optional[str] = None,
|
|
18
|
-
# session: Optional[aiohttp.ClientSession] = None,
|
|
19
|
-
# connector: Optional[aiohttp.BaseConnector] = None,
|
|
20
|
-
# ssl: Union[bool, ssl.SSLContext] = True,
|
|
21
|
-
):
|
|
22
|
-
self.timeout = timeout
|
|
23
|
-
self.max_retries = max_retries
|
|
24
|
-
self.retry_delay = retry_delay
|
|
25
|
-
# self.session = session
|
|
26
|
-
# self.connector = connector
|
|
27
|
-
self.use_cookies = use_cookies
|
|
28
|
-
self.keep_alive = keep_alive
|
|
29
|
-
|
|
30
|
-
self.session = aiohttp.ClientSession(
|
|
31
|
-
proxy=proxy,
|
|
32
|
-
connector=aiohttp.TCPConnector(keepalive_timeout=self.timeout) if self.keep_alive else None,
|
|
33
|
-
timeout=aiohttp.ClientTimeout(total=self.timeout),
|
|
34
|
-
cookie_jar=aiohttp.CookieJar() if self.use_cookies else None,
|
|
35
|
-
)
|
|
36
|
-
|
|
37
|
-
async def request(
|
|
38
|
-
self,
|
|
39
|
-
method: str,
|
|
40
|
-
url: str,
|
|
41
|
-
params: Optional[Dict[str, Any]] = None,
|
|
42
|
-
data: Optional[Union[Dict[str, Any], str, bytes]] = None,
|
|
43
|
-
json_data: Optional[JSONType] = None,
|
|
44
|
-
headers: Optional[Dict[str, str]] = None,
|
|
45
|
-
cookies: Optional[Dict[str, str]] = None,
|
|
46
|
-
allow_redirects: bool = True,
|
|
47
|
-
raise_for_status: bool = True,
|
|
48
|
-
proxy: Optional[str] = None,
|
|
49
|
-
# parse_json: bool = False,
|
|
50
|
-
) -> Union[dict, str, aiohttp.ClientResponse]:
|
|
51
|
-
last_exception = None
|
|
52
|
-
|
|
53
|
-
for attempt in range(self.max_retries):
|
|
54
|
-
try:
|
|
55
|
-
response = await self.session.request(
|
|
56
|
-
method=method,
|
|
57
|
-
url=url,
|
|
58
|
-
params=params,
|
|
59
|
-
data=data,
|
|
60
|
-
json=json_data,
|
|
61
|
-
headers=headers,
|
|
62
|
-
cookies=cookies,
|
|
63
|
-
allow_redirects=allow_redirects,
|
|
64
|
-
proxy=proxy,
|
|
65
|
-
)
|
|
66
|
-
return response
|
|
67
|
-
|
|
68
|
-
except (aiohttp.ClientError, asyncio.TimeoutError) as e:
|
|
69
|
-
last_exception = e
|
|
70
|
-
if attempt < self.max_retries - 1:
|
|
71
|
-
await asyncio.sleep(self.retry_delay * (attempt + 1))
|
|
72
|
-
continue
|
|
73
|
-
# finally:
|
|
74
|
-
# if use_temp_session:
|
|
75
|
-
# await session.close()
|
|
76
|
-
|
|
77
|
-
raise last_exception or RuntimeError(
|
|
78
|
-
f"Request failed after {self.max_retries} attempts"
|
|
79
|
-
)
|
|
80
|
-
|
|
81
|
-
async def get(
|
|
82
|
-
self,
|
|
83
|
-
url: str,
|
|
84
|
-
params: Optional[Dict[str, Any]] = None,
|
|
85
|
-
headers: Optional[Dict[str, str]] = None,
|
|
86
|
-
**kwargs,
|
|
87
|
-
) -> aiohttp.ClientResponse:
|
|
88
|
-
"""Send a GET request"""
|
|
89
|
-
return await self.request("GET", url, params=params, headers=headers, **kwargs)
|
|
90
|
-
|
|
91
|
-
async def post(
|
|
92
|
-
self,
|
|
93
|
-
url: str,
|
|
94
|
-
data: Optional[Union[Dict[str, Any], str, bytes]] = None,
|
|
95
|
-
json_data: Optional[Any] = None,
|
|
96
|
-
headers: Optional[Dict[str, str]] = None,
|
|
97
|
-
**kwargs,
|
|
98
|
-
) -> aiohttp.ClientResponse:
|
|
99
|
-
"""Send a POST request"""
|
|
100
|
-
return await self.request(
|
|
101
|
-
"POST", url, data=data, json_data=json_data, headers=headers, **kwargs
|
|
102
|
-
)
|
|
103
|
-
|
|
104
|
-
async def put(
|
|
105
|
-
self,
|
|
106
|
-
url: str,
|
|
107
|
-
data: Optional[Union[Dict[str, Any], str, bytes]] = None,
|
|
108
|
-
json_data: Optional[Any] = None,
|
|
109
|
-
headers: Optional[Dict[str, str]] = None,
|
|
110
|
-
**kwargs,
|
|
111
|
-
) -> aiohttp.ClientResponse:
|
|
112
|
-
"""Send a PUT request"""
|
|
113
|
-
return await self.request(
|
|
114
|
-
"PUT", url, data=data, json_data=json_data, headers=headers, **kwargs
|
|
115
|
-
)
|
|
116
|
-
|
|
117
|
-
async def delete(
|
|
118
|
-
self, url: str, headers: Optional[Dict[str, str]] = None, **kwargs
|
|
119
|
-
) -> aiohttp.ClientResponse:
|
|
120
|
-
"""Send a DELETE request"""
|
|
121
|
-
return await self.request("DELETE", url, headers=headers, **kwargs)
|
|
122
|
-
|
|
123
|
-
async def close(self) -> None:
|
|
124
|
-
"""Close the aiohttp session if it exists"""
|
|
125
|
-
if self.session is not None:
|
|
126
|
-
await self.session.close()
|
|
127
|
-
self.session = None
|
|
128
|
-
|
|
129
|
-
async def __aenter__(self):
|
|
130
|
-
return self
|
|
131
|
-
|
|
132
|
-
async def __aexit__(self, exc_type, exc_val, exc_tb):
|
|
133
|
-
await self.close()
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
# demo
|
|
137
|
-
"""
|
|
138
|
-
async def test():
|
|
139
|
-
async with AsyncRequest() as client:
|
|
140
|
-
try:
|
|
141
|
-
# GET Request example
|
|
142
|
-
response = await client.get(
|
|
143
|
-
"https://httpbin.org/get",
|
|
144
|
-
params={"key": "value"},
|
|
145
|
-
headers={"User-Agent": "AsyncRequest/1.0"},
|
|
146
|
-
)
|
|
147
|
-
print(await response.json())
|
|
148
|
-
|
|
149
|
-
# POST Request example
|
|
150
|
-
response = await client.post(
|
|
151
|
-
"https://httpbin.org/post",
|
|
152
|
-
json_data={"key": "value"},
|
|
153
|
-
headers={"Content-Type": "application/json"},
|
|
154
|
-
)
|
|
155
|
-
print(await response.json())
|
|
156
|
-
|
|
157
|
-
except Exception as e:
|
|
158
|
-
print(f"Request failed: {e}")
|
|
159
|
-
"""
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|