Skip to content
Myr

big docs update

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 · parent 1f3e53b · Browse files · 5 files+82 added−82 removed
This commit

State

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

Diff stats

5 files+82 added−82 removed

  • other:+82 added−82 removed

5 files+82 added−82 removed

modified:docs/api.rst+44 added-12 removed
11 unmodified lines
1213Main Interface14--------------1516All of Request's functionality can be accessed by these 6 methods. They17all return a :class:`Response <models.Response>` object.16All of Request's functionality can be accessed by these 7 methods.17They all return an instance of the :class:`Response <Response>` object.1819.. autofunction:: request20.. autofunction:: head21.. autofunction:: get22.. autofunction:: post23.. autofunction:: put24.. autofunction:: patch25.. autofunction:: delete25.. autofunction:: request262728-----------293030.. autoclass:: requests.models.Response31.. autoclass:: Response32 :inherited-members:333434Exceptions35----------3537.. autoexception:: HTTPError36Utilities37---------3839.. autoexception:: RequestException39These functions are used internally, but may be useful outside of40Requests.4141.. autoexception:: requests.models.AuthenticationError42.. autoexception:: requests.models.URLRequired43.. autoexception:: requests.models.InvalidMethod42.. module:: requests.utils4344Cookies45~~~~~~~4647.. autofunction:: dict_from_cookiejar48.. autofunction:: cookiejar_from_dict49.. autofunction:: add_dict_to_cookiejar5051Encodings52~~~~~~~~~5354.. autofunction:: get_encodings_from_content55.. autofunction:: get_encoding_from_headers56.. autofunction:: get_unicode_from_response57.. autofunction:: decode_gzip585960Internals61---------6263These items are an internal component to Requests, and should never be64seen by the end user (developer). This part of the API documentation65exists for those who are extending the functionality of Requests.6667Exceptions68~~~~~~~~~~6970.. module:: requests7172.. autoexception:: HTTPError7374.. autoexception:: RequestException7576.. autoexception:: AuthenticationError77.. autoexception:: URLRequired78.. autoexception:: InvalidMethod79.. autoexception:: TooManyRedirects80818283Classes84~~~~~~~8556.. autoclass:: requests.models.Request86.. autoclass:: requests.Request87 :inherited-members:8889
modified:requests/api.py+16 added-54 removed
23 unmodified lines
24def request(method, url,25 params=None, data=None, headers=None, cookies=None, files=None, auth=None,26 timeout=None, allow_redirects=False, proxies=None, hooks=None):2728 """Constructs and sends a :class:`Request <models.Request>`.29 Returns :class:`Response <models.Response>` object.28 """Constructs and sends a :class:`Request <Request>`.29 Returns :class:`Response <Response>` object.3031 :param method: method for the new :class:`Request` object.32 :param url: URL for the new :class:`Request` object.33 :param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
6 unmodified lines
40 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.41 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.42 """4344 method = method.upper()4546 if cookies is None:47 cookies = {}4849 cookies = cookiejar_from_dict(cookies)
36 unmodified lines
8687 """Sends a GET request. Returns :class:`Response` object.8889 :param url: URL for the new :class:`Request` object.88 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.89 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.90 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.91 :param auth: (optional) AuthObject to enable Basic HTTP Auth.92 :param timeout: (optional) Float describing the timeout of the request.93 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.90 :param **kwargs: Optional arguments that ``request`` takes.91 """9296 return request('GET', url, **kwargs)93 return request('get', url, **kwargs)949596def head(url, **kwargs):10097 """Sends a HEAD request. Returns :class:`Response` object.9899 :param url: URL for the new :class:`Request` object.104 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.105 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.106 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.107 :param auth: (optional) AuthObject to enable Basic HTTP Auth.108 :param timeout: (optional) Float describing the timeout of the request.109 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.100 :param **kwargs: Optional arguments that ``request`` takes.101 """102112 return request('HEAD', url, **kwargs)103 return request('head', url, **kwargs)104105106def post(url, data='', **kwargs):116107 """Sends a POST request. Returns :class:`Response` object.108109 :param url: URL for the new :class:`Request` object.110 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.121 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.122 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.123 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.124 :param auth: (optional) AuthObject to enable Basic HTTP Auth.125 :param timeout: (optional) Float describing the timeout of the request.126 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.127 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.128 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.111 :param **kwargs: Optional arguments that ``request`` takes.112 """113131 return request('POST', url, data=data, **kwargs)114 return request('post', url, data=data, **kwargs)115116117def put(url, data='', **kwargs):118 """Sends a PUT request. Returns :class:`Response` object.119120 :param url: URL for the new :class:`Request` object.121 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.139 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.140 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.141 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.142 :param auth: (optional) AuthObject to enable Basic HTTP Auth.143 :param timeout: (optional) Float describing the timeout of the request.144 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.145 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.146 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.122 :param **kwargs: Optional arguments that ``request`` takes.123 """124149 return request('PUT', url, data=data, **kwargs)125 return request('put', url, data=data, **kwargs)126127128def patch(url, data='', **kwargs):129 """Sends a PATCH request. Returns :class:`Response` object.130131 :param url: URL for the new :class:`Request` object.132 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.157 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.158 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.159 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.160 :param auth: (optional) AuthObject to enable Basic HTTP Auth.161 :param timeout: (optional) Float describing the timeout of the request.162 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.163 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.164 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.133 :param **kwargs: Optional arguments that ``request`` takes.134 """135167 return request('PATCH', url, **kwargs)136 return request('patch', url, **kwargs)137138139def delete(url, **kwargs):171140 """Sends a DELETE request. Returns :class:`Response` object.141142 :param url: URL for the new :class:`Request` object.175 :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`.176 :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`.177 :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.178 :param auth: (optional) AuthObject to enable Basic HTTP Auth.179 :param timeout: (optional) Float describing the timeout of the request.180 :param allow_redirects: (optional) Boolean. Set to True if redirect following is allowed.181 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.143 :param **kwargs: Optional arguments that ``request`` takes.144 """145184 return request('DELETE', url, **kwargs)146 return request('delete', url, **kwargs)
modified:requests/core.py+4 added-2 removed
17 unmodified lines
18__license__ = 'ISC'19__copyright__ = 'Copyright 2011 Kenneth Reitz'202122from models import HTTPError22from models import HTTPError, Request, Response23from api import *24from exceptions import *25from sessions import session26from status_codes import codes27from config import settings27from config import settings2829import utils
modified:requests/models.py+13 added-13 removed
29 unmodified lines
30313233class Request(object):34 """The :class:`Request <models.Request>` object. It carries out all functionality of34 """The :class:`Request <Request>` object. It carries out all functionality of35 Requests. Recommended interface is with the Requests functions.36 """3738 def __init__(self,
7 unmodified lines
4647 #: Request URL.48 self.url = url4950 #: Dictonary of HTTP Headers to attach to the :class:`Request <models.Request>`.50 #: Dictonary of HTTP Headers to attach to the :class:`Request <Request>`.51 self.headers = headers5253 #: Dictionary of files to multipart upload (``{filename: content}``).54 self.files = files
1 unmodified line
56 #: HTTP Method to use.57 self.method = method5859 #: Dictionary or byte of request body data to attach to the60 #: :class:`Request <models.Request>`.60 #: :class:`Request <Request>`.61 self.data = None6263 #: Dictionary or byte of querystring data to attach to the64 #: :class:`Request <models.Request>`.64 #: :class:`Request <Request>`.65 self.params = None6667 #: True if :class:`Request <models.Request>` is part of a redirect chain (disables history67 #: True if :class:`Request <Request>` is part of a redirect chain (disables history68 #: and HTTPError storage).69 self.redirect = redirect7071 #: Set to True if full redirects are allowed (e.g. re-POST-ing of data at new ``Location``)
4 unmodified lines
7677 self.data, self._enc_data = self._encode_params(data)78 self.params, self._enc_params = self._encode_params(params)7980 #: :class:`Response <models.Response>` instance, containing80 #: :class:`Response <Response>` instance, containing81 #: content and metadata of HTTP Response, once :attr:`sent <send>`.82 self.response = Response()8384 if isinstance(auth, (list, tuple)):85 auth = AuthObject(*auth)86 if not auth:87 auth = auth_manager.get_auth(self.url)8889 #: :class:`AuthObject` to attach to :class:`Request <models.Request>`.89 #: :class:`AuthObject` to attach to :class:`Request <Request>`.90 self.auth = auth9192 #: CookieJar to attach to :class:`Request <models.Request>`.92 #: CookieJar to attach to :class:`Request <Request>`.93 self.cookiejar = cookiejar9495 #: True if Request has been sent.96 self.sent = False
76 unmodified lines
173 return opener.open174175176 def _build_response(self, resp, is_error=False):177 """Build internal :class:`Response <models.Response>` object177 """Build internal :class:`Response <Response>` object178 from given response.179 """180181
203 unmodified lines
385 return self.sent386387388class Response(object):389 """The core :class:`Response <models.Response>` object. All390 :class:`Request <models.Request>` objects contain a391 :class:`response <models.Response>` attribute, which is an instance389 """The core :class:`Response <Response>` object. All390 :class:`Request <Request>` objects contain a391 :class:`response <Response>` attribute, which is an instance392 of this class.393 """394395 def __init__(self):
22 unmodified lines
418419 #: Resulting :class:`HTTPError` of request, if one occured.420 self.error = None421422 #: A list of :class:`Response <models.Response>` objects from422 #: A list of :class:`Response <Response>` objects from423 #: the history of the Request. Any redirect responses will end424 #: up here.425 self.history = []426
229 unmodified lines
modified:requests/utils.py+5 added-1 removed
114 unmodified lines
115116 :param r: Reponse object to get unicode content from.117118 Tried:119120 1. charset from content-type120 2. every encodings from <meta ... charset=XXX>121122 2. every encodings from ``<meta ... charset=XXX>``123124 3. fall back and replace all unicode characters125126 """127128 tried_encodings = []129
36 unmodified lines