Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_vendor/requests/api.py @ 1:64071f2a4cf0 draft default tip
Deleted selected files
author | guerler |
---|---|
date | Mon, 27 Jul 2020 03:55:49 -0400 |
parents | 9e54283cc701 |
children |
comparison
equal
deleted
inserted
replaced
0:9e54283cc701 | 1:64071f2a4cf0 |
---|---|
1 # -*- coding: utf-8 -*- | |
2 | |
3 """ | |
4 requests.api | |
5 ~~~~~~~~~~~~ | |
6 | |
7 This module implements the Requests API. | |
8 | |
9 :copyright: (c) 2012 by Kenneth Reitz. | |
10 :license: Apache2, see LICENSE for more details. | |
11 """ | |
12 | |
13 from . import sessions | |
14 | |
15 | |
16 def request(method, url, **kwargs): | |
17 """Constructs and sends a :class:`Request <Request>`. | |
18 | |
19 :param method: method for the new :class:`Request` object. | |
20 :param url: URL for the new :class:`Request` object. | |
21 :param params: (optional) Dictionary, list of tuples or bytes to send | |
22 in the query string for the :class:`Request`. | |
23 :param data: (optional) Dictionary, list of tuples, bytes, or file-like | |
24 object to send in the body of the :class:`Request`. | |
25 :param json: (optional) A JSON serializable Python object to send in the body of the :class:`Request`. | |
26 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. | |
27 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. | |
28 :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': file-tuple}``) for multipart encoding upload. | |
29 ``file-tuple`` can be a 2-tuple ``('filename', fileobj)``, 3-tuple ``('filename', fileobj, 'content_type')`` | |
30 or a 4-tuple ``('filename', fileobj, 'content_type', custom_headers)``, where ``'content-type'`` is a string | |
31 defining the content type of the given file and ``custom_headers`` a dict-like object containing additional headers | |
32 to add for the file. | |
33 :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. | |
34 :param timeout: (optional) How many seconds to wait for the server to send data | |
35 before giving up, as a float, or a :ref:`(connect timeout, read | |
36 timeout) <timeouts>` tuple. | |
37 :type timeout: float or tuple | |
38 :param allow_redirects: (optional) Boolean. Enable/disable GET/OPTIONS/POST/PUT/PATCH/DELETE/HEAD redirection. Defaults to ``True``. | |
39 :type allow_redirects: bool | |
40 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. | |
41 :param verify: (optional) Either a boolean, in which case it controls whether we verify | |
42 the server's TLS certificate, or a string, in which case it must be a path | |
43 to a CA bundle to use. Defaults to ``True``. | |
44 :param stream: (optional) if ``False``, the response content will be immediately downloaded. | |
45 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. | |
46 :return: :class:`Response <Response>` object | |
47 :rtype: requests.Response | |
48 | |
49 Usage:: | |
50 | |
51 >>> import requests | |
52 >>> req = requests.request('GET', 'https://httpbin.org/get') | |
53 <Response [200]> | |
54 """ | |
55 | |
56 # By using the 'with' statement we are sure the session is closed, thus we | |
57 # avoid leaving sockets open which can trigger a ResourceWarning in some | |
58 # cases, and look like a memory leak in others. | |
59 with sessions.Session() as session: | |
60 return session.request(method=method, url=url, **kwargs) | |
61 | |
62 | |
63 def get(url, params=None, **kwargs): | |
64 r"""Sends a GET request. | |
65 | |
66 :param url: URL for the new :class:`Request` object. | |
67 :param params: (optional) Dictionary, list of tuples or bytes to send | |
68 in the query string for the :class:`Request`. | |
69 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
70 :return: :class:`Response <Response>` object | |
71 :rtype: requests.Response | |
72 """ | |
73 | |
74 kwargs.setdefault('allow_redirects', True) | |
75 return request('get', url, params=params, **kwargs) | |
76 | |
77 | |
78 def options(url, **kwargs): | |
79 r"""Sends an OPTIONS request. | |
80 | |
81 :param url: URL for the new :class:`Request` object. | |
82 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
83 :return: :class:`Response <Response>` object | |
84 :rtype: requests.Response | |
85 """ | |
86 | |
87 kwargs.setdefault('allow_redirects', True) | |
88 return request('options', url, **kwargs) | |
89 | |
90 | |
91 def head(url, **kwargs): | |
92 r"""Sends a HEAD request. | |
93 | |
94 :param url: URL for the new :class:`Request` object. | |
95 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
96 :return: :class:`Response <Response>` object | |
97 :rtype: requests.Response | |
98 """ | |
99 | |
100 kwargs.setdefault('allow_redirects', False) | |
101 return request('head', url, **kwargs) | |
102 | |
103 | |
104 def post(url, data=None, json=None, **kwargs): | |
105 r"""Sends a POST request. | |
106 | |
107 :param url: URL for the new :class:`Request` object. | |
108 :param data: (optional) Dictionary, list of tuples, bytes, or file-like | |
109 object to send in the body of the :class:`Request`. | |
110 :param json: (optional) json data to send in the body of the :class:`Request`. | |
111 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
112 :return: :class:`Response <Response>` object | |
113 :rtype: requests.Response | |
114 """ | |
115 | |
116 return request('post', url, data=data, json=json, **kwargs) | |
117 | |
118 | |
119 def put(url, data=None, **kwargs): | |
120 r"""Sends a PUT request. | |
121 | |
122 :param url: URL for the new :class:`Request` object. | |
123 :param data: (optional) Dictionary, list of tuples, bytes, or file-like | |
124 object to send in the body of the :class:`Request`. | |
125 :param json: (optional) json data to send in the body of the :class:`Request`. | |
126 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
127 :return: :class:`Response <Response>` object | |
128 :rtype: requests.Response | |
129 """ | |
130 | |
131 return request('put', url, data=data, **kwargs) | |
132 | |
133 | |
134 def patch(url, data=None, **kwargs): | |
135 r"""Sends a PATCH request. | |
136 | |
137 :param url: URL for the new :class:`Request` object. | |
138 :param data: (optional) Dictionary, list of tuples, bytes, or file-like | |
139 object to send in the body of the :class:`Request`. | |
140 :param json: (optional) json data to send in the body of the :class:`Request`. | |
141 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
142 :return: :class:`Response <Response>` object | |
143 :rtype: requests.Response | |
144 """ | |
145 | |
146 return request('patch', url, data=data, **kwargs) | |
147 | |
148 | |
149 def delete(url, **kwargs): | |
150 r"""Sends a DELETE request. | |
151 | |
152 :param url: URL for the new :class:`Request` object. | |
153 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
154 :return: :class:`Response <Response>` object | |
155 :rtype: requests.Response | |
156 """ | |
157 | |
158 return request('delete', url, **kwargs) |