Skip to content
Myr

Merge branch 'feature/timeout' 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 59dd3ed, 45ca6d8 · Browse files · 2 files+44 added−14 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+44 added−14 removed

  • other:+44 added−14 removed

2 files+44 added−14 removed

modified:requests/__init__.py+25 added
1# -*- coding: utf-8 -*-23import inspect45import packages6from core import *78from core import __version__910timeout = None1112class settings:13 """Context manager for settings."""14 15 cache = {}16 17 def __init__(self, timeout):18 self.module = inspect.getmodule(self)19 20 # Cache settings21 self.cache['timeout'] = self.module.timeout22 23 self.module.timeout = timeout24 25 def __enter__(self):26 pass27 28 def __exit__(self, type, value, traceback):29 # Restore settings 30 for key in self.cache:31 setattr(self.module, key, self.cache[key])
modified:requests/core.py+19 added-14 removed
10 unmodified lines
11"""1213from __future__ import absolute_import1415import requests16import urllib17import urllib218import socket19import zlib
4 unmodified lines
24from .packages.poster.encode import multipart_encode25from .packages.poster.streaminghttp import register_openers, get_handlers26272728__title__ = 'requests'29__version__ = '0.3.2'30__build__ = 0x00030231__author__ = 'Kenneth Reitz'
6 unmodified lines
38 'URLRequired', 'InvalidMethod', 'HTTPError'39]40414242class _Request(urllib2.Request):43 """Hidden wrapper around the urllib2.Request object. Allows for manual44 setting of HTTP methods.45 """
410 unmodified lines
456 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.457 :param cookies: (optional) CookieJar object to send with the :class:`Request`.458 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.459 :param auth: (optional) AuthObject to enable Basic HTTP Auth.460 :param timeout: (optional) Float describing the timeout of the request.461 """462 data = kwargs.pop('data', dict()) or kwargs.pop('params', dict())463463 464 r = Request(method=method, url=url, data=data, headers=kwargs.pop('headers', {}),465 cookiejar=kwargs.pop('cookies', None), files=kwargs.pop('files', None),466 auth=kwargs.pop('auth', auth_manager.get_auth(url)),467 timeout=kwargs.pop('timeout', None))467 timeout=kwargs.pop('timeout', requests.timeout))468 r.send()469470 return r.response471472473def get(url, params={}, headers={}, cookies=None, auth=None, timeout=None):473def get(url, params={}, headers={}, cookies=None, auth=None, **kwargs):474 """Sends a GET request. Returns :class:`Response` object.475476 :param url: URL for the new :class:`Request` object.477 :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.478 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.479 :param cookies: (optional) CookieJar object to send with the :class:`Request`.480 :param auth: (optional) AuthObject to enable Basic HTTP Auth.481 :param timeout: (optional) Float describing the timeout of the request.482 """483483 return request('GET', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)484 return request('GET', url, params=params, headers=headers, cookies=cookies, auth=auth, **kwargs)485486486def head(url, params={}, headers={}, cookies=None, auth=None, timeout=None):487def head(url, params={}, headers={}, cookies=None, auth=None, **kwargs):488 """Sends a HEAD request. Returns :class:`Response` object.489490 :param url: URL for the new :class:`Request` object.491 :param params: (optional) Dictionary of GET Parameters to send with the :class:`Request`.492 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.493 :param cookies: (optional) CookieJar object to send with the :class:`Request`.494 :param auth: (optional) AuthObject to enable Basic HTTP Auth.495 :param timeout: (optional) Float describing the timeout of the request.496 """497496 return request('HEAD', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)498 return request('HEAD', url, params=params, headers=headers, cookies=cookies, auth=auth, **kwargs)499500499def post(url, data={}, headers={}, files=None, cookies=None, auth=None, timeout=None):501def post(url, data={}, headers={}, files=None, cookies=None, auth=None, **kwargs):502 """Sends a POST request. Returns :class:`Response` object.503504 :param url: URL for the new :class:`Request` object.505 :param data: (optional) Dictionary of POST data to send with the :class:`Request`.506 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.507 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.508 :param cookies: (optional) CookieJar object to send with the :class:`Request`.509 :param auth: (optional) AuthObject to enable Basic HTTP Auth.510 :param timeout: (optional) Float describing the timeout of the request.511 """512510 return request('POST', url, data=data, headers=headers, files=files, cookies=cookies, auth=auth, timeout=timeout)513 return request('POST', url, data=data, headers=headers, files=files, cookies=cookies, auth=auth, **kwargs)514515513def put(url, data='', headers={}, files={}, cookies=None, auth=None, timeout=None):516def put(url, data='', headers={}, files={}, cookies=None, auth=None, **kwargs):517 """Sends a PUT request. Returns :class:`Response` object.518519 :param url: URL for the new :class:`Request` object.520 :param params: (optional) Bytes of PUT Data to send with the :class:`Request`.521 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.522 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.523 :param cookies: (optional) CookieJar object to send with the :class:`Request`.524 :param auth: (optional) AuthObject to enable Basic HTTP Auth.525 :param timeout: (optional) Float describing the timeout of the request.526 """527524 return request('PUT', url, data=data, headers=headers, files=files, cookies=cookies, auth=auth, timeout=timeout)528 return request('PUT', url, data=data, headers=headers, files=files, cookies=cookies, auth=auth, **kwargs)529530527def delete(url, params={}, headers={}, cookies=None, auth=None, timeout=None):531def delete(url, params={}, headers={}, cookies=None, auth=None, **kwargs):532 """Sends a DELETE request. Returns :class:`Response` object.533534 :param url: URL for the new :class:`Request` object.535 :param params: (optional) Dictionary of DELETE Parameters to send with the :class:`Request`.536 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.537 :param cookies: (optional) CookieJar object to send with the :class:`Request`.538 :param auth: (optional) AuthObject to enable Basic HTTP Auth.539 :param timeout: (optional) Float describing the timeout of the request.540 """541537 return request('DELETE', url, params=params, headers=headers, cookies=cookies, auth=auth, timeout=timeout)542 return request('DELETE', url, params=params, headers=headers, cookies=cookies, auth=auth, **kwargs)543544545546class RequestException(Exception):
11 unmodified lines