cloudoll 3.0.2__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.
Files changed (45) hide show
  1. {cloudoll-3.0.2 → cloudoll-3.0.3}/PKG-INFO +1 -1
  2. cloudoll-3.0.3/cloudoll/__init__.py +1 -0
  3. cloudoll-3.0.3/cloudoll/web/requests.py +86 -0
  4. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll.egg-info/PKG-INFO +1 -1
  5. {cloudoll-3.0.2 → cloudoll-3.0.3}/pyproject.toml +1 -1
  6. cloudoll-3.0.2/cloudoll/__init__.py +0 -1
  7. cloudoll-3.0.2/cloudoll/web/requests.py +0 -163
  8. {cloudoll-3.0.2 → cloudoll-3.0.3}/LICENSE +0 -0
  9. {cloudoll-3.0.2 → cloudoll-3.0.3}/README.md +0 -0
  10. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/__main__.py +0 -0
  11. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/cli.py +0 -0
  12. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/clitool/__init__.py +0 -0
  13. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/clitool/cli_main.py +0 -0
  14. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/clitool/m2d.py +0 -0
  15. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/clitool/process.py +0 -0
  16. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/clitool/spinner.py +0 -0
  17. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/clitool/watch.py +0 -0
  18. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/logging/__init__.py +0 -0
  19. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/mail/__init__.py +0 -0
  20. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/mail/smtp.py +0 -0
  21. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/orm/__init__.py +0 -0
  22. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/orm/base.py +0 -0
  23. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/orm/err.py +0 -0
  24. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/orm/field.py +0 -0
  25. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/orm/model.py +0 -0
  26. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/orm/mysql.py +0 -0
  27. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/orm/parse.py +0 -0
  28. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/orm/postgres.py +0 -0
  29. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/template/__init__.py +0 -0
  30. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/utils/__init__.py +0 -0
  31. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/utils/common.py +0 -0
  32. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/utils/snowflake.py +0 -0
  33. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/web/__init__.py +0 -0
  34. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/web/core.py +0 -0
  35. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/web/exception.py +0 -0
  36. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/web/html.py +0 -0
  37. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/web/jwt.py +0 -0
  38. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll/web/settings.py +0 -0
  39. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll.egg-info/SOURCES.txt +0 -0
  40. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll.egg-info/dependency_links.txt +0 -0
  41. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll.egg-info/entry_points.txt +0 -0
  42. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll.egg-info/requires.txt +0 -0
  43. {cloudoll-3.0.2 → cloudoll-3.0.3}/cloudoll.egg-info/top_level.txt +0 -0
  44. {cloudoll-3.0.2 → cloudoll-3.0.3}/setup.cfg +0 -0
  45. {cloudoll-3.0.2 → 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.2
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"
@@ -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.2
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.2"
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.2"
@@ -1,163 +0,0 @@
1
- import aiohttp
2
- import asyncio
3
-
4
- # import ssl
5
- from typing import Optional, Dict, Union, List, Any
6
-
7
- JSONType = Union[Dict[str, Any], List[Any], str, int, float, bool, None]
8
-
9
-
10
- class AsyncRequest:
11
- def __init__(
12
- self,
13
- timeout: float = 30.0,
14
- max_retries: int = 1,
15
- retry_delay: float = 1.0,
16
- keep_alive: bool = True,
17
- use_cookies: bool = False,
18
- proxy: Optional[str] = None,
19
- # session: Optional[aiohttp.ClientSession] = None,
20
- # connector: Optional[aiohttp.BaseConnector] = None,
21
- # ssl: Union[bool, ssl.SSLContext] = True,
22
- ):
23
- self.timeout = timeout
24
- self.max_retries = max_retries
25
- self.retry_delay = retry_delay
26
- # self.session = session
27
- # self.connector = connector
28
- self.use_cookies = use_cookies
29
- self.keep_alive = keep_alive
30
-
31
- self.session: aiohttp.ClientSession = aiohttp.ClientSession(
32
- proxy=proxy,
33
- connector=(
34
- aiohttp.TCPConnector(keepalive_timeout=self.timeout)
35
- if self.keep_alive
36
- else None
37
- ),
38
- timeout=aiohttp.ClientTimeout(total=self.timeout),
39
- cookie_jar=aiohttp.CookieJar() if self.use_cookies else None,
40
- )
41
-
42
- async def request(
43
- self,
44
- method: str,
45
- url: str,
46
- params: Optional[Dict[str, Any]] = None,
47
- data: Optional[Union[Dict[str, Any], str, bytes]] = None,
48
- json_data: Optional[JSONType] = None,
49
- headers: Optional[Dict[str, str]] = None,
50
- cookies: Optional[Dict[str, str]] = None,
51
- allow_redirects: bool = True,
52
- raise_for_status: bool = True,
53
- proxy: Optional[str] = None,
54
- # parse_json: bool = False,
55
- ) -> Union[dict, str, aiohttp.ClientResponse]:
56
- last_exception = None
57
-
58
- for attempt in range(self.max_retries):
59
- try:
60
- response = await self.session.request(
61
- method=method,
62
- url=url,
63
- params=params,
64
- data=data,
65
- json=json_data,
66
- headers=headers,
67
- cookies=cookies,
68
- allow_redirects=allow_redirects,
69
- proxy=proxy,
70
- )
71
- return response
72
-
73
- except (aiohttp.ClientError, asyncio.TimeoutError) as e:
74
- last_exception = e
75
- if attempt < self.max_retries - 1:
76
- await asyncio.sleep(self.retry_delay * (attempt + 1))
77
- continue
78
- # finally:
79
- # if use_temp_session:
80
- # await session.close()
81
-
82
- raise last_exception or RuntimeError(
83
- f"Request failed after {self.max_retries} attempts"
84
- )
85
-
86
- async def get(
87
- self,
88
- url: str,
89
- params: Optional[Dict[str, Any]] = None,
90
- headers: Optional[Dict[str, str]] = None,
91
- **kwargs,
92
- ) -> Union[dict, str, aiohttp.ClientResponse]:
93
- """Send a GET request"""
94
- return await self.request("GET", url, params=params, headers=headers, **kwargs)
95
-
96
- async def post(
97
- self,
98
- url: str,
99
- data: Optional[Union[Dict[str, Any], str, bytes]] = None,
100
- json_data: Optional[Any] = None,
101
- headers: Optional[Dict[str, str]] = None,
102
- **kwargs,
103
- ) -> Union[dict, str, aiohttp.ClientResponse]:
104
- """Send a POST request"""
105
- return await self.request(
106
- "POST", url, data=data, json_data=json_data, headers=headers, **kwargs
107
- )
108
-
109
- async def put(
110
- self,
111
- url: str,
112
- data: Optional[Union[Dict[str, Any], str, bytes]] = None,
113
- json_data: Optional[Any] = None,
114
- headers: Optional[Dict[str, str]] = None,
115
- **kwargs,
116
- ) -> Union[dict, str, aiohttp.ClientResponse]:
117
- """Send a PUT request"""
118
- return await self.request(
119
- "PUT", url, data=data, json_data=json_data, headers=headers, **kwargs
120
- )
121
-
122
- async def delete(
123
- self, url: str, headers: Optional[Dict[str, str]] = None, **kwargs
124
- ) -> Union[dict, str, aiohttp.ClientResponse]:
125
- """Send a DELETE request"""
126
- return await self.request("DELETE", url, headers=headers, **kwargs)
127
-
128
- async def close(self) -> None:
129
- """Close the aiohttp session if it exists"""
130
- if self.session is not None:
131
- await self.session.close()
132
-
133
- async def __aenter__(self):
134
- return self
135
-
136
- async def __aexit__(self, exc_type, exc_val, exc_tb):
137
- await self.close()
138
-
139
-
140
- # demo
141
- """
142
- async def test():
143
- async with AsyncRequest() as client:
144
- try:
145
- # GET Request example
146
- response = await client.get(
147
- "https://httpbin.org/get",
148
- params={"key": "value"},
149
- headers={"User-Agent": "AsyncRequest/1.0"},
150
- )
151
- print(await response.json())
152
-
153
- # POST Request example
154
- response = await client.post(
155
- "https://httpbin.org/post",
156
- json_data={"key": "value"},
157
- headers={"Content-Type": "application/json"},
158
- )
159
- print(await response.json())
160
-
161
- except Exception as e:
162
- print(f"Request failed: {e}")
163
- """
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