k3http 0.1.0__tar.gz → 0.1.2__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.
- k3http-0.1.2/LICENSE +21 -0
- k3http-0.1.2/PKG-INFO +142 -0
- k3http-0.1.2/README.md +105 -0
- {k3http-0.1.0/k3http → k3http-0.1.2}/__init__.py +13 -16
- {k3http-0.1.0/k3http → k3http-0.1.2}/client.py +78 -109
- k3http-0.1.2/k3http.egg-info/PKG-INFO +142 -0
- k3http-0.1.2/k3http.egg-info/SOURCES.txt +19 -0
- k3http-0.1.2/k3http.egg-info/requires.txt +17 -0
- k3http-0.1.2/pyproject.toml +60 -0
- {k3http-0.1.0/k3http → k3http-0.1.2}/synopsis.py +10 -11
- k3http-0.1.2/test/test_doctest.py +8 -0
- k3http-0.1.2/test/test_httpclient.py +556 -0
- k3http-0.1.2/test/test_util.py +62 -0
- {k3http-0.1.0/k3http → k3http-0.1.2}/util.py +4 -4
- k3http-0.1.0/PKG-INFO +0 -121
- k3http-0.1.0/k3http/setup.py +0 -23
- k3http-0.1.0/k3http.egg-info/PKG-INFO +0 -121
- k3http-0.1.0/k3http.egg-info/SOURCES.txt +0 -11
- k3http-0.1.0/k3http.egg-info/requires.txt +0 -2
- k3http-0.1.0/setup.py +0 -23
- {k3http-0.1.0 → k3http-0.1.2}/k3http.egg-info/dependency_links.txt +0 -0
- {k3http-0.1.0 → k3http-0.1.2}/k3http.egg-info/top_level.txt +0 -0
- {k3http-0.1.0 → k3http-0.1.2}/setup.cfg +0 -0
k3http-0.1.2/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2020 张炎泼
|
|
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.
|
k3http-0.1.2/PKG-INFO
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: k3http
|
|
3
|
+
Version: 0.1.2
|
|
4
|
+
Summary: HTTP/1.1 client with timeout support
|
|
5
|
+
Author-email: Zhang Yanpo <drdr.xp@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pykit3/k3http
|
|
8
|
+
Project-URL: Documentation, https://k3http.readthedocs.io
|
|
9
|
+
Keywords: http,client,socket,timeout
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: k3stopwatch
|
|
23
|
+
Provides-Extra: dev
|
|
24
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff; extra == "dev"
|
|
26
|
+
Requires-Dist: coverage; extra == "dev"
|
|
27
|
+
Requires-Dist: k3ut; extra == "dev"
|
|
28
|
+
Provides-Extra: publish
|
|
29
|
+
Requires-Dist: build; extra == "publish"
|
|
30
|
+
Requires-Dist: twine; extra == "publish"
|
|
31
|
+
Requires-Dist: pk3; extra == "publish"
|
|
32
|
+
Provides-Extra: docs
|
|
33
|
+
Requires-Dist: mkdocs>=1.5; extra == "docs"
|
|
34
|
+
Requires-Dist: mkdocs-material>=9.0; extra == "docs"
|
|
35
|
+
Requires-Dist: mkdocstrings[python]>=0.24; extra == "docs"
|
|
36
|
+
Dynamic: license-file
|
|
37
|
+
|
|
38
|
+
# k3http
|
|
39
|
+
|
|
40
|
+
[](https://github.com/pykit3/k3http/actions/workflows/python-package.yml)
|
|
41
|
+
[](https://travis-ci.com/pykit3/k3http)
|
|
42
|
+
[](https://k3http.readthedocs.io/en/stable/?badge=stable)
|
|
43
|
+
[](https://pypi.org/project/k3http)
|
|
44
|
+
|
|
45
|
+
We find that 'httplib' must work in blocking mode and it can not have a timeout when recving response.
|
|
46
|
+
|
|
47
|
+
k3http is a component of [pykit3] project: a python3 toolkit set.
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
HTTP/1.1 client
|
|
51
|
+
|
|
52
|
+
Use this module, we can set timeout, if timeout raise a 'socket.timeout'.
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
# Install
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
pip install k3http
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
# Synopsis
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
|
|
66
|
+
import k3http
|
|
67
|
+
import urllib
|
|
68
|
+
import socket
|
|
69
|
+
|
|
70
|
+
headers = {
|
|
71
|
+
'Host': '127.0.0.1',
|
|
72
|
+
'Accept-Language': 'en, mi',
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
h = k3http.Client('127.0.0.1', 80)
|
|
77
|
+
|
|
78
|
+
# send http reqeust without body
|
|
79
|
+
# read response status line
|
|
80
|
+
# read response headers
|
|
81
|
+
h.request('/test.txt', method='GET', headers=headers)
|
|
82
|
+
|
|
83
|
+
status = h.status
|
|
84
|
+
# response code return from http server, type is int
|
|
85
|
+
# 200
|
|
86
|
+
# 302
|
|
87
|
+
# 404
|
|
88
|
+
# ...
|
|
89
|
+
|
|
90
|
+
res_headers = h.headers
|
|
91
|
+
# response headers except status line
|
|
92
|
+
# res_headers = {
|
|
93
|
+
# 'Content-Type': 'text/html;charset=utf-8',
|
|
94
|
+
# 'Content-Length': 1024,
|
|
95
|
+
# ...
|
|
96
|
+
# }
|
|
97
|
+
|
|
98
|
+
# get response body
|
|
99
|
+
print(h.read_body(None))
|
|
100
|
+
except (socket.error, k3http.HttpError) as e:
|
|
101
|
+
print(repr(e))
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
content = urllib.urlencode({'f': 'foo', 'b': 'bar'})
|
|
106
|
+
headers = {
|
|
107
|
+
'Host': 'www.example.com',
|
|
108
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
|
|
109
|
+
'Content-Length': len(content),
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
try:
|
|
113
|
+
h = k3http.Client('127.0.0.1', 80)
|
|
114
|
+
|
|
115
|
+
# send http reqeust
|
|
116
|
+
h.send_request('http://www.example.com', method='POST', headers=headers)
|
|
117
|
+
|
|
118
|
+
# send http request body
|
|
119
|
+
h.send_body(content)
|
|
120
|
+
|
|
121
|
+
# read response status line and headers
|
|
122
|
+
status, headers = h.read_response()
|
|
123
|
+
|
|
124
|
+
# read response body
|
|
125
|
+
print(h.read_body(None))
|
|
126
|
+
except (socket.error, k3http.HttpError) as e:
|
|
127
|
+
print(repr(e))
|
|
128
|
+
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
# Author
|
|
132
|
+
|
|
133
|
+
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
134
|
+
|
|
135
|
+
# Copyright and License
|
|
136
|
+
|
|
137
|
+
The MIT License (MIT)
|
|
138
|
+
|
|
139
|
+
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
[pykit3]: https://github.com/pykit3
|
k3http-0.1.2/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# k3http
|
|
2
|
+
|
|
3
|
+
[](https://github.com/pykit3/k3http/actions/workflows/python-package.yml)
|
|
4
|
+
[](https://travis-ci.com/pykit3/k3http)
|
|
5
|
+
[](https://k3http.readthedocs.io/en/stable/?badge=stable)
|
|
6
|
+
[](https://pypi.org/project/k3http)
|
|
7
|
+
|
|
8
|
+
We find that 'httplib' must work in blocking mode and it can not have a timeout when recving response.
|
|
9
|
+
|
|
10
|
+
k3http is a component of [pykit3] project: a python3 toolkit set.
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
HTTP/1.1 client
|
|
14
|
+
|
|
15
|
+
Use this module, we can set timeout, if timeout raise a 'socket.timeout'.
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Install
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
pip install k3http
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
# Synopsis
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
|
|
29
|
+
import k3http
|
|
30
|
+
import urllib
|
|
31
|
+
import socket
|
|
32
|
+
|
|
33
|
+
headers = {
|
|
34
|
+
'Host': '127.0.0.1',
|
|
35
|
+
'Accept-Language': 'en, mi',
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
try:
|
|
39
|
+
h = k3http.Client('127.0.0.1', 80)
|
|
40
|
+
|
|
41
|
+
# send http reqeust without body
|
|
42
|
+
# read response status line
|
|
43
|
+
# read response headers
|
|
44
|
+
h.request('/test.txt', method='GET', headers=headers)
|
|
45
|
+
|
|
46
|
+
status = h.status
|
|
47
|
+
# response code return from http server, type is int
|
|
48
|
+
# 200
|
|
49
|
+
# 302
|
|
50
|
+
# 404
|
|
51
|
+
# ...
|
|
52
|
+
|
|
53
|
+
res_headers = h.headers
|
|
54
|
+
# response headers except status line
|
|
55
|
+
# res_headers = {
|
|
56
|
+
# 'Content-Type': 'text/html;charset=utf-8',
|
|
57
|
+
# 'Content-Length': 1024,
|
|
58
|
+
# ...
|
|
59
|
+
# }
|
|
60
|
+
|
|
61
|
+
# get response body
|
|
62
|
+
print(h.read_body(None))
|
|
63
|
+
except (socket.error, k3http.HttpError) as e:
|
|
64
|
+
print(repr(e))
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
content = urllib.urlencode({'f': 'foo', 'b': 'bar'})
|
|
69
|
+
headers = {
|
|
70
|
+
'Host': 'www.example.com',
|
|
71
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8',
|
|
72
|
+
'Content-Length': len(content),
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
try:
|
|
76
|
+
h = k3http.Client('127.0.0.1', 80)
|
|
77
|
+
|
|
78
|
+
# send http reqeust
|
|
79
|
+
h.send_request('http://www.example.com', method='POST', headers=headers)
|
|
80
|
+
|
|
81
|
+
# send http request body
|
|
82
|
+
h.send_body(content)
|
|
83
|
+
|
|
84
|
+
# read response status line and headers
|
|
85
|
+
status, headers = h.read_response()
|
|
86
|
+
|
|
87
|
+
# read response body
|
|
88
|
+
print(h.read_body(None))
|
|
89
|
+
except (socket.error, k3http.HttpError) as e:
|
|
90
|
+
print(repr(e))
|
|
91
|
+
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
# Author
|
|
95
|
+
|
|
96
|
+
Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
97
|
+
|
|
98
|
+
# Copyright and License
|
|
99
|
+
|
|
100
|
+
The MIT License (MIT)
|
|
101
|
+
|
|
102
|
+
Copyright (c) 2015 Zhang Yanpo (张炎泼) <drdr.xp@gmail.com>
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
[pykit3]: https://github.com/pykit3
|
|
@@ -4,9 +4,9 @@ HTTP/1.1 client
|
|
|
4
4
|
Use this module, we can set timeout, if timeout raise a 'socket.timeout'.
|
|
5
5
|
"""
|
|
6
6
|
|
|
7
|
+
from importlib.metadata import version
|
|
7
8
|
|
|
8
|
-
__version__ = "
|
|
9
|
-
__name__ = "k3http"
|
|
9
|
+
__version__ = version("k3http")
|
|
10
10
|
|
|
11
11
|
from .client import (
|
|
12
12
|
HttpError,
|
|
@@ -17,25 +17,22 @@ from .client import (
|
|
|
17
17
|
HeadersError,
|
|
18
18
|
BadStatusLineError,
|
|
19
19
|
Client,
|
|
20
|
-
|
|
21
20
|
)
|
|
22
21
|
|
|
23
|
-
from .util import(
|
|
22
|
+
from .util import (
|
|
24
23
|
headers_add_host,
|
|
25
24
|
request_add_host,
|
|
26
25
|
)
|
|
27
26
|
|
|
28
27
|
__all__ = [
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
'request_add_host',
|
|
28
|
+
"HttpError",
|
|
29
|
+
"LineTooLongError",
|
|
30
|
+
"ChunkedSizeError",
|
|
31
|
+
"NotConnectedError",
|
|
32
|
+
"ResponseNotReadyError",
|
|
33
|
+
"HeadersError",
|
|
34
|
+
"BadStatusLineError",
|
|
35
|
+
"Client",
|
|
36
|
+
"headers_add_host",
|
|
37
|
+
"request_add_host",
|
|
40
38
|
]
|
|
41
|
-
|