geventhttpclient 2.4.0__cp315-cp315-win_amd64.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.
- geventhttpclient/__init__.py +9 -0
- geventhttpclient/_parser.cp315-win_amd64.pyd +0 -0
- geventhttpclient/api.py +157 -0
- geventhttpclient/client.py +568 -0
- geventhttpclient/connectionpool.py +359 -0
- geventhttpclient/header.py +289 -0
- geventhttpclient/httplib.py +252 -0
- geventhttpclient/httplib2.py +69 -0
- geventhttpclient/requests.py +250 -0
- geventhttpclient/response.py +305 -0
- geventhttpclient/url.py +226 -0
- geventhttpclient/useragent.py +666 -0
- geventhttpclient-2.4.0.dist-info/METADATA +298 -0
- geventhttpclient-2.4.0.dist-info/RECORD +17 -0
- geventhttpclient-2.4.0.dist-info/WHEEL +5 -0
- geventhttpclient-2.4.0.dist-info/licenses/LICENSE-MIT +22 -0
- geventhttpclient-2.4.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# package
|
|
2
|
+
|
|
3
|
+
__version__ = "2.4.0" # don't forget to update version in pyproject.toml as well
|
|
4
|
+
|
|
5
|
+
from geventhttpclient.api import delete, get, head, options, patch, post, put, request
|
|
6
|
+
from geventhttpclient.client import HTTPClient
|
|
7
|
+
from geventhttpclient.requests import Session
|
|
8
|
+
from geventhttpclient.url import URL
|
|
9
|
+
from geventhttpclient.useragent import UserAgent
|
|
Binary file
|
geventhttpclient/api.py
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"""
|
|
2
|
+
This module mimics and blatantly borrows with all due respect
|
|
3
|
+
from the excellent and rightfully popular Requests API.
|
|
4
|
+
|
|
5
|
+
Copyright of the original requests project:
|
|
6
|
+
|
|
7
|
+
:copyright: (c) 2012 by Kenneth Reitz.
|
|
8
|
+
:license: Apache2, see LICENSE for more details.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
import geventhttpclient.requests
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def request(method, url, **kw):
|
|
15
|
+
"""Constructs and sends a HTTP request. WARNING: Only a subset of the following parameters is currently supported
|
|
16
|
+
|
|
17
|
+
:param method: method for the new request object: ``GET``, ``OPTIONS``, ``HEAD``, ``POST``, ``PUT``, ``PATCH``, or ``DELETE``.
|
|
18
|
+
:param url: URL for the new HTTP Request object.
|
|
19
|
+
:param params: (optional) Dictionary, list of tuples or bytes to send
|
|
20
|
+
in the query string for the HTTP Request.
|
|
21
|
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
|
22
|
+
object to send in the body of the HTTP Request.
|
|
23
|
+
:param json: (optional) A JSON serializable Python object to send in the body of the HTTP Request.
|
|
24
|
+
:param headers: (optional) Dictionary of HTTP Headers to send with the HTTP Request.
|
|
25
|
+
:param cookies: (optional) Dict or CookieJar object to send with the HTTP Request.
|
|
26
|
+
:param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload.
|
|
27
|
+
``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')``
|
|
28
|
+
or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string
|
|
29
|
+
defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers
|
|
30
|
+
to add for the file.
|
|
31
|
+
:param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth.
|
|
32
|
+
:param timeout: (optional) How many seconds to wait for the server to send data
|
|
33
|
+
before giving up, as a float, or a :ref:`(connect timeout, read
|
|
34
|
+
timeout) <timeouts>` tuple.
|
|
35
|
+
:type timeout: float or tuple
|
|
36
|
+
:param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``.
|
|
37
|
+
:type allow_redirects: bool
|
|
38
|
+
:param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.
|
|
39
|
+
:param verify: (optional) Either a boolean, in which case it controls whether we verify
|
|
40
|
+
the server's TLS certificate, or a string, in which case it must be a path
|
|
41
|
+
to a CA bundle to use. Defaults to ``True``.
|
|
42
|
+
:param stream: (optional) if ``False``, the response content will be immediately downloaded.
|
|
43
|
+
:param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.
|
|
44
|
+
:return: HTTP Response object
|
|
45
|
+
:rtype: HTTP Response
|
|
46
|
+
|
|
47
|
+
Usage::
|
|
48
|
+
|
|
49
|
+
>>> import geventhttpclient
|
|
50
|
+
>>> req = geventhttpclient.request('GET', 'https://httpbingo.org/get')
|
|
51
|
+
>>> req
|
|
52
|
+
<Response [200]>
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
# By using the 'with' statement we are sure the session is closed, thus we
|
|
56
|
+
# avoid leaving sockets open which can trigger a ResourceWarning in some
|
|
57
|
+
# cases, and look like a memory leak in others.
|
|
58
|
+
with geventhttpclient.requests.Session() as session:
|
|
59
|
+
return session.request(method=method, url=url, **kw)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def get(url, params=None, **kw):
|
|
63
|
+
r"""Sends a GET request.
|
|
64
|
+
|
|
65
|
+
:param url: URL for the new HTTP Request object.
|
|
66
|
+
:param params: (optional) Dictionary, list of tuples or bytes to send
|
|
67
|
+
in the query string for the HTTP Request.
|
|
68
|
+
:param \*\*kw: Optional arguments that ``request`` takes.
|
|
69
|
+
:return: HTTP Response object
|
|
70
|
+
:rtype: requests.Response
|
|
71
|
+
"""
|
|
72
|
+
|
|
73
|
+
return request("get", url, params=params, **kw)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def options(url, **kw):
|
|
77
|
+
r"""Sends an OPTIONS request.
|
|
78
|
+
|
|
79
|
+
:param url: URL for the new HTTP Request object.
|
|
80
|
+
:param \*\*kw: Optional arguments that ``request`` takes.
|
|
81
|
+
:return: HTTP Response object
|
|
82
|
+
:rtype: requests.Response
|
|
83
|
+
"""
|
|
84
|
+
|
|
85
|
+
return request("options", url, **kw)
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def head(url, **kw):
|
|
89
|
+
r"""Sends a HEAD request.
|
|
90
|
+
|
|
91
|
+
:param url: URL for the new HTTP Request object.
|
|
92
|
+
:param \*\*kw: Optional arguments that ``request`` takes. If
|
|
93
|
+
`allow_redirects` is not provided, it will be set to `False` (as
|
|
94
|
+
opposed to the default :meth:`request` behavior).
|
|
95
|
+
:return: HTTP Response object
|
|
96
|
+
:rtype: requests.Response
|
|
97
|
+
"""
|
|
98
|
+
|
|
99
|
+
kw.setdefault("allow_redirects", False)
|
|
100
|
+
return request("head", url, **kw)
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def post(url, data=None, json=None, **kw):
|
|
104
|
+
r"""Sends a POST request.
|
|
105
|
+
|
|
106
|
+
:param url: URL for the new HTTP Request object.
|
|
107
|
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
|
108
|
+
object to send in the body of the HTTP Request.
|
|
109
|
+
:param json: (optional) A JSON serializable Python object to send in the body of the HTTP Request.
|
|
110
|
+
:param \*\*kw: Optional arguments that ``request`` takes.
|
|
111
|
+
:return: HTTP Response object
|
|
112
|
+
:rtype: requests.Response
|
|
113
|
+
"""
|
|
114
|
+
|
|
115
|
+
return request("post", url, data=data, json=json, **kw)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def put(url, data=None, **kw):
|
|
119
|
+
r"""Sends a PUT request.
|
|
120
|
+
|
|
121
|
+
:param url: URL for the new HTTP Request object.
|
|
122
|
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
|
123
|
+
object to send in the body of the HTTP Request.
|
|
124
|
+
:param json: (optional) A JSON serializable Python object to send in the body of the HTTP Request.
|
|
125
|
+
:param \*\*kw: Optional arguments that ``request`` takes.
|
|
126
|
+
:return: HTTP Response object
|
|
127
|
+
:rtype: requests.Response
|
|
128
|
+
"""
|
|
129
|
+
|
|
130
|
+
return request("put", url, data=data, **kw)
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def patch(url, data=None, **kw):
|
|
134
|
+
r"""Sends a PATCH request.
|
|
135
|
+
|
|
136
|
+
:param url: URL for the new HTTP Request object.
|
|
137
|
+
:param data: (optional) Dictionary, list of tuples, bytes, or file-like
|
|
138
|
+
object to send in the body of the HTTP Request.
|
|
139
|
+
:param json: (optional) A JSON serializable Python object to send in the body of the HTTP Request.
|
|
140
|
+
:param \*\*kw: Optional arguments that ``request`` takes.
|
|
141
|
+
:return: HTTP Response object
|
|
142
|
+
:rtype: requests.Response
|
|
143
|
+
"""
|
|
144
|
+
|
|
145
|
+
return request("patch", url, data=data, **kw)
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def delete(url, **kw):
|
|
149
|
+
r"""Sends a DELETE request.
|
|
150
|
+
|
|
151
|
+
:param url: URL for the new HTTP Request object.
|
|
152
|
+
:param \*\*kw: Optional arguments that ``request`` takes.
|
|
153
|
+
:return: HTTP Response object
|
|
154
|
+
:rtype: requests.Response
|
|
155
|
+
"""
|
|
156
|
+
|
|
157
|
+
return request("delete", url, **kw)
|