From: Kenneth Reitz Date: Fri, 14 Oct 2011 01:54:42 +0000 (-0400) Subject: Merge branch 'feature-content-streaming' of https://github.com/mitsuhiko/requests... X-Git-Tag: v0.6.4^2~5^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=46f0146adfb6faaef4d47e8e1037dd1156b57a3a;p=services%2Fpython-requests.git Merge branch 'feature-content-streaming' of https://github.com/mitsuhiko/requests into feature/content-stream Conflicts: AUTHORS HISTORY.rst docs/api.rst docs/community/faq.rst docs/user/intro.rst requests/api.py requests/models.py --- 46f0146adfb6faaef4d47e8e1037dd1156b57a3a diff --cc AUTHORS index 8dccb46,8497a09..bac9367 --- a/AUTHORS +++ b/AUTHORS @@@ -39,4 -39,7 +39,8 @@@ Patches and Suggestion - Shrikant Sharat Kandula - Mikko Ohtamaa - Den Shabalin +- Daniel Miller + - Alejandro Giacometti + - Rick Mak + - Johan Bergström + - Josselin Jacquard diff --cc HISTORY.rst index 229d8fc,6fcd8f1..c5c711f --- a/HISTORY.rst +++ b/HISTORY.rst @@@ -1,18 -1,12 +1,23 @@@ History ------- + * Automatic decoding of unicode, based on HTTP Headers. + * New ``decode_unicode`` setting + * Removal of ``r.read/close`` methods + * New ``r.fo`` interface for advanced response usage.* + * Automatic expansion of parameterized headers + +0.6.3 (2011-10-13) +++++++++++++++++++ + +* Beautiful ``requests.async`` module, for making async requests w/ gevent. + - +0.6.2 (2011-10-09) +++++++++++++++++++ + +* GET/HEAD obeys allow_redirects=False + + 0.6.1 (2011-08-20) ++++++++++++++++++ diff --cc docs/community/faq.rst index 91ca06b,b6efc78..0cda659 --- a/docs/community/faq.rst +++ b/docs/community/faq.rst @@@ -9,7 -9,7 +9,8 @@@ Encoded Data ------------- Requests automatically decompresses gzip-encoded responses, and does +its best to decodes response content to unicode when possible. + it's best to decodes response content to unicode when possible. You can get direct access to the raw response (and even the socket), if needed as well. diff --cc docs/user/install.rst index 6179abd,dc4aa62..aef598d --- a/docs/user/install.rst +++ b/docs/user/install.rst @@@ -54,25 -54,3 +54,25 @@@ Once you have a copy of the source, yo or install it into your site-packages easily:: $ python setup.py install + +.. _gevent: + +Installing Gevent +----------------- + +If you are using the ``requests.async`` module for making concurrent +requests, you need to install gevent. + +To install gevent, you'll need ``libevent``. + +OSX:: + + $ brew install libevent + +Ubuntu:: + + $ apt-get install libevent-dev + +Once you have ``libevent``, you can install ``gevent`` with ``pip``:: + - $ pip install gevent ++ $ pip install gevent diff --cc docs/user/intro.rst index c2b6bf3,9837fa1..0a168d1 --- a/docs/user/intro.rst +++ b/docs/user/intro.rst @@@ -48,4 -48,23 +48,6 @@@ Requests Licens 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. -.. _interpreters: -Python Interpreters -------------------- - -At this time, the following Python platforms are officially supported: - -* cPython 2.5 -* cPython 2.5.5 -* cPython 2.5.6 -* cPython 2.6 -* cPython 2.6.6 -* cPython 2.6.7 -* cPython 2.7 -* cPython 2.7.1 -* cPython 2.7.2 -* PyPy-c 1.4 -* PyPy-c 1.5 - ++Support for Python 3.x is planned. + Support for Python 3.x is planned. diff --cc requests/api.py index 89eb44c,102bc75..54aeff8 --- a/requests/api.py +++ b/requests/api.py @@@ -15,17 -15,18 +15,17 @@@ import confi from .models import Request, Response, AuthObject from .status_codes import codes from .hooks import dispatch_hook - from .utils import cookiejar_from_dict + from .utils import cookiejar_from_dict, header_expand -from urlparse import urlparse __all__ = ('request', 'get', 'head', 'post', 'patch', 'put', 'delete') def request(method, url, params=None, data=None, headers=None, cookies=None, files=None, auth=None, - timeout=None, allow_redirects=False, proxies=None, hooks=None): + timeout=None, allow_redirects=False, proxies=None, hooks=None, return_response=True): - """Constructs and sends a :class:`Request `. - Returns :class:`Response ` object. + """Constructs and sends a :class:`Request `. + Returns :class:`Response ` object. :param method: method for the new :class:`Request` object. :param url: URL for the new :class:`Request` object. @@@ -89,39 -92,29 +96,61 @@@ def get(url, **kwargs) """Sends a GET request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. + :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`. + :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. + :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. + :param auth: (optional) AuthObject to enable Basic HTTP Auth. + :param timeout: (optional) Float describing the timeout of the request. ++ :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. ++ :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`. ++ :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`. ++ :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. ++ :param auth: (optional) AuthObject to enable Basic HTTP Auth. ++ :param timeout: (optional) Float describing the timeout of the request. + :param allow_redirects: (optional) Boolean. Set to False to disable redirect following. + :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. + :param **kwargs: Optional arguments that ``request`` takes. """ ++ return request('GET', url, **kwargs) + kwargs.setdefault('allow_redirects', True) + return request('GET', url, **kwargs) + if "allow_redirects" not in kwargs: + kwargs["allow_redirects"] = True + return request('get', url, **kwargs) - def head(url, **kwargs): + def head(url, **kwargs): """Sends a HEAD request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. + :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`. + :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`. + :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. + :param auth: (optional) AuthObject to enable Basic HTTP Auth. + :param timeout: (optional) Float describing the timeout of the request. ++ :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. ++ :param params: (optional) Dictionary of parameters, or bytes, to be sent in the query string for the :class:`Request`. ++ :param headers: (optional) Dictionary of HTTP Headers to sent with the :class:`Request`. ++ :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`. ++ :param auth: (optional) AuthObject to enable Basic HTTP Auth. ++ :param timeout: (optional) Float describing the timeout of the request. + :param allow_redirects: (optional) Boolean. Set to False to disable redirect following. + :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy. + :param **kwargs: Optional arguments that ``request`` takes. """ ++ return request('HEAD', url, **kwargs) + kwargs.setdefault('allow_redirects', True) + return request('HEAD', url, **kwargs) + if "allow_redirects" not in kwargs: + kwargs["allow_redirects"] = True + return request('head', url, **kwargs) - def post(url, data='', **kwargs): + def post(url, data='', **kwargs): """Sends a POST request. Returns :class:`Response` object. :param url: URL for the new :class:`Request` object. diff --cc requests/core.py index 655703e,c436664..e44cf83 --- a/requests/core.py +++ b/requests/core.py @@@ -24,4 -24,6 +24,6 @@@ from api import from exceptions import * from sessions import session from status_codes import codes - from config import settings + from config import settings + -import utils ++import utils diff --cc requests/models.py index a63c904,9a7c57d..4a304a5 --- a/requests/models.py +++ b/requests/models.py @@@ -177,11 -187,10 +189,9 @@@ class Request(object) try: response.headers = CaseInsensitiveDict(getattr(resp.info(), 'dict', None)) - response.read = resp.read - response._resp = resp - response._close = resp.close + response.fo = resp if self.cookiejar: - response.cookies = dict_from_cookiejar(self.cookiejar) @@@ -204,10 -213,11 +214,15 @@@ while ( ('location' in r.headers) and ++ ((self.method in ('GET', 'HEAD')) or ++ (r.status_code is codes.see_other) or ++ (self.allow_redirects)) + ((r.status_code is codes.see_other) or (self.allow_redirects)) + ((r.status_code is codes.see_other) or + (self.allow_redirects)) ): - r.close() + r.fo.close() if not len(history) < settings.max_redirects: raise TooManyRedirects()