Merge pull request #1831 from kevinburke/interlinks
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Add more interlinks between the documentation
authored by Kenneth Reitz · committed by Kenneth Reitz · parents e93b07e, fad8d74 · Browse files · 2 files·+46 added−35 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+46 added−35 removed
- other:+46 added−35 removed
Provenance
- Commit
6323042- Tree
736c55b- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent 1
e93b07e- Parent 2
fad8d74
2 files changed+46 added−35 removed
modified:docs/user/advanced.rst+40 added-34 removed
107 unmodified lines108 109 print(resp.status_code)110 111 Since you are not doing anything special with the ``Request`` object, you112-prepare it immediately and modified the ``PreparedRequest`` object. You then112+prepare it immediately and modify the ``PreparedRequest`` object. You then113 send that with the other parameters you would have sent to ``requests.*`` or114 ``Sesssion.*``.115 116 However, the above code will lose some of the advantages of having a Requests117 :class:`Session <requests.Session>` object. In particular,118 :class:`Session <requests.Session>`-level state such as cookies will119 not get applied to your request. To get a120 :class:`PreparedRequest <requests.models.PreparedRequest>` with that state121-applied, replace the call to ``Request.prepare()`` with a call to122-``Session.prepare_request()``, like this::121+applied, replace the call to :meth:`Request.prepare()122+<requests.Request.prepare>` with a call to123+:meth:`Session.prepare_request() <requests.Session.prepare_request>`, like this::124 125 from requests import Request, Session126 127 s = Session()54 unmodified lines182 183 Body Content Workflow184 ---------------------185 185-By default, when you make a request, the body of the response is downloaded immediately. You can override this behavior and defer downloading the response body until you access the :class:`Response.content` attribute with the ``stream`` parameter::186+By default, when you make a request, the body of the response is downloaded187+immediately. You can override this behavior and defer downloading the response188+body until you access the :class:`Response.content <requests.Response.content>`189+attribute with the ``stream`` parameter::190 191 tarball_url = 'https://github.com/kennethreitz/requests/tarball/master'192 r = requests.get(tarball_url, stream=True)193 2 unmodified lines196 if int(r.headers['content-length']) < TOO_LONG:197 content = r.content198 ...199 196-You can further control the workflow by use of the :class:`Response.iter_content` and :class:`Response.iter_lines` methods. Alternatively, you can read the undecoded body from the underlying urllib3 :class:`urllib3.HTTPResponse` at :class:`Response.raw`.200+You can further control the workflow by use of the :class:`Response.iter_content <requests.Response.iter_content>` and :class:`Response.iter_lines <requests.Response.iter_lines>` methods. Alternatively, you can read the undecoded body from the underlying urllib3 :class:`urllib3.HTTPResponse <urllib3.response.HTTPResponse>` at :class:`Response.raw <requests.Response.raw>`.201 202 203 Keep-Alive204 ----------103 unmodified lines308 309 Streaming Requests310 ------------------311 308-With ``requests.Response.iter_lines()`` you can easily iterate over streaming309-APIs such as the `Twitter Streaming API <https://dev.twitter.com/docs/streaming-api>`_.310-Simply set ``stream`` to ``True`` and iterate over the response with ``iter_lines()``::312+With :class:`requests.Response.iter_lines()` you can easily313+iterate over streaming APIs such as the `Twitter Streaming314+API <https://dev.twitter.com/docs/streaming-api>`_. Simply315+set ``stream`` to ``True`` and iterate over the response with316+:class:`~requests.Response.iter_lines()`::317 318 import json319 import requests320 50 unmodified lines371 372 Encodings373 ^^^^^^^^^374 369-When you receive a response, Requests makes a guess at the encoding to use for370-decoding the response when you call the ``Response.text`` method. Requests371-will first check for an encoding in the HTTP header, and if none is present,372-will use `chardet <http://pypi.python.org/pypi/chardet>`_ to attempt to guess373-the encoding.375+When you receive a response, Requests makes a guess at the encoding to376+use for decoding the response when you access the :attr:`Response.text377+<requests.Response.text>` attribute. Requests will first check for an378+encoding in the HTTP header, and if none is present, will use `chardet379+<http://pypi.python.org/pypi/chardet>`_ to attempt to guess the encoding.380 375-The only time Requests will not do this is if no explicit charset is present376-in the HTTP headers **and** the ``Content-Type`` header contains ``text``. In377-this situation,378-`RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1>`_379-specifies that the default charset must be ``ISO-8859-1``. Requests follows380-the specification in this case. If you require a different encoding, you can381-manually set the ``Response.encoding`` property, or use the raw382-``Response.content``.381+The only time Requests will not do this is if no explicit charset382+is present in the HTTP headers **and** the ``Content-Type``383+header contains ``text``. In this situation, `RFC 2616384+<http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.7.1>`_ specifies385+that the default charset must be ``ISO-8859-1``. Requests follows the386+specification in this case. If you require a different encoding, you can387+manually set the :attr:`Response.encoding <requests.Response.encoding>`388+property, or use the raw :attr:`Response.content <requests.Response.content>`.389 390 HTTP Verbs391 ----------392 18 unmodified lines411 ... print r.headers['content-type']412 ...413 application/json; charset=utf-8414 409-So, GitHub returns JSON. That's great, we can use the ``r.json`` method to410-parse it into Python objects.415+So, GitHub returns JSON. That's great, we can use the :meth:`r.json416+<requests.Response.json>` method to parse it into Python objects.417 418 ::419 420 >>> commit_data = r.json()167 unmodified lines588 `described here`_. Transport Adapters provide a mechanism to define interaction589 methods for an HTTP service. In particular, they allow you to apply per-service590 configuration.591 586-Requests ships with a single Transport Adapter, the587-:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`. This adapter provides the588-default Requests interaction with HTTP and HTTPS using the powerful `urllib3`_589-library. Whenever a Requests :class:`Session <Session>` is initialized, one of590-these is attached to the :class:`Session <Session>` object for HTTP, and one592+Requests ships with a single Transport Adapter, the :class:`HTTPAdapter593+<requests.adapters.HTTPAdapter>`. This adapter provides the default Requests594+interaction with HTTP and HTTPS using the powerful `urllib3`_ library. Whenever595+a Requests :class:`Session <requests.Session>` is initialized, one of these is596+attached to the :class:`Session <requests.Session>` object for HTTP, and one597 for HTTPS.598 599 Requests enables users to create and use their own Transport Adapters that600 provide specific functionality. Once created, a Transport Adapter can be9 unmodified lines610 prefix. Once mounted, any HTTP request made using that session whose URL starts611 with the given prefix will use the given Transport Adapter.612 613 Implementing a Transport Adapter is beyond the scope of this documentation, but608-a good start would be to subclass the ``requests.adapters.BaseAdapter`` class.614+a good start would be to subclass the :class:`requests.adapters.BaseAdapter` class.615 616 .. _`described here`: http://kennethreitz.org/exposures/the-future-of-python-http617 .. _`urllib3`: https://github.com/shazow/urllib3618 619 Blocking Or Non-Blocking?620 -------------------------621 622 With the default Transport Adapter in place, Requests does not provide any kind617-of non-blocking IO. The ``Response.content`` property will block until the618-entire response has been downloaded. If you require more granularity, the619-streaming features of the library (see :ref:`streaming-requests`) allow you to620-retrieve smaller quantities of the response at a time. However, these calls621-will still block.623+of non-blocking IO. The :attr:`Response.content <requests.Response.content>`624+property will block until the entire response has been downloaded. If625+you require more granularity, the streaming features of the library (see626+:ref:`streaming-requests`) allow you to retrieve smaller quantities of the627+response at a time. However, these calls will still block.628 629 If you are concerned about the use of blocking IO, there are lots of projects630 out there that combine Requests with one of Python's asynchronicity frameworks.631 Two excellent examples are `grequests`_ and `requests-futures`_.3 unmodified linesmodified:docs/conf.py+6 added-1 removed
25 unmodified lines26 #needs_sphinx = '1.0'27 28 # Add any Sphinx extension module names here, as strings. They can be extensions29 # coming with Sphinx (named 'sphinx.ext.*') or your custom ones.30-extensions = ['sphinx.ext.autodoc']30+extensions = [31+ 'sphinx.ext.autodoc',32+ 'sphinx.ext.intersphinx',33+]34 35 # Add any paths that contain templates here, relative to this directory.36 templates_path = ['_templates']37 205 unmodified lines243 244 sys.path.append(os.path.abspath('_themes'))245 html_theme_path = ['_themes']246 html_theme = 'kr'247+248+intersphinx_mapping = {'urllib3': ('http://urllib3.readthedocs.org/en/latest', None)}