Mercurial > repos > bcclaywell > argo_navis
comparison venv/lib/python2.7/site-packages/requests/api.py @ 0:d67268158946 draft
planemo upload commit a3f181f5f126803c654b3a66dd4e83a48f7e203b
author | bcclaywell |
---|---|
date | Mon, 12 Oct 2015 17:43:33 -0400 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d67268158946 |
---|---|
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 | |
14 from . import sessions | |
15 | |
16 | |
17 def request(method, url, **kwargs): | |
18 """Constructs and sends a :class:`Request <Request>`. | |
19 | |
20 :param method: method for the new :class:`Request` object. | |
21 :param url: URL for the new :class:`Request` object. | |
22 :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. | |
23 :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. | |
24 :param json: (optional) json data to send in the body of the :class:`Request`. | |
25 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. | |
26 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. | |
27 :param files: (optional) Dictionary of ``'name': file-like-objects`` (or ``{'name': ('filename', fileobj)}``) for multipart encoding upload. | |
28 :param auth: (optional) Auth tuple to enable Basic/Digest/Custom HTTP Auth. | |
29 :param timeout: (optional) How long to wait for the server to send data | |
30 before giving up, as a float, or a :ref:`(connect timeout, read | |
31 timeout) <timeouts>` tuple. | |
32 :type timeout: float or tuple | |
33 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed. | |
34 :type allow_redirects: bool | |
35 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. | |
36 :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided. | |
37 :param stream: (optional) if ``False``, the response content will be immediately downloaded. | |
38 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair. | |
39 :return: :class:`Response <Response>` object | |
40 :rtype: requests.Response | |
41 | |
42 Usage:: | |
43 | |
44 >>> import requests | |
45 >>> req = requests.request('GET', 'http://httpbin.org/get') | |
46 <Response [200]> | |
47 """ | |
48 | |
49 session = sessions.Session() | |
50 response = session.request(method=method, url=url, **kwargs) | |
51 # By explicitly closing the session, we avoid leaving sockets open which | |
52 # can trigger a ResourceWarning in some cases, and look like a memory leak | |
53 # in others. | |
54 session.close() | |
55 return response | |
56 | |
57 | |
58 def get(url, params=None, **kwargs): | |
59 """Sends a GET request. | |
60 | |
61 :param url: URL for the new :class:`Request` object. | |
62 :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`. | |
63 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
64 :return: :class:`Response <Response>` object | |
65 :rtype: requests.Response | |
66 """ | |
67 | |
68 kwargs.setdefault('allow_redirects', True) | |
69 return request('get', url, params=params, **kwargs) | |
70 | |
71 | |
72 def options(url, **kwargs): | |
73 """Sends a OPTIONS request. | |
74 | |
75 :param url: URL for the new :class:`Request` object. | |
76 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
77 :return: :class:`Response <Response>` object | |
78 :rtype: requests.Response | |
79 """ | |
80 | |
81 kwargs.setdefault('allow_redirects', True) | |
82 return request('options', url, **kwargs) | |
83 | |
84 | |
85 def head(url, **kwargs): | |
86 """Sends a HEAD request. | |
87 | |
88 :param url: URL for the new :class:`Request` object. | |
89 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
90 :return: :class:`Response <Response>` object | |
91 :rtype: requests.Response | |
92 """ | |
93 | |
94 kwargs.setdefault('allow_redirects', False) | |
95 return request('head', url, **kwargs) | |
96 | |
97 | |
98 def post(url, data=None, json=None, **kwargs): | |
99 """Sends a POST request. | |
100 | |
101 :param url: URL for the new :class:`Request` object. | |
102 :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. | |
103 :param json: (optional) json data to send in the body of the :class:`Request`. | |
104 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
105 :return: :class:`Response <Response>` object | |
106 :rtype: requests.Response | |
107 """ | |
108 | |
109 return request('post', url, data=data, json=json, **kwargs) | |
110 | |
111 | |
112 def put(url, data=None, **kwargs): | |
113 """Sends a PUT request. | |
114 | |
115 :param url: URL for the new :class:`Request` object. | |
116 :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. | |
117 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
118 :return: :class:`Response <Response>` object | |
119 :rtype: requests.Response | |
120 """ | |
121 | |
122 return request('put', url, data=data, **kwargs) | |
123 | |
124 | |
125 def patch(url, data=None, **kwargs): | |
126 """Sends a PATCH request. | |
127 | |
128 :param url: URL for the new :class:`Request` object. | |
129 :param data: (optional) Dictionary, bytes, or file-like object to send in the body of the :class:`Request`. | |
130 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
131 :return: :class:`Response <Response>` object | |
132 :rtype: requests.Response | |
133 """ | |
134 | |
135 return request('patch', url, data=data, **kwargs) | |
136 | |
137 | |
138 def delete(url, **kwargs): | |
139 """Sends a DELETE request. | |
140 | |
141 :param url: URL for the new :class:`Request` object. | |
142 :param \*\*kwargs: Optional arguments that ``request`` takes. | |
143 :return: :class:`Response <Response>` object | |
144 :rtype: requests.Response | |
145 """ | |
146 | |
147 return request('delete', url, **kwargs) |