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
Provenance
- Commit
1551158- Tree
08d5df6- Author
Kenneth Reitz <me@kennethreitz.com>- Committer
Kenneth Reitz <me@kennethreitz.com>- Parent 1
98c719f- Parent 2
80cd1ee
15 files changed+270 added−84 removed
modified:docs/community/faq.rst+43 added-3 removed
1 unmodified line2 3 Frequently Asked Questions4 ==========================5 6-This part of the documentation covers common questions about Requests.6+This part of the documentation answers common questions about Requests.7 8+Encoded Data?9+-------------10+11+Requests automatically decompresses gzip-encoded responses, and does12+its best to decodes response content to unicode when possible.13+14+You can get direct access to the raw response (and even the socket),15+if needed as well.16+17+18+Custom User-Agents?19+-------------------20+21+Requests allows you to easily override User-Agent strings, along with22+any other HTTP Header.23+24+25 Why not Httplib2?26 -----------------27 28 Chris Adams gave an excellent summary on21 unmodified lines50 51 Python 3 Support?52 -----------------53 37-It's on the way. Here's a list of `supported interpreters <interpreters>`_.54+It's on the way. Here's a list of Python platforms that are officially55+supported:56 57+* 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.568 69+70+Support for Python 3.x is coming *very* soon.71+72+73 Keep-alive Support?74 -------------------75 43-It's on the way.76+It's on the way.77+78+79+Proxy Support?80+--------------81+82+You bet!83+modified:docs/community/updates.rst-1 removed
18 unmodified lines19 20 Follow `@kennethreitz <https://twitter.com/kennethreitz>`_ for updates.21 22 23-23 Mailing List24 ------------25 26 There's a low-volume mailing list for Requests. To subscribe to the4 unmodified linesmodified:docs/user/advanced.rst+36 added-2 removed
41 unmodified lines42 Certain parameters are best set at the ``request.config`` level43 (e.g.. a global proxy, user agent header).44 45 46+Asynchronous Requests47+----------------------48+49+Requests has first-class support for non-blocking i/o requests, powered50+by gevent. This allows you to send a bunch of HTTP requests at the same51+52+First, let's import the async module. Heads up — if you don't have53+**gevent** installed, this will fail.::54+55+ from requests import async56+57+The ``async`` module has the exact same api as ``requests``, except it58+doesn't send the request immediately. Instead, it returns the ``Request``59+object.60+61+We can build a list of ``Request`` objects easily::62+63+ urls = [64+ 'http://python-requests.org',65+ 'http://httpbin.org',66+ 'http://python-guide.org',67+ 'http://kennethreitz.com'68+ ]69+70+ rs = [async.get(u) for u in urls]71+72+Now we have a list of ``Request`` objects, ready to be sent. We could73+send them one at a time with ``Request.send()``, but that would take a while.74+Instead, we'll send them all at the same time with ``async.map()``::75+76+ >>> async.map(rs)77+ [<Response [200]>, <Response [200]>, <Response [200]>, <Response [200]>]78+79+80 Event Hooks81 -----------82 83 Requests has a hook system that you can use to manipulate portions of15 unmodified lines99 100 101 You can assign a hook function on a per-request basis by passing a102 ``{hook_name: callback_function}`` dictionary to the ``hooks`` request69-paramaeter::103+parameter::104 105 hooks=dict(args=print_url)106 107 That ``callback_function`` will receive a chunk of data as its first59 unmodified lines167 168 >>> 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 line2 3 Installation4 ============5 6-This part of the documentation covers the installation of Requests. The first step to using any software package is getting it properly installed.6+This part of the documentation covers the installation of Requests.7+The first step to using any software package is getting it properly installed.8 9 10 Distribute & Pip11 ----------------12 unmodified lines24 25 Cheeseshop Mirror26 -----------------27 27-If the Cheeseshop is down, you can also install Requests from Kenneth Reitz's personal `Cheeseshop mirror <http://pip.kreitz.co/>`_::28+If the Cheeseshop is down, you can also install Requests from Kenneth Reitz's29+personal `Cheeseshop mirror <http://pip.kreitz.co/>`_::30 31 $ pip install -i http://pip.kreitz.co/simple requests32 33 15 unmodified lines49 50 $ curl -O https://github.com/kennethreitz/requests/zipball/master51 52 51-Once you have a copy of the source, you can embed it in your Python package, or install it into your site-packages easily::53+Once you have a copy of the source, you can embed it in your Python package,54+or install it into your site-packages easily::55 56 $ python setup.py installmodified:docs/user/intro.rst+8 added-21 removed
19 unmodified lines20 21 ISC License22 -----------23 24+A large number of open source projects you find today are `GPL Licensed`_.25+While the GPL has its time and place, it should most certainly not be your26+go-to license for your next open source project.27 25-A 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.28+A project that is released as GPL cannot be used in any commercial product29+without the product itself also being offered as open source.30 27-A 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.31+The MIT, BSD, ISC, and Apache2 licenses are great alternatives to the GPL32+that allow your open-source software to be used freely in proprietary,33+closed-source software.34 35 Requests is released under terms of `The ISC License`_.36 37 .. _`GPL Licensed`: http://www.opensource.org/licenses/gpl-license.php9 unmodified lines47 48 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.49 50 45-.. _interpreters:46-Python Interpreters47--------------------51 49-At this time, the following Python platforms are officially supported:50-51-* 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.562-63-64-Support for Python 3.x is planned.modified:docs/user/quickstart.rst+8 added-4 removed
3 unmodified lines4 ==========5 6 .. module:: requests.models7 8-Eager 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.8+Eager to get started? This page gives a good introduction in how to get started9+with Requests. This assumes you already have Requests installed. If you do not,10+head over to the :ref:`Installation <install>` section.11 12 First, make sure that:13 14 * Requests is :ref:`installed <install>`11 unmodified lines26 Let's get GitHub's public timeline ::27 28 r = requests.get('https://github.com/timeline.json')29 28-Now, we have a :class:`Response` object called ``r``. We can get all the information we need from this.30+Now, we have a :class:`Response` object called ``r``. We can get all the31+information we need from this.32 33 34 Response Content35 ----------------56 unmodified lines92 'etag': '"e1ca502697e5c9317743dc078f67693f"',93 'content-type': 'application/json; charset=utf-8'94 }95 93-The dictionary is special, though: it's made just for HTTP headers. According to `RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>`_, HTTP96+The dictionary is special, though: it's made just for HTTP headers. According to97+`RFC 2616 <http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html>`_, HTTP98 Headers are case-insensitive.99 100 So, we can access the headers using any capitalization we want::101 19 unmodified lines121 122 >>> print r.cookies123 {'requests-is': 'awesome'}124 121-The underlying CookieJar is also available for more advanced handing::125+The underlying CookieJar is also available for more advanced handling::126 127 >>> r.request.cookiejar128 <cookielib.CookieJar>129 9 unmodified linesmodified:docs/api.rst+48 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+Curl52+~~~~53+.. autofunction:: curl_from_request54+55+Encodings56+~~~~~~~~~57+58+.. autofunction:: get_encodings_from_content59+.. autofunction:: get_encoding_from_headers60+.. autofunction:: get_unicode_from_response61+.. autofunction:: decode_gzip62+63+64 Internals65 ---------66 67 These items are an internal component to Requests, and should never be68 seen by the end user (developer). This part of the API documentation69 exists for those who are extending the functionality of Requests.70 71+Exceptions72+~~~~~~~~~~73+74+.. module:: requests75+76+.. autoexception:: HTTPError77+78+.. autoexception:: RequestException79+80+.. autoexception:: AuthenticationError81+.. autoexception:: URLRequired82+.. autoexception:: InvalidMethod83+.. autoexception:: TooManyRedirects84+85+86+87 Classes88 ~~~~~~~89 56-.. autoclass:: requests.models.Request90+.. autoclass:: requests.Request91 :inherited-members:92+93+modified:docs/index.rst+11 added-7 removed
34 unmodified lines35 multipart files, and parameters with simple Python dictionaries, and access the36 response data in the same way. It's powered by :py:class:`urllib2`, but it does37 all the hard work and crazy hacks for you.38 39-Testimonals40------------39+Testimonials40+------------41 42-`Twitter, Inc <http://twitter.com>`_ uses Requests internally.42+`Twitter, Inc <http://twitter.com>`_,43+a U.S. Federal Institution,44+`Readability <http://readability.com>`_, and45+`Work for Pie <http://workforpie.com>`_46+use Requests internally.47 48+**Armin Ronacher**49+ Requests is the perfect example how beautiful an API can be with the50+ right level of abstraction.51+52 **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 lines59 60 **Rich Leland**61 Requests is awesome. That is all.62 55-**Steve Pike**56- I can never remember how to do it the regular way.57- ``import requests; requests.get()`` is just so easy!63 59-64 User Guide65 ----------66 67 This part of the documentation, which is mostly prose, begins with some49 unmodified linesmodified:requests/api.py+6 added-2 removed
15 unmodified lines16 from .status_codes import codes17 from .hooks import dispatch_hook18 from .utils import cookiejar_from_dict19 20-from urlparse import urlparse20 21 __all__ = ('request', 'get', 'head', 'post', 'patch', 'put', 'delete')22 23 def 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):26 27 """Constructs and sends a :class:`Request <models.Request>`.28 Returns :class:`Response <models.Response>` object.29 23 unmodified lines53 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 lines67 68 # Pre-request hook.69 r = dispatch_hook('pre_request', hooks, r)70 71+ # Don't send if asked nicely.72+ if not return_response:73+ return r74+75 # Send the HTTP Request.76 r.send()77 78 # Post-request hook.114 unmodified linesmodified:requests/async.py+68 added-25 removed
1 # -*- coding: utf-8 -*-2 3 """4- requests.async5- ~~~~~~~~~~~~~~4+requests.async5+~~~~~~~~~~~~~~6 7- This module implements the main Requests system, after monkey-patching8- the urllib2 module with eventlet or gevent..9-10- :copyright: (c) 2011 by Kenneth Reitz.11- :license: ISC, see LICENSE for more details.7+This module contains an asynchronous replica of ``requests.api``, powered8+by gevent. All API methods return a ``Request`` instance (as opposed to9+``Response``). A list of requests can be sent with ``map()``.10 """11 12+try:13+ import gevent14+ from gevent import monkey as curious_george15+except ImportError:16+ raise RuntimeError('Gevent is required for requests.async.')17 15-from __future__ import absolute_import18+# Monkey-patch.19+curious_george.patch_all(thread=False)20 17-import urllib18-import urllib221+from . import api22+from .hooks import dispatch_hook23 20-from urllib2 import HTTPError24 25+__all__ = (26+ 'map',27+ 'get', 'head', 'post', 'put', 'patch', 'delete', 'request'28+)29 23-try:24- import eventlet25- eventlet.monkey_patch()26-except ImportError:27- pass30 29-if not 'eventlet' in locals():30- try:31- from gevent import monkey32- monkey.patch_all()33- except ImportError:34- pass31+def _patched(f):32+ """Patches a given API function to not send."""33 34+ def wrapped(*args, **kwargs):35+ return f(*args, return_response=False, **kwargs)36 37-if not 'eventlet' in locals():38- raise ImportError('No Async adaptations of urllib2 found!')37+ return wrapped38 39 41-from .core import *40+def _send(r, pools=None):41+ """Sends a given Request object."""42+43+ if pools:44+ r._pools = pools45+46+ r.send()47+48+ # Post-request hook.49+ r = dispatch_hook('post_request', r.hooks, r)50+51+ # Response manipulation hook.52+ r.response = dispatch_hook('response', r.hooks, r.response)53+54+ return r.response55+56+57+# Patched requests.api functions.58+get = _patched(api.get)59+head = _patched(api.head)60+post = _patched(api.post)61+put = _patched(api.put)62+patch = _patched(api.patch)63+delete = _patched(api.delete)64+request = _patched(api.request)65+66+67+def map(requests, prefetch=True):68+ """Concurrently converts a list of Requests to Responses.69+70+ :param requests: a collection of Request objects.71+ :param prefetch: If False, the content will not be downloaded immediately.72+ """73+74+ jobs = [gevent.spawn(_send, r) for r in requests]75+ gevent.joinall(jobs)76+77+ if prefetch:78+ [r.response.content for r in requests]79+80+ return [r.response for r in requests]81+82+83+84+modified:requests/core.py+2 added-2 removed
10 unmodified lines11 12 """13 14 __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 linesmodified:requests/models.py+5 added-1 removed
35 unmodified lines36 37 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):41 42 #: Float describ the timeout of the request.43 # (Use socket.setdefaulttimeout() as fallback)44 self.timeout = timeout48 unmodified lines93 94 #: True if Request has been sent.95 self.sent = False96 97+ #: Event-handling hooks.98+ self.hooks = hooks99 100 # Header manipulation and defaults.101 102 if settings.accept_gzip:259 unmodified lines362 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)368 369 self._build_response(why, is_error=True)370 371 254 unmodified linesmodified:HISTORY.rst+12 added
1 History2 -------3 4+0.6.3 (2011-10-13)5+++++++++++++++++++6 7+* Beautiful ``requests.async`` module, for making async requests w/ gevent.8+9+10+0.6.2 (2011-10-09)11+++++++++++++++++++12+13+* GET/HEAD obeys allow_redirects=False14+15+16 0.6.1 (2011-08-20)17 ++++++++++++++++++18 19 * Enhanced status codes experience ``\o/``18 unmodified lines38 * HTTPError handling improvements39 * Improved https testing40 * Bugfixes41 42+43 0.5.1 (2011-07-23)44 ++++++++++++++++++45 46 * International Domain Name Support!127 unmodified linesadded:Makefile+14 added
1+init:2+ pip install -r reqs.txt3+4+test:5+ nosetests test_requests.py --processes=306+7+ci: 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.txt10+11+site:12+ cd docs; make dirhtml13+14+docs: sitemodified:test_requests.py+3 added-1 removed
14 unmodified lines15 16 from requests.sessions import Session17 18 19-HTTPBIN_URL = 'http://httpbin.org/'19+HTTPBIN_URL = 'http://httpbin.ep.io/'20 HTTPSBIN_URL = 'https://httpbin.ep.io/'21 22 # HTTPBIN_URL = 'http://staging.httpbin.org/'23 # HTTPSBIN_URL = 'https://httpbin-staging.ep.io/'17 unmodified lines41 42 class RequestsTestSuite(unittest.TestCase):43 """Requests test cases."""44 45+ # It goes to eleven.46+ _multiprocess_can_split_ = True47 48 def setUp(self):49 pass50 445 unmodified lines