Merge branch 'timeout' of https://github.com/jgorset/requests into develop
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parents f6f636f, 39e9424 · Browse files · 2 files·+17 added−12 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+17 added−12 removed
- other:+17 added−12 removed
Provenance
- Commit
8349415- Tree
720ed71- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
f6f636f- Parent 2
39e9424
2 files changed+17 added−12 removed
modified:requests/core.py+16 added-12 removed
12 unmodified lines13 from __future__ import absolute_import14 15 import urllib16 import urllib217+import socket18 import zlib19 20 from urllib2 import HTTPError21 from urlparse import urlparse41 unmodified lines63 64 _METHODS = ('GET', 'HEAD', 'PUT', 'POST', 'DELETE')65 66 def __init__(self, url=None, headers=dict(), files=None, method=None,66- data=dict(), auth=None, cookiejar=None):67+ data=dict(), auth=None, cookiejar=None, timeout=None):68 69 self.url = url70 self.headers = headers71 self.files = files72 self.method = method73 self.data = data74+ 75+ socket.setdefaulttimeout(timeout)76 77 # url encode data if it's a dict78 if hasattr(data, 'items'):79 self._enc_data = urllib.urlencode(data)370 unmodified lines450 data = kwargs.pop('data', dict()) or kwargs.pop('params', dict())451 452 r = Request(method=method, url=url, data=data, headers=kwargs.pop('headers', {}),453 cookiejar=kwargs.pop('cookies', None), files=kwargs.pop('files', None),451- auth=kwargs.pop('auth', auth_manager.get_auth(url)))454+ auth=kwargs.pop('auth', auth_manager.get_auth(url)),455+ timeout=kwargs.pop('timeout', None))456 r.send()457 458 return r.response459 460 457-def get(url, params={}, headers={}, cookies=None, auth=None):461+def get(url, params={}, headers={}, cookies=None, auth=None, timeout=None):462 """Sends a GET request. Returns :class:`Response` object.463 464 :param url: URL for the new :class:`Request` object.465 :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.1 unmodified line467 :param cookies: (optional) CookieJar object to send with the :class:`Request`.468 :param auth: (optional) AuthObject to enable Basic HTTP Auth.469 """470 467- return request('GET', url, params=params, headers=headers, cookies=cookies, auth=auth)471+ return request('GET', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)472 473 470-def head(url, params={}, headers={}, cookies=None, auth=None):474+def head(url, params={}, headers={}, cookies=None, auth=None, timeout=None):475 """Sends a HEAD request. Returns :class:`Response` object.476 477 :param url: URL for the new :class:`Request` object.478 :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.1 unmodified line480 :param cookies: (optional) CookieJar object to send with the :class:`Request`.481 :param auth: (optional) AuthObject to enable Basic HTTP Auth.482 """483 480- return request('HEAD', url, params=params, headers=headers, cookies=cookies, auth=auth)484+ return request('HEAD', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)485 486 483-def post(url, data={}, headers={}, files=None, cookies=None, auth=None):487+def post(url, data={}, headers={}, files=None, cookies=None, auth=None, timeout=None):488 """Sends a POST request. Returns :class:`Response` object.489 490 :param url: URL for the new :class:`Request` object.491 :param data: (optional) Dictionary of POST data to send with the :class:`Request`.2 unmodified lines494 :param cookies: (optional) CookieJar object to send with the :class:`Request`.495 :param auth: (optional) AuthObject to enable Basic HTTP Auth.496 """497 494- return request('POST', url, data=data, headers=headers, files=files, cookies=cookies, auth=auth)498+ return request('POST', url, data=data, headers=headers, files=files, cookies=cookies, auth=auth, timeout=timeout)499 500 497-def put(url, data='', headers={}, files={}, cookies=None, auth=None):501+def put(url, data='', headers={}, files={}, cookies=None, auth=None, timeout=None):502 """Sends a PUT request. Returns :class:`Response` object.503 504 :param url: URL for the new :class:`Request` object.505 :param params: (optional) Bytes of PUT Data to send with the :class:`Request`.2 unmodified lines508 :param cookies: (optional) CookieJar object to send with the :class:`Request`.509 :param auth: (optional) AuthObject to enable Basic HTTP Auth.510 """511 508- return request('PUT', url, data=data, headers=headers, files=files, cookies=cookies, auth=auth)512+ return request('PUT', url, data=data, headers=headers, files=files, cookies=cookies, auth=auth, timeout=timeout)513 514 511-def delete(url, params={}, headers={}, cookies=None, auth=None):515+def delete(url, params={}, headers={}, cookies=None, auth=None, timeout=None):516 """Sends a DELETE request. Returns :class:`Response` object.517 518 :param url: URL for the new :class:`Request` object.519 :param params: (optional) Dictionary of DELETE Parameters to send with the :class:`Request`.1 unmodified line521 :param cookies: (optional) CookieJar object to send with the :class:`Request`.522 :param auth: (optional) AuthObject to enable Basic HTTP Auth.523 """524 521- return request('DELETE', url, params=params, headers=headers, cookies=cookies, auth=auth)525+ return request('DELETE', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)526 527 528 529 class RequestException(Exception):11 unmodified linesmodified:AUTHORS+1 added
15 unmodified lines16 - Dj Gilcrease17 - Justin Murphy18 - Rob Madole19 - Aram Dulyan20+- Johannes Gorset