Support for proxies
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by moliware · committed by moliware · parent bbd1e40 · Browse files · 3 files·+29 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+29 added−13 removed
- other:+29 added−13 removed
Provenance
- Commit
3e7c682- Tree
64edaca- Author
moliware <miguel@moliware.com>- Committer
moliware <miguel@moliware.com>- Parent
bbd1e40
3 files changed+29 added−13 removed
modified:requests/api.py+22 added-12 removed
17 unmodified lines18 19 __all__ = ('request', 'get', 'head', 'post', 'put', 'delete')20 21 def request(method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None,22- timeout=None, allow_redirects=False):22+ timeout=None, allow_redirects=False, proxies=None):23 """Constructs and sends a :class:`Request <models.Request>`. Returns :class:`Response <models.Response>` object.24 25 :param method: method for the new :class:`Request` object.26 :param url: URL for the new :class:`Request` object.4 unmodified lines31 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.32 :param auth: (optional) AuthObject to enable Basic HTTP Auth.33 :param timeout: (optional) Float describing the timeout of the request.34 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.35+ :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.36 """37 38 r = Request(39 method = method,4 unmodified lines44 cookiejar = cookies,45 files = files,46 auth = auth or auth_manager.get_auth(url),47 timeout = timeout or config.settings.timeout,47- allow_redirects = allow_redirects48+ allow_redirects = allow_redirects,49+ proxies = proxies50 )51 52 r.send()53 54 return r.response55 54-def get(url, params=None, headers=None, cookies=None, auth=None, timeout=None):56+def get(url, params=None, headers=None, cookies=None, auth=None, timeout=None, proxies=None):57 """Sends a GET request. Returns :class:`Response` object.58 59 :param url: URL for the new :class:`Request` object.60 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.61 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.62 :param cookies: (optional) CookieJar object to send with the :class:`Request`.63 :param auth: (optional) AuthObject to enable Basic HTTP Auth.64 :param timeout: (optional) Float describing the timeout of the request.65+ :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.66 """67 65- return request('GET', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)68+ return request('GET', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout,69+ proxies=proxies)70 71 68-def head(url, params=None, headers=None, cookies=None, auth=None, timeout=None):72+def head(url, params=None, headers=None, cookies=None, auth=None, timeout=None, proxies=None):73 """Sends a HEAD request. Returns :class:`Response` object.74 75 :param url: URL for the new :class:`Request` object.76 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.77 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.78 :param cookies: (optional) CookieJar object to send with the :class:`Request`.79 :param auth: (optional) AuthObject to enable Basic HTTP Auth.80 :param timeout: (optional) Float describing the timeout of the request.81+ :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.82 """83 79- return request('HEAD', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)84+ return request('HEAD', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout,85+ proxies=proxies)86 87 88 def post(url, data='', headers=None, files=None, cookies=None, auth=None,83- timeout=None, allow_redirects=False, params=None):89+ timeout=None, allow_redirects=False, params=None, proxies=None):90 """Sends a POST request. Returns :class:`Response` object.91 92 :param url: URL for the new :class:`Request` object.93 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.3 unmodified lines97 :param auth: (optional) AuthObject to enable Basic HTTP Auth.98 :param timeout: (optional) Float describing the timeout of the request.99 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.100 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.101+ :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.102 """103 104 return request('POST', url, params=params, data=data, headers=headers,105 files=files, cookies=cookies, auth=auth, timeout=timeout,99- allow_redirects=allow_redirects)106+ allow_redirects=allow_redirects, proxies=proxies)107 108 109 def put(url, data='', headers=None, files=None, cookies=None, auth=None,103- timeout=None, allow_redirects=False, params=None):110+ timeout=None, allow_redirects=False, params=None, proxies=None):111 """Sends a PUT request. Returns :class:`Response` object.112 113 :param url: URL for the new :class:`Request` object.114 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.3 unmodified lines118 :param auth: (optional) AuthObject to enable Basic HTTP Auth.119 :param timeout: (optional) Float describing the timeout of the request.120 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.121 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.122+ :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.123 """124 125 return request('PUT', url, params=params, data=data, headers=headers,126 files=files, cookies=cookies, auth=auth, timeout=timeout,119- allow_redirects=allow_redirects)127+ allow_redirects=allow_redirects, proxies=proxies)128 129 122-def delete(url, params=None, headers=None, cookies=None, auth=None, timeout=None, allow_redirects=False):130+def delete(url, params=None, headers=None, cookies=None, auth=None, timeout=None, allow_redirects=False,131+ proxies=None):132 """Sends a DELETE request. Returns :class:`Response` object.133 134 :param url: URL for the new :class:`Request` object.135 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.1 unmodified line137 :param cookies: (optional) CookieJar object to send with the :class:`Request`.138 :param auth: (optional) AuthObject to enable Basic HTTP Auth.139 :param timeout: (optional) Float describing the timeout of the request.140 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.141+ :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.142 """143 144 return request('DELETE', url, params=params, headers=headers, cookies=cookies, auth=auth,135- timeout=timeout, allow_redirects=allow_redirects)145+ timeout=timeout, allow_redirects=allow_redirects, proxies=proxies)modified:requests/models.py+6 added-1 removed
30 unmodified lines31 _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE')32 33 def __init__(self, url=None, headers=dict(), files=None, method=None,34 data=dict(), params=dict(), auth=None, cookiejar=None,35- timeout=None, redirect=False, allow_redirects=False):35+ timeout=None, redirect=False, allow_redirects=False,36+ proxies=None):37 38 socket.setdefaulttimeout(timeout)39 40 #: Request URL.14 unmodified lines55 #: and HTTPError storage).56 self.redirect = redirect57 #: Set to True if full redirects are allowed (e.g. re-POST-ing of data at new ``Location``)58 self.allow_redirects = allow_redirects59+ # Dictionary mapping protocol to the URL of the proxy (e.g. {'http': 'foo.bar:3128'})60+ self.proxies = proxies61 62 self.data, self._enc_data = self._encode_params(data)63 self.params, self._enc_params = self._encode_params(params)64 47 unmodified lines112 auth_manager.add_auth(self.url, self.auth)113 114 _handlers.append(self.auth.handler)115 116+ if self.proxies:117+ _handlers.append(urllib2.ProxyHandler(self.proxies))118 119 _handlers.append(HTTPRedirectHandler)120 121 if not _handlers:413 unmodified linesmodified:AUTHORS+1 added
22 unmodified lines23 - Daniel Schauenberg24 - Zbigniew Siciarz25 - Daniele Tricoli 'Eriol'26 - Richard Boulton27+- Miguel Olivares <miguel@moliware.com>