Merge remote-tracking branch 'upstream/develop' into develop
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Jérémy Bethmont · committed by Jérémy Bethmont · parents 571d808, 9471b0a · Browse files · 10 files·+54 added−107 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
10 files+54 added−107 removed
- other:+54 added−107 removed
Provenance
- Commit
a17110b- Tree
909889e- Author
Jérémy Bethmont <jeremy.bethmont@gmail.com>- Committer
Jérémy Bethmont <jeremy.bethmont@gmail.com>- Parent 1
571d808- Parent 2
9471b0a
10 files changed+54 added−107 removed
modified:docs/community/faq.rst+1 added-1 removed
32 unmodified lines33 34 Python 3 Support?35 -----------------36 37-It's on the way.37+It's on the way. Here's a list of `supported interpreters <interpreters>`_.38 39 40 Keep-alive Support?41 -------------------2 unmodified linesmodified:docs/user/advanced.rst+1 added
21 unmodified lines22 s.get('http://httpbin.org/cookies/set/sessioncookie/123456789')23 r = s.get("http://httpbin.org/cookies")24 25 print r.content26+ # '{"cookies": {"sessioncookie": "123456789"}}'27 28 29 Sessions can also be used to provide default data to the request methods::30 107 unmodified linesmodified:docs/user/intro.rst+9 added
1+.. _introduction:2+3 Introduction4 ============5 6 Philosophy34 unmodified lines41 42 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.43 44 45+.. _interpreters:46 Python Interpreters47 -------------------48 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 1 unmodified linemodified:docs/user/quickstart.rst+1 added-1 removed
62 unmodified lines63 File "requests/models.py", line 394, in raise_for_status64 raise self.error65 urllib2.HTTPError: HTTP Error 404: NOT FOUND66 67-But, sice our ``status_code`` was ``200``, when we call it::67+But, since our ``status_code`` was ``200``, when we call it::68 69 >>> r.raise_for_status()70 None71 63 unmodified linesmodified:docs/api.rst+1 added-12 removed
20 unmodified lines21 .. autofunction:: post22 .. autofunction:: put23 .. autofunction:: patch24 .. autofunction:: delete25+.. autofunction:: request26 26-27 -----------28 29 30 .. autoclass:: requests.models.Response18 unmodified lines49 These items are an internal component to Requests, and should never be50 seen by the end user (developer). This part of the API documentation51 exists for those who are extending the functionality of Requests.52 53-Functions54-~~~~~~~~~55-56-.. autofunction:: request57-53 Classes54 ~~~~~~~55 56 .. autoclass:: requests.models.Request57 :inherited-members:63-64-Structures65-~~~~~~~~~~66-67-.. autoclass:: requests.structures.CaseInsensitiveDict68- :inherited-members:modified:requests/api.py+8 added-8 removed
31 unmodified lines32 :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`.34 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.35 :param headers: (optional) Dictionary of HTTP Headers to send with the :class:`Request`.36- :param cookies: (optional) CookieJar object to send with the :class:`Request`.36+ :param cookies: (optional) Dict or CookieJar object to send with the :class:`Request`.37 :param files: (optional) Dictionary of 'filename': file-like-objects for multipart encoding upload.38 :param auth: (optional) AuthObject to enable Basic HTTP Auth.39 :param timeout: (optional) Float describing the timeout of the request.40 :param allow_redirects: (optional) Boolean. Set to True if POST/PUT/DELETE redirect following is allowed.21 unmodified lines62 63 # Arguments manipulation hook.64 args = dispatch_hook('args', hooks, args)65 66- r = Request(hooks=hooks, **args)66+ r = Request(**args)67 68 # Pre-request hook.69 r = dispatch_hook('pre_request', hooks, r)70 15 unmodified lines86 87 :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) CookieJar object 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.94 """7 unmodified lines102 103 :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) CookieJar object to send 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.110 """8 unmodified lines119 :param url: URL for the new :class:`Request` object.120 :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) CookieJar object to send with the :class:`Request`.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`.9 unmodified lines137 :param url: URL for the new :class:`Request` object.138 :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) CookieJar object to send with the :class:`Request`.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`.9 unmodified lines155 :param url: URL for the new :class:`Request` object.156 :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) CookieJar object to send with the :class:`Request`.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`.9 unmodified lines173 174 :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) CookieJar object to send 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.3 unmodified linesmodified:requests/models.py+2 added-4 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, hooks=None):40+ allow_redirects=False, proxies=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- #: Dictionary of event hook callbacks.98- self.hooks = hooks97 100-98 # Header manipulation and defaults.99 100 if settings.accept_gzip:101 settings.base_headers.update({'Accept-Encoding': 'gzip'})308 unmodified lines410 #: up here.411 self.history = []412 #: The Request that created the Response.413 self.request = None414+ #: A dictionary of Cookies the server sent back.415 self.cookies = None416 417 418 def __repr__(self):207 unmodified linesmodified:AUTHORS+1 added-1 removed
29 unmodified lines30 - 潘旭 (Xu Pan)31 - Tamás Gulácsi32 - Rubén Abad33 - Peter Manser34-- Jeremy Selie34+- Jeremy Selier35 - Jens Diemer36 - Alex <@alopatin>37 - Tom Hogans <tomhsx@gmail.com>modified:HISTORY.rst+3 added-3 removed
1 History2 -------3 4 5-0.6.0 (2011-09-??)5+0.6.0 (2011-08-17)6 ++++++++++++++++++7 8 * New callback hook system9 * New persistient sessions object and context manager10 * Transparent Dict-cookie handling11-* status code reference object11+* Status code reference object12 * Removed Response.cached13 * Added Response.request14-* all args are kwargs14+* All args are kwargs15 * Relative redirect support16 * HTTPError handling improvements17 * Improved https testing18 * Bugfixes132 unmodified linesmodified:README.rst+27 added-77 removed
1 Requests: HTTP for Humans2 =========================3 4-Most existing Python modules for dealing HTTP requests are insane. I have to look up *everything* that I want to do. Most of my worst Python experiences are a result of the various built-in HTTP libraries (yes, even worse than Logging).4+Requests is an ISC Licensed HTTP library, written in Python, for human5+beings.6 6-But this one's different. This one's going to be awesome. And simple.7+Most existing Python modules for sending HTTP requests are extremely8+verbose and cumbersome. Python's builtin urllib2 module provides most of9+the HTTP capabilities you should need, but the api is thoroughly broken.10+It requires an enormous amount of work (even method overrides) to11+perform the simplest of tasks.12 8-Really simple.13+Things shouldn't be this way. Not in Python.14 15+::16+17+ >>> r = requests.get('https://api.github.com', auth=('user', 'pass'))18+ >>> r.status_code19+ 20420+ >>> r.headers['content-type']21+ 'application/json'22+ >>> r.content23+ ...24+25+See `the same code, without Requests <https://gist.github.com/973705>`_.26+27+Requests allow you to send **HEAD**, **GET**, **POST**, **PUT**,28+**PATCH**, and **DELETE** HTTP requests. You can add headers, form data,29+multipart files, and parameters with simple Python dictionaries, and access the30+response data in the same way. It's powered by urllib2, but it does31+all the hard work and crazy hacks for you.32+33+34 Features35 --------36 37 - Extremely simple HEAD, GET, POST, PUT, PATCH, DELETE Requests40 unmodified lines78 >>> r.content79 '{"authenticated": true, "user": "user"}'80 81 58-59-API60----61-62-**Requests:**63-64-All request functions return a Response object (see below).65-66-If a {filename: fileobject} dictionary is passed in (files=...), a multipart_encode upload will be performed.67-If CookieJar object is is passed in (cookies=...), the cookies will be sent with the request.68-69- HEAD Requests70- >>> requests.head(url, params={}, headers={}, cookies=None, auth=None, timeout=None, proxies={})71- <Response [200]>72-73- GET Requests74- >>> requests.get(url, params={}, headers={}, cookies=None, auth=None, timeout=None, proxies={})75- <Response [200]>76-77- POST Requests78- >>> requests.post(url, data={}, headers={}, files={}, cookies=None, auth=None, timeout=None, allow_redirects=False, params{}, proxies={})79- <Response [200]>80-81- PUT Requests82- >>> requests.put(url, data={}, headers={}, files={}, cookies=None, auth=None, timeout=None, allow_redirects=False, params{}, proxies={})83- <Response [200]>84-85- PATCH Requests86- >>> requests.patch(url, data={}, headers={}, files={}, cookies=None, auth=None, timeout=None, allow_redirects=False, params{}, proxies={})87- <Response [200]>88-89- DELETE Requests90- >>> requests.delete(url, params={}, headers={}, cookies=None, auth=None, timeout=None, allow_redirects=False, params{}, proxies={})91- <Response [200]>92-93-94-**Responses:**95-96- Response.status_code97- (Integer) Received HTTP Status Code Response98-99- Response.headers100- ((CaseInsensitive) Dictionary) Received HTTP Response Headers.101-102- Response.content103- (Bytes) Received Content.104-105- Response.history106- (List of Responses) Redirection History.107-108- Response.url109- (String) URL of response. Useful for detecting redirects.110-111- Response.ok112- (Bool) True if no errors occurred during the request, and the status_code is kosher.113-114- Response.cached115- (Bool) True if Response.content is stored within the object.116-117- Response.error118- (HTTPError) If an HTTPError occurred (e.g. status of 404), Otherwise this is None.119-120- Response.raise_for_status()121- Raises HTTPError if a request is not kosher.122-123-124-**HTTP Authentication Registry:**125-126- You can register AuthObjects to automatically enable HTTP Authentication on requests that contain a registered base URL string.127-128- >>> requests.auth_manager.add_auth(url, authobject)129-130-131-82 Installation83 ------------84 85 To install requests, simply: ::25 unmodified lines