requests_request 0.0.1__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.
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 ChenyangGao <https://github.com/ChenyangGao>
|
|
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,44 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: requests_request
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: requests request extension.
|
|
5
|
+
Home-page: https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/requests_request
|
|
6
|
+
License: MIT
|
|
7
|
+
Keywords: requests,request
|
|
8
|
+
Author: ChenyangGao
|
|
9
|
+
Author-email: wosiwujm@gmail.com
|
|
10
|
+
Requires-Python: >=3.10,<4.0
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
21
|
+
Classifier: Topic :: Software Development
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Requires-Dist: python-argtools
|
|
25
|
+
Requires-Dist: requests
|
|
26
|
+
Project-URL: Repository, https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/requests_request
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
|
|
29
|
+
# requests request extension.
|
|
30
|
+
|
|
31
|
+
## Installation
|
|
32
|
+
|
|
33
|
+
You can install via [pypi](https://pypi.org/project/requests_request/)
|
|
34
|
+
|
|
35
|
+
```console
|
|
36
|
+
pip install -U requests_request
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Usage
|
|
40
|
+
|
|
41
|
+
```python
|
|
42
|
+
from requests_request import request
|
|
43
|
+
```
|
|
44
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
[tool.poetry]
|
|
2
|
+
name = "requests_request"
|
|
3
|
+
version = "0.0.1"
|
|
4
|
+
description = "requests request extension."
|
|
5
|
+
authors = ["ChenyangGao <wosiwujm@gmail.com>"]
|
|
6
|
+
license = "MIT"
|
|
7
|
+
readme = "readme.md"
|
|
8
|
+
homepage = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/requests_request"
|
|
9
|
+
repository = "https://github.com/ChenyangGao/web-mount-packs/tree/main/python-module/requests_request"
|
|
10
|
+
keywords = ["requests", "request"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"License :: OSI Approved :: MIT License",
|
|
13
|
+
"Development Status :: 5 - Production/Stable",
|
|
14
|
+
"Programming Language :: Python",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.10",
|
|
17
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Intended Audience :: Developers",
|
|
20
|
+
"Topic :: Software Development",
|
|
21
|
+
"Topic :: Software Development :: Libraries",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
]
|
|
24
|
+
include = [
|
|
25
|
+
"LICENSE",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
[tool.poetry.dependencies]
|
|
29
|
+
python = "^3.10"
|
|
30
|
+
requests = "*"
|
|
31
|
+
python-argtools = "*"
|
|
32
|
+
|
|
33
|
+
[build-system]
|
|
34
|
+
requires = ["poetry-core"]
|
|
35
|
+
build-backend = "poetry.core.masonry.api"
|
|
36
|
+
|
|
37
|
+
[[tool.poetry.packages]]
|
|
38
|
+
include = "requests_request"
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# requests request extension.
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
You can install via [pypi](https://pypi.org/project/requests_request/)
|
|
6
|
+
|
|
7
|
+
```console
|
|
8
|
+
pip install -U requests_request
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from requests_request import request
|
|
15
|
+
```
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# coding: utf-8
|
|
3
|
+
|
|
4
|
+
__author__ = "ChenyangGao <https://chenyanggao.github.io>"
|
|
5
|
+
__version__ = (0, 0, 1)
|
|
6
|
+
__all__ = ["request"]
|
|
7
|
+
|
|
8
|
+
from collections.abc import Callable
|
|
9
|
+
from json import loads
|
|
10
|
+
|
|
11
|
+
from argtools import argcount
|
|
12
|
+
from requests.models import Response
|
|
13
|
+
from requests.sessions import Session
|
|
14
|
+
|
|
15
|
+
if "__del__" not in Response.__dict__:
|
|
16
|
+
setattr(Response, "__del__", Response.close)
|
|
17
|
+
|
|
18
|
+
if "__del__" not in Session.__dict__:
|
|
19
|
+
setattr(Session, "__del__", Session.close)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def request(
|
|
23
|
+
url: str,
|
|
24
|
+
method: str = "GET",
|
|
25
|
+
parse: None | bool | Callable = None,
|
|
26
|
+
raise_for_status: bool = True,
|
|
27
|
+
session: None | Session = None,
|
|
28
|
+
**request_kwargs,
|
|
29
|
+
):
|
|
30
|
+
if session is None:
|
|
31
|
+
with Session() as session:
|
|
32
|
+
return request(
|
|
33
|
+
url,
|
|
34
|
+
method,
|
|
35
|
+
parse=parse,
|
|
36
|
+
raise_for_status=raise_for_status,
|
|
37
|
+
session=session,
|
|
38
|
+
**request_kwargs,
|
|
39
|
+
)
|
|
40
|
+
request_kwargs.setdefault("stream", True)
|
|
41
|
+
resp = session.request(method, url, **request_kwargs)
|
|
42
|
+
if raise_for_status:
|
|
43
|
+
resp.raise_for_status()
|
|
44
|
+
if parse is None:
|
|
45
|
+
return resp
|
|
46
|
+
elif parse is False:
|
|
47
|
+
return resp.content
|
|
48
|
+
elif parse is True:
|
|
49
|
+
with resp:
|
|
50
|
+
content_type = resp.headers.get("Content-Type", "")
|
|
51
|
+
if content_type == "application/json":
|
|
52
|
+
return resp.json()
|
|
53
|
+
elif content_type.startswith("application/json;"):
|
|
54
|
+
return loads(resp.text)
|
|
55
|
+
elif content_type.startswith("text/"):
|
|
56
|
+
return resp.text
|
|
57
|
+
return resp.content
|
|
58
|
+
else:
|
|
59
|
+
ac = argcount(parse)
|
|
60
|
+
with resp:
|
|
61
|
+
if ac == 1:
|
|
62
|
+
return parse(resp)
|
|
63
|
+
else:
|
|
64
|
+
return parse(resp, resp.content)
|
|
65
|
+
|
|
File without changes
|