Skip to content
Myr

Merge branch 'release/0.6.3'

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 98c719f, 80cd1ee · Browse files · 15 files+270 added−84 removed
This commit

State

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

Diff stats

15 files+270 added−84 removed

  • other:+270 added−84 removed

15 files+270 added−84 removed

modified:docs/community/faq.rst+43 added-3 removed
1 unmodified line
23Frequently Asked Questions4==========================56This part of the documentation covers common questions about Requests.6This part of the documentation answers common questions about Requests.78Encoded Data?9-------------1011Requests automatically decompresses gzip-encoded responses, and does12its best to decodes response content to unicode when possible.1314You can get direct access to the raw response (and even the socket),15if needed as well.161718Custom User-Agents?19-------------------2021Requests allows you to easily override User-Agent strings, along with22any other HTTP Header.232425Why not Httplib2?26-----------------2728Chris Adams gave an excellent summary on
21 unmodified lines
5051Python 3 Support?52-----------------5337It's on the way. Here's a list of `supported interpreters <interpreters>`_.54It's on the way. Here's a list of Python platforms that are officially55supported:5657* cPython 2.558* cPython 2.5.559* cPython 2.5.660* cPython 2.661* cPython 2.6.662* cPython 2.6.763* cPython 2.764* cPython 2.7.165* cPython 2.7.266* PyPy-c 1.467* PyPy-c 1.5686970Support for Python 3.x is coming *very* soon.717273Keep-alive Support?74-------------------7543It's on the way.76It's on the way.777879Proxy Support?80--------------8182You bet!83
modified:docs/community/updates.rst-1 removed
18 unmodified lines
1920Follow `@kennethreitz <https://twitter.com/kennethreitz>`_ for updates.21222323Mailing List24------------2526There's a low-volume mailing list for Requests. To subscribe to the
4 unmodified lines
modified:docs/user/advanced.rst+36 added-2 removed
41 unmodified lines
42 Certain parameters are best set at the ``request.config`` level43 (e.g.. a global proxy, user agent header).444546Asynchronous Requests47----------------------4849Requests has first-class support for non-blocking i/o requests, powered50by gevent. This allows you to send a bunch of HTTP requests at the same5152First, let's import the async module. Heads up — if you don't have53**gevent** installed, this will fail.::5455 from requests import async5657The ``async`` module has the exact same api as ``requests``, except it58doesn't send the request immediately. Instead, it returns the ``Request``59object.6061We can build a list of ``Request`` objects easily::6263 urls = [64 'http://python-requests.org',65 'http://httpbin.org',66 'http://python-guide.org',67 'http://kennethreitz.com'68 ]6970 rs = [async.get(u) for u in urls]7172Now we have a list of ``Request`` objects, ready to be sent. We could73send them one at a time with ``Request.send()``, but that would take a while.74Instead, we'll send them all at the same time with ``async.map()``::7576 >>> async.map(rs)77 [<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>]787980Event Hooks81-----------8283Requests has a hook system that you can use to manipulate portions of
15 unmodified lines
99100101You can assign a hook function on a per-request basis by passing a102``{hook_name: callback_function}`` dictionary to the ``hooks`` request69paramaeter::103parameter::104105 hooks=dict(args=print_url)106107That ``callback_function`` will receive a chunk of data as its first
59 unmodified lines
167168 >>> requests.settings.verbose = sys.stderr169 >>> requests.get('http://httpbin.org/headers')170 2011-08-17T03:04:23.380175 GET http://httpbin.org/headers137 <Response [200]>171 <Response [200]>
modified:docs/user/install.rst+6 added-3 removed
1 unmodified line
23Installation4============56This part of the documentation covers the installation of Requests. The first step to using any software package is getting it properly installed.6This part of the documentation covers the installation of Requests.7The first step to using any software package is getting it properly installed.8910Distribute & Pip11----------------
12 unmodified lines
2425Cheeseshop Mirror26-----------------2727If the Cheeseshop is down, you can also install Requests from Kenneth Reitz's personal `Cheeseshop mirror <http://pip.kreitz.co/>`_::28If the Cheeseshop is down, you can also install Requests from Kenneth Reitz's29personal `Cheeseshop mirror <http://pip.kreitz.co/>`_::3031 $ pip install -i http://pip.kreitz.co/simple requests3233
15 unmodified lines
4950 $ curl -O https://github.com/kennethreitz/requests/zipball/master515251Once you have a copy of the source, you can embed it in your Python package, or install it into your site-packages easily::53Once you have a copy of the source, you can embed it in your Python package,54or install it into your site-packages easily::5556 $ python setup.py install
modified:docs/user/intro.rst+8 added-21 removed
19 unmodified lines
2021ISC License22-----------2324A large number of open source projects you find today are `GPL Licensed`_.25While the GPL has its time and place, it should most certainly not be your26go-to license for your next open source project.2725A large number of open source projects you find today are `GPL Licensed`_. While the GPL has its time and place, it should most certainly not be your go-to license for your next open source project.28A project that is released as GPL cannot be used in any commercial product29without the product itself also being offered as open source.3027A project that is released as GPL cannot be used in any commercial product without the product itself also being offered as open source. The MIT, BSD, ISC, and Apache2 licenses are great alternatives to the GPL that allow your open-source software to be used freely in proprietary, closed-source software.31The MIT, BSD, ISC, and Apache2 licenses are great alternatives to the GPL32that allow your open-source software to be used freely in proprietary,33closed-source software.3435Requests is released under terms of `The ISC License`_.3637.. _`GPL Licensed`: http://www.opensource.org/licenses/gpl-license.php
9 unmodified lines
4748 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.495045.. _interpreters:46Python Interpreters47-------------------5149At this time, the following Python platforms are officially supported:5051* cPython 2.552* cPython 2.5.553* cPython 2.5.654* cPython 2.655* cPython 2.6.656* cPython 2.6.757* cPython 2.758* cPython 2.7.159* cPython 2.7.260* PyPy-c 1.461* PyPy-c 1.5626364Support for Python 3.x is planned.
modified:docs/user/quickstart.rst+8 added-4 removed
3 unmodified lines
4==========56.. module:: requests.models78Eager to get started? This page gives a good introduction in how to get started with Requests. This assumes you already have Requests installed. If you do not, head over to the :ref:`Installation <install>` section.8Eager to get started? This page gives a good introduction in how to get started9with Requests. This assumes you already have Requests installed. If you do not,10head over to the :ref:`Installation <install>` section.1112First, make sure that:1314* Requests is :ref:`installed <install>`
11 unmodified lines
26Let's get GitHub's public timeline ::2728 r = requests.get('https://github.com/timeline.json')2928Now, we have a :class:`Response` object called ``r``. We can get all the information we need from this.30Now, we have a :class:`Response` object called ``r``. We can get all the31information we need from this.323334Response Content35----------------
56 unmodified lines
92 'etag': '"e1ca502697e5c9317743dc078f67693f"',93 'content-type': 'application/json; charset=utf-8'94 }9593The dictionary is special, though: it's made just for HTTP headers. According to `RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>`_, HTTP96The dictionary is special, though: it's made just for HTTP headers. According to97`RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>`_, HTTP98Headers are case-insensitive.99100So, we can access the headers using any capitalization we want::101
19 unmodified lines
121122 >>> print r.cookies123 {'requests-is': 'awesome'}124121The underlying CookieJar is also available for more advanced handing::125The underlying CookieJar is also available for more advanced handling::126127 >>> r.request.cookiejar128 <cookielib.CookieJar>129
9 unmodified lines
modified:docs/api.rst+48 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_cookiejar5051Curl52~~~~53.. autofunction:: curl_from_request5455Encodings56~~~~~~~~~5758.. autofunction:: get_encodings_from_content59.. autofunction:: get_encoding_from_headers60.. autofunction:: get_unicode_from_response61.. autofunction:: decode_gzip626364Internals65---------6667These items are an internal component to Requests, and should never be68seen by the end user (developer). This part of the API documentation69exists for those who are extending the functionality of Requests.7071Exceptions72~~~~~~~~~~7374.. module:: requests7576.. autoexception:: HTTPError7778.. autoexception:: RequestException7980.. autoexception:: AuthenticationError81.. autoexception:: URLRequired82.. autoexception:: InvalidMethod83.. autoexception:: TooManyRedirects84858687Classes88~~~~~~~8956.. autoclass:: requests.models.Request90.. autoclass:: requests.Request91 :inherited-members:9293
modified:docs/index.rst+11 added-7 removed
34 unmodified lines
35multipart files, and parameters with simple Python dictionaries, and access the36response data in the same way. It's powered by :py:class:`urllib2`, but it does37all the hard work and crazy hacks for you.3839Testimonals40-----------39Testimonials40------------4142`Twitter, Inc <http://twitter.com>`_ uses Requests internally.42`Twitter, Inc <http://twitter.com>`_,43a U.S. Federal Institution,44`Readability <http://readability.com>`_, and45`Work for Pie <http://workforpie.com>`_46use Requests internally.4748**Armin Ronacher**49 Requests is the perfect example how beautiful an API can be with the50 right level of abstraction.5152**Daniel Greenfeld**53 Nuked a 1200 LOC spaghetti code library with 10 lines of code thanks to54 @kennethreitz's request library. Today has been AWESOME.55
3 unmodified lines
5960**Rich Leland**61 Requests is awesome. That is all.6255**Steve Pike**56 I can never remember how to do it the regular way.57 ``import requests; requests.get()`` is just so easy!635964User Guide65----------6667This part of the documentation, which is mostly prose, begins with some
49 unmodified lines
modified:requests/api.py+6 added-2 removed
15 unmodified lines
16from .status_codes import codes17from .hooks import dispatch_hook18from .utils import cookiejar_from_dict1920from urlparse import urlparse2021__all__ = ('request', 'get', 'head', 'post', 'patch', 'put', 'delete')2223def request(method, url,24 params=None, data=None, headers=None, cookies=None, files=None, auth=None,26 timeout=None, allow_redirects=False, proxies=None, hooks=None):25 timeout=None, allow_redirects=False, proxies=None, hooks=None, return_response=True):2627 """Constructs and sends a :class:`Request <models.Request>`.28 Returns :class:`Response <models.Response>` object.29
23 unmodified lines
53 headers = headers,54 cookiejar = cookies,55 files = files,56 auth = auth,57 hooks = hooks,58 timeout = timeout or config.settings.timeout,59 allow_redirects = allow_redirects,60 proxies = proxies or config.settings.proxies,61 )
5 unmodified lines
6768 # Pre-request hook.69 r = dispatch_hook('pre_request', hooks, r)7071 # Don't send if asked nicely.72 if not return_response:73 return r7475 # Send the HTTP Request.76 r.send()7778 # Post-request hook.
114 unmodified lines
modified:requests/async.py+68 added-25 removed
1# -*- coding: utf-8 -*-23"""4 requests.async5 ~~~~~~~~~~~~~~4requests.async5~~~~~~~~~~~~~~67 This module implements the main Requests system, after monkey-patching8 the urllib2 module with eventlet or gevent..910 :copyright: (c) 2011 by Kenneth Reitz.11 :license: ISC, see LICENSE for more details.7This module contains an asynchronous replica of ``requests.api``, powered8by gevent. All API methods return a ``Request`` instance (as opposed to9``Response``). A list of requests can be sent with ``map()``.10"""1112try:13 import gevent14 from gevent import monkey as curious_george15except ImportError:16 raise RuntimeError('Gevent is required for requests.async.')1715from __future__ import absolute_import18# Monkey-patch.19curious_george.patch_all(thread=False)2017import urllib18import urllib221from . import api22from .hooks import dispatch_hook2320from urllib2 import HTTPError2425__all__ = (26 'map',27 'get', 'head', 'post', 'put', 'patch', 'delete', 'request'28)2923try:24 import eventlet25 eventlet.monkey_patch()26except ImportError:27 pass3029if not 'eventlet' in locals():30 try:31 from gevent import monkey32 monkey.patch_all()33 except ImportError:34 pass31def _patched(f):32 """Patches a given API function to not send."""3334 def wrapped(*args, **kwargs):35 return f(*args, return_response=False, **kwargs)3637if not 'eventlet' in locals():38 raise ImportError('No Async adaptations of urllib2 found!')37 return wrapped383941from .core import *40def _send(r, pools=None):41 """Sends a given Request object."""4243 if pools:44 r._pools = pools4546 r.send()4748 # Post-request hook.49 r = dispatch_hook('post_request', r.hooks, r)5051 # Response manipulation hook.52 r.response = dispatch_hook('response', r.hooks, r.response)5354 return r.response555657# Patched requests.api functions.58get = _patched(api.get)59head = _patched(api.head)60post = _patched(api.post)61put = _patched(api.put)62patch = _patched(api.patch)63delete = _patched(api.delete)64request = _patched(api.request)656667def map(requests, prefetch=True):68 """Concurrently converts a list of Requests to Responses.6970 :param requests: a collection of Request objects.71 :param prefetch: If False, the content will not be downloaded immediately.72 """7374 jobs = [gevent.spawn(_send, r) for r in requests]75 gevent.joinall(jobs)7677 if prefetch:78 [r.response.content for r in requests]7980 return [r.response for r in requests]81828384
modified:requests/core.py+2 added-2 removed
10 unmodified lines
1112"""1314__title__ = 'requests'15__version__ = '0.6.1'16__build__ = 0x00060115__version__ = '0.6.3'16__build__ = 0x00060317__author__ = 'Kenneth Reitz'18__license__ = 'ISC'19__copyright__ = 'Copyright 2011 Kenneth Reitz'20
7 unmodified lines
modified:requests/models.py+5 added-1 removed
35 unmodified lines
3637 def __init__(self,38 url=None, headers=dict(), files=None, method=None, data=dict(),39 params=dict(), auth=None, cookiejar=None, timeout=None, redirect=False,40 allow_redirects=False, proxies=None):40 allow_redirects=False, proxies=None, hooks=None):4142 #: Float describ the timeout of the request.43 # (Use socket.setdefaulttimeout() as fallback)44 self.timeout = timeout
48 unmodified lines
9394 #: True if Request has been sent.95 self.sent = False9697 #: Event-handling hooks.98 self.hooks = hooks99100 # Header manipulation and defaults.101102 if settings.accept_gzip:
259 unmodified lines
362 except (urllib2.HTTPError, urllib2.URLError), why:363 if hasattr(why, 'reason'):364 if isinstance(why.reason, socket.timeout):365 why = Timeout(why)366 elif isinstance(why.reason, socket.error):367 why = Timeout(why)368369 self._build_response(why, is_error=True)370371
254 unmodified lines
modified:HISTORY.rst+12 added
1History2-------340.6.3 (2011-10-13)5++++++++++++++++++67* Beautiful ``requests.async`` module, for making async requests w/ gevent.89100.6.2 (2011-10-09)11++++++++++++++++++1213* GET/HEAD obeys allow_redirects=False1415160.6.1 (2011-08-20)17++++++++++++++++++1819* Enhanced status codes experience ``\o/``
18 unmodified lines
38* HTTPError handling improvements39* Improved https testing40* Bugfixes4142430.5.1 (2011-07-23)44++++++++++++++++++4546* International Domain Name Support!
127 unmodified lines
added:Makefile+14 added
1init:2 pip install -r reqs.txt34test:5 nosetests test_requests.py --processes=3067ci: init8 nosetests --search-test --processes=30 --with-nosexunit test_requests.py9 pyflakes requests | awk -F\: '{printf "%s:%s: [E]%s\n", $1, $2, $3}' > violations.pyflakes.txt1011site:12 cd docs; make dirhtml1314docs: site
modified:test_requests.py+3 added-1 removed
14 unmodified lines
1516from requests.sessions import Session171819HTTPBIN_URL = 'http://httpbin.org/'19HTTPBIN_URL = 'http://httpbin.ep.io/'20HTTPSBIN_URL = 'https://httpbin.ep.io/'2122# HTTPBIN_URL = 'http://staging.httpbin.org/'23# HTTPSBIN_URL = 'https://httpbin-staging.ep.io/'
17 unmodified lines
4142class RequestsTestSuite(unittest.TestCase):43 """Requests test cases."""4445 # It goes to eleven.46 _multiprocess_can_split_ = True4748 def setUp(self):49 pass50
445 unmodified lines