Skip to content
Myr

Merge pull request #38 from jgorset/requests

Before adoption: this commit came in with the history the project adopted, so no landing records it.

--- Ive refactored `api.request`. I think. The new version is more robust in that it no longer accepts arbitrary arguments and raises an exception if one attempts to call it with both `params` and `data` (that should probably be supported, though, but thats a topic for another issue). Conflicts: requests/api.py

authored by Kenneth Reitz · committed by Kenneth Reitz · parents 670c4ae, 82f1320 · Browse files · 1 file+15 added−11 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+15 added−11 removed

  • other:+15 added−11 removed

1 file+15 added−11 removed

modified:requests/api.py+15 added-11 removed
16 unmodified lines
171819__all__ = ('request', 'get', 'head', 'post', 'put', 'delete')20212223def request(method, url, **kwargs):21def request(method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None,22 timeout=config.settings.timeout, allow_redirects=False):23 """Constructs and sends a :class:`Request <models.Request>`. Returns :class:`Response <models.Response>` object.2425 :param method: method for the new :class:`Request` object.26 :param url: URL for the new :class:`Request` object.
5 unmodified lines
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 """37 data = kwargs.pop('data', dict()) or kwargs.pop('params', dict())3639 r = Request(method=method, url=url, data=data, headers=kwargs.pop('headers', dict()),40 cookiejar=kwargs.get('cookies', None),41 files=kwargs.get('files', None),42 auth=kwargs.get('auth', auth_manager.get_auth(url)),43 timeout=kwargs.get('timeout', config.settings.timeout),44 allow_redirects=kwargs.get('allow_redirects', None)37 if params and data:38 raise StandardError('You may provide either params or data to a request, but not both.')3940 r = Request(41 method = method,42 url = url,43 data = params or data,44 headers = headers,45 cookiejar = cookies,46 files = files,47 auth = auth or auth_manager.get_auth(url),48 timeout = timeout,49 allow_redirects = allow_redirects50 )5152 r.send()5354 return r.response555156def get(url, params={}, headers={}, cookies=None, auth=None, **kwargs):57 """Sends a GET request. Returns :class:`Response` object.5859 :param url: URL for the new :class:`Request` object.
66 unmodified lines