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
Provenance
- Commit
596aceb- Tree
9d717f1- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent
1f3e53b
5 files changed+82 added−82 removed
modified:docs/api.rst+44 added-12 removed
11 unmodified lines12 13 Main Interface14 --------------15 16-All of Request's functionality can be accessed by these 6 methods. They17-all return a :class:`Response <models.Response>` object.16+All of Request's functionality can be accessed by these 7 methods.17+They all return an instance of the :class:`Response <Response>` object.18 19+.. autofunction:: request20 .. autofunction:: head21 .. autofunction:: get22 .. autofunction:: post23 .. autofunction:: put24 .. autofunction:: patch25 .. autofunction:: delete25-.. autofunction:: request26 27+28 -----------29 30 30-.. autoclass:: requests.models.Response31+.. autoclass:: Response32 :inherited-members:33 34 34-Exceptions35-----------35 37-.. autoexception:: HTTPError36+Utilities37+---------38 39-.. autoexception:: RequestException39+These functions are used internally, but may be useful outside of40+Requests.41 41-.. autoexception:: requests.models.AuthenticationError42-.. autoexception:: requests.models.URLRequired43-.. autoexception:: requests.models.InvalidMethod42+.. module:: requests.utils43 44+Cookies45+~~~~~~~46 47+.. autofunction:: dict_from_cookiejar48+.. autofunction:: cookiejar_from_dict49+.. autofunction:: add_dict_to_cookiejar50+51+Encodings52+~~~~~~~~~53+54+.. autofunction:: get_encodings_from_content55+.. autofunction:: get_encoding_from_headers56+.. autofunction:: get_unicode_from_response57+.. autofunction:: decode_gzip58+59+60 Internals61 ---------62 63 These items are an internal component to Requests, and should never be64 seen by the end user (developer). This part of the API documentation65 exists for those who are extending the functionality of Requests.66 67+Exceptions68+~~~~~~~~~~69+70+.. module:: requests71+72+.. autoexception:: HTTPError73+74+.. autoexception:: RequestException75+76+.. autoexception:: AuthenticationError77+.. autoexception:: URLRequired78+.. autoexception:: InvalidMethod79+.. autoexception:: TooManyRedirects80+81+82+83 Classes84 ~~~~~~~85 56-.. autoclass:: requests.models.Request86+.. autoclass:: requests.Request87 :inherited-members:88+89+modified:requests/api.py+16 added-54 removed
23 unmodified lines24 def 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):27 28- """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.30 31 :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 lines40 :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 """43 44+ method = method.upper()45+46 if cookies is None:47 cookies = {}48 49 cookies = cookiejar_from_dict(cookies)36 unmodified lines86 87 """Sends a GET request. Returns :class:`Response` object.88 89 :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 """92 96- return request('GET', url, **kwargs)93+ return request('get', url, **kwargs)94 95 96 def head(url, **kwargs):100-97 """Sends a HEAD request. Returns :class:`Response` object.98 99 :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 """102 112- return request('HEAD', url, **kwargs)103+ return request('head', url, **kwargs)104 105 106 def post(url, data='', **kwargs):116-107 """Sends a POST request. Returns :class:`Response` object.108 109 :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 """113 131- return request('POST', url, data=data, **kwargs)114+ return request('post', url, data=data, **kwargs)115 116 117 def put(url, data='', **kwargs):118 """Sends a PUT request. Returns :class:`Response` object.119 120 :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 """124 149- return request('PUT', url, data=data, **kwargs)125+ return request('put', url, data=data, **kwargs)126 127 128 def patch(url, data='', **kwargs):129 """Sends a PATCH request. Returns :class:`Response` object.130 131 :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 """135 167- return request('PATCH', url, **kwargs)136+ return request('patch', url, **kwargs)137 138 139 def delete(url, **kwargs):171-140 """Sends a DELETE request. Returns :class:`Response` object.141 142 :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 """145 184- return request('DELETE', url, **kwargs)146+ return request('delete', url, **kwargs)modified:requests/core.py+4 added-2 removed
17 unmodified lines18 __license__ = 'ISC'19 __copyright__ = 'Copyright 2011 Kenneth Reitz'20 21 22-from models import HTTPError22+from models import HTTPError, Request, Response23 from api import *24 from exceptions import *25 from sessions import session26 from status_codes import codes27-from config import settings27+from config import settings28+29+import utilsmodified:requests/models.py+13 added-13 removed
29 unmodified lines30 31 32 33 class 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 """37 38 def __init__(self,7 unmodified lines46 47 #: Request URL.48 self.url = url49 50- #: 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 = headers52 53 #: Dictionary of files to multipart upload (``{filename: content}``).54 self.files = files1 unmodified line56 #: HTTP Method to use.57 self.method = method58 59 #: Dictionary or byte of request body data to attach to the60- #: :class:`Request <models.Request>`.60+ #: :class:`Request <Request>`.61 self.data = None62 63 #: Dictionary or byte of querystring data to attach to the64- #: :class:`Request <models.Request>`.64+ #: :class:`Request <Request>`.65 self.params = None66 67- #: 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 = redirect70 71 #: Set to True if full redirects are allowed (e.g. re-POST-ing of data at new ``Location``)4 unmodified lines76 77 self.data, self._enc_data = self._encode_params(data)78 self.params, self._enc_params = self._encode_params(params)79 80- #: :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()83 84 if isinstance(auth, (list, tuple)):85 auth = AuthObject(*auth)86 if not auth:87 auth = auth_manager.get_auth(self.url)88 89- #: :class:`AuthObject` to attach to :class:`Request <models.Request>`.89+ #: :class:`AuthObject` to attach to :class:`Request <Request>`.90 self.auth = auth91 92- #: CookieJar to attach to :class:`Request <models.Request>`.92+ #: CookieJar to attach to :class:`Request <Request>`.93 self.cookiejar = cookiejar94 95 #: True if Request has been sent.96 self.sent = False76 unmodified lines173 return opener.open174 175 176 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 """180 181 203 unmodified lines385 return self.sent386 387 388 class 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 """394 395 def __init__(self):22 unmodified lines418 419 #: Resulting :class:`HTTPError` of request, if one occured.420 self.error = None421 422- #: 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 linesmodified:requests/utils.py+5 added-1 removed
114 unmodified lines115 116 :param r: Reponse object to get unicode content from.117 118 Tried:119+120 1. charset from content-type120- 2. every encodings from <meta ... charset=XXX>121+122+ 2. every encodings from ``<meta ... charset=XXX>``123+124 3. fall back and replace all unicode characters125+126 """127 128 tried_encodings = []129 36 unmodified lines