Skip to content
Myr

Merge branch 'develop' of github.com:kennethreitz/requests into develop

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 6e26f57, eab2ab9 · Browse files · 14 files+104 added−63 removed
This commit

State

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

Diff stats

14 files+104 added−63 removed

  • tests:+6 added−0 removed
  • other:+98 added−63 removed

14 files+104 added−63 removed

modified:docs/community/out-there.rst-3 removed
48 unmodified lines
49Requests is available installed as a Debian package! Debian Etch Ubuntu, since Oneiric::5051 $ apt-get install python-requests5253Unfortunately, the most recent version available is v0.5.0. If you're on the54Debian Python Package team, I'd love an update of that :)535654Fedora and RedHat55-----------------5657You can easily install Requests v0.6.1 with yum on rpm-based systems::
6 unmodified lines
modified:docs/user/quickstart.rst+26 added
28 unmodified lines
2930Now, we have a :class:`Response` object called ``r``. We can get all the31information we need from this.3233Typically, you want to send some sort of data in the urls query string.34To do this, simply pass a dictionary to the `params` argument. Your35dictionary of data will automatically be encoded when the request is made::3637 >>> payload = {'key1': 'value1', 'key2': 'value2'}38 >>> r = requests.get("http://httpbin.org/get", params=payload)39 >>> print r.text40 {41 "origin": "179.13.100.4",42 "args": {43 "key2": "value2",44 "key1": "value1"45 },46 "url": "http://httpbin.org/get",47 "headers": {48 "Connections": "keep-alive",49 "Content-Length": "",50 "Accept-Encoding": "identity, deflate, compress, gzip",51 "Accept": "*/*",52 "User-Agent": "python-requests/0.11.0",53 "Host": httpbin.org",54 "Content-Type": ""55 },56 }57585960Response Content61----------------6263We can read the content of the server's response::
369 unmodified lines
modified:requests/packages/oreos/monkeys.py+1 added-1 removed
253 unmodified lines
254# _Translator hash-table for fast quoting255#256_RFC2965Forbidden = "[]:{}="257_LegalChars = ( string.ascii_letters + string.digits + 258 "!#$%&'*+-.^_`|~_" + _RFC2965Forbidden )258 "!#$%&'*+-.^_`|~_@" + _RFC2965Forbidden )259_Translator = {260 '\000' : '\\000', '\001' : '\\001', '\002' : '\\002',261 '\003' : '\\003', '\004' : '\\004', '\005' : '\\005',262 '\006' : '\\006', '\007' : '\\007', '\010' : '\\010',
511 unmodified lines
modified:requests/__init__.py+2 added-2 removed
13 unmodified lines
1415"""1617__title__ = 'requests'18__version__ = '0.10.8'19__build__ = 0x00100818__version__ = '0.11.0'19__build__ = 0x00110020__author__ = 'Kenneth Reitz'21__license__ = 'ISC'22__copyright__ = 'Copyright 2012 Kenneth Reitz'23
10 unmodified lines
modified:requests/api.py+8 added-7 removed
31 unmodified lines
32 :param session: (optional) A :class:`Session` object to be used for the request.33 :param config: (optional) A configuration dictionary.34 :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.35 :param prefetch: (optional) if ``True``, the response content will be immediately downloaded.36 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.37 """3839 s = kwargs.pop('session') if 'session' in kwargs else sessions.session()40 return s.request(method=method, url=url, **kwargs)
3 unmodified lines
44def get(url, **kwargs):45 """Sends a GET request. Returns :class:`Response` object.4647 :param url: URL for the new :class:`Request` object.47 :param **kwargs: Optional arguments that ``request`` takes.48 :param \*\*kwargs: Optional arguments that ``request`` takes.49 """5051 kwargs.setdefault('allow_redirects', True)52 return request('get', url, **kwargs)
2 unmodified lines
55def options(url, **kwargs):56 """Sends a OPTIONS request. Returns :class:`Response` object.5758 :param url: URL for the new :class:`Request` object.58 :param **kwargs: Optional arguments that ``request`` takes.59 :param \*\*kwargs: Optional arguments that ``request`` takes.60 """6162 kwargs.setdefault('allow_redirects', True)63 return request('options', url, **kwargs)
2 unmodified lines
66def head(url, **kwargs):67 """Sends a HEAD request. Returns :class:`Response` object.6869 :param url: URL for the new :class:`Request` object.69 :param **kwargs: Optional arguments that ``request`` takes.70 :param \*\*kwargs: Optional arguments that ``request`` takes.71 """7273 kwargs.setdefault('allow_redirects', False)74 return request('head', url, **kwargs)
3 unmodified lines
78 """Sends a POST request. Returns :class:`Response` object.7980 :param url: URL for the new :class:`Request` object.81 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.81 :param **kwargs: Optional arguments that ``request`` takes.82 :param \*\*kwargs: Optional arguments that ``request`` takes.83 """8485 return request('post', url, data=data, **kwargs)86
2 unmodified lines
89 """Sends a PUT request. Returns :class:`Response` object.9091 :param url: URL for the new :class:`Request` object.92 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.92 :param **kwargs: Optional arguments that ``request`` takes.93 :param \*\*kwargs: Optional arguments that ``request`` takes.94 """9596 return request('put', url, data=data, **kwargs)97
2 unmodified lines
100 """Sends a PATCH request. Returns :class:`Response` object.101102 :param url: URL for the new :class:`Request` object.103 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.103 :param **kwargs: Optional arguments that ``request`` takes.104 :param \*\*kwargs: Optional arguments that ``request`` takes.105 """106107 return request('patch', url, data=data, **kwargs)108
1 unmodified line
110def delete(url, **kwargs):111 """Sends a DELETE request. Returns :class:`Response` object.112113 :param url: URL for the new :class:`Request` object.113 :param **kwargs: Optional arguments that ``request`` takes.114 :param \*\*kwargs: Optional arguments that ``request`` takes.115 """116117 return request('delete', url, **kwargs)
modified:requests/async.py+1 added-1 removed
15 unmodified lines
16except ImportError:17 raise RuntimeError('Gevent is required for requests.async.')1819# Monkey-patch.20curious_george.patch_all(thread=False)20curious_george.patch_all(thread=False, select=False)2122from . import api2324
82 unmodified lines
modified:requests/auth.py+1 added-1 removed
9 unmodified lines
10import time11import hashlib1213from base64 import b64encode14from .compat import urlparse, str, bytes14from .compat import urlparse, str15from .utils import randombytes, parse_dict_header161718
130 unmodified lines
modified:requests/models.py+22 added-36 removed
61 unmodified lines
62 hooks=None,63 config=None,64 _poolmanager=None,65 verify=None,66 session=None):66 session=None,67 cert=None):6869 #: Dictionary of configurations for this request.70 self.config = dict(config or [])71
71 unmodified lines
143144 #: SSL Verification.145 self.verify = verify146147 #: SSL Certificate148 self.cert = cert149150 if headers:151 headers = CaseInsensitiveDict(self.headers)152 else:153 headers = CaseInsensitiveDict()
116 unmodified lines
270 timeout=self.timeout,271 _poolmanager=self._poolmanager,272 proxies=self.proxies,273 verify=self.verify,270 session=self.session274 session=self.session,275 cert=self.cert276 )277278 request.send()279 r = request.response
231 unmodified lines
511 else:512 conn.cert_reqs = 'CERT_NONE'513 conn.ca_certs = None514515 if self.cert and self.verify:516 if len(self.cert) == 2:517 conn.cert_file = self.cert[0]518 conn.key_file = self.cert[1]519 else:520 conn.cert_file = self.cert521522 if not self.sent or anyway:523524 if self.cookies:525
133 unmodified lines
659 @property660 def ok(self):661 try:662 self.raise_for_status()651 except HTTPError:663 except RequestException:664 return False665 return True666667 def iter_content(self, chunk_size=10 * 1024, decode_unicode=False):
14 unmodified lines
682 break683 yield chunk684 self._content_consumed = True685674 def generate_chunked():675 resp = self.raw._original_response676 fp = resp.fp677 if resp.chunk_left is not None:678 pending_bytes = resp.chunk_left679 while pending_bytes:680 chunk = fp.read(min(chunk_size, pending_bytes))681 pending_bytes -= len(chunk)682 yield chunk683 fp.read(2) # throw away crlf684 while 1:685 #XXX correct line size? (httplib has 64kb, seems insane)686 pending_bytes = fp.readline(40).strip()687 if not len(pending_bytes):688 # No content, like a HEAD request. Break out.689 break690 pending_bytes = int(pending_bytes, 16)691 if pending_bytes == 0:692 break693 while pending_bytes:694 chunk = fp.read(min(chunk_size, pending_bytes))695 pending_bytes -= len(chunk)696 yield chunk697 fp.read(2) # throw away crlf698 self._content_consumed = True699 fp.close()686 gen = stream_untransfer(generate(), self)687701 if getattr(getattr(self.raw, '_original_response', None), 'chunked', False):702 gen = generate_chunked()703 else:704 gen = generate()705706 gen = stream_untransfer(gen, self)707688 if decode_unicode:689 gen = stream_decode_response_unicode(gen, self)690691 return gen
75 unmodified lines
767768 # Decode unicode from given encoding.769 try:770 content = str(self.content, encoding, errors='replace')771 except LookupError:772 # A LookupError is raised if the encoding was not found which could773 # indicate a misspelling or similar mistake.774 #775 # So we try blindly encoding.776 content = str(self.content, errors='replace')777 except (UnicodeError, TypeError):778 pass779780 return content
22 unmodified lines
modified:requests/sessions.py+15 added-10 removed
50 unmodified lines
51 """A Requests session."""5253 __attrs__ = [54 'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',55 'params', 'config', 'verify']55 'params', 'config', 'verify', 'cert']565758 def __init__(self,59 headers=None,
4 unmodified lines
64 hooks=None,65 params=None,66 config=None,67 prefetch=False,68 verify=True):68 verify=True,69 cert=None):7071 self.headers = headers or {}72 self.cookies = cookies or {}73 self.auth = auth
3 unmodified lines
77 self.params = params or {}78 self.config = config or {}79 self.prefetch = prefetch80 self.verify = verify81 self.cert = cert8283 for (k, v) in list(defaults.items()):84 self.config.setdefault(k, v)85
34 unmodified lines
120 hooks=None,121 return_response=True,122 config=None,123 prefetch=False,122 verify=None):124 verify=None,125 cert=None):126127 """Constructs and sends a :class:`Request <Request>`.128 Returns :class:`Response <Response>` object.129
11 unmodified lines
141 :param return_response: (optional) If False, an un-sent Request object will returned.142 :param config: (optional) A configuration dictionary.143 :param prefetch: (optional) if ``True``, the response content will be immediately downloaded.144 :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.145 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.146 """147148 method = str(method).upper()149
29 unmodified lines
179 allow_redirects=allow_redirects,180 proxies=proxies,181 config=config,182 verify=verify,183 cert=cert,184 _poolmanager=self.poolmanager185 )186187 # Merge local kwargs with session kwargs.
29 unmodified lines
217 def get(self, url, **kwargs):218 """Sends a GET request. Returns :class:`Response` object.219220 :param url: URL for the new :class:`Request` object.216 :param **kwargs: Optional arguments that ``request`` takes.221 :param \*\*kwargs: Optional arguments that ``request`` takes.222 """223224 kwargs.setdefault('allow_redirects', True)225 return self.request('get', url, **kwargs)
2 unmodified lines
228 def options(self, url, **kwargs):229 """Sends a OPTIONS request. Returns :class:`Response` object.230231 :param url: URL for the new :class:`Request` object.227 :param **kwargs: Optional arguments that ``request`` takes.232 :param \*\*kwargs: Optional arguments that ``request`` takes.233 """234235 kwargs.setdefault('allow_redirects', True)236 return self.request('options', url, **kwargs)
2 unmodified lines
239 def head(self, url, **kwargs):240 """Sends a HEAD request. Returns :class:`Response` object.241242 :param url: URL for the new :class:`Request` object.238 :param **kwargs: Optional arguments that ``request`` takes.243 :param \*\*kwargs: Optional arguments that ``request`` takes.244 """245246 kwargs.setdefault('allow_redirects', False)247 return self.request('head', url, **kwargs)
3 unmodified lines
251 """Sends a POST request. Returns :class:`Response` object.252253 :param url: URL for the new :class:`Request` object.254 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.250 :param **kwargs: Optional arguments that ``request`` takes.255 :param \*\*kwargs: Optional arguments that ``request`` takes.256 """257258 return self.request('post', url, data=data, **kwargs)259
2 unmodified lines
262 """Sends a PUT request. Returns :class:`Response` object.263264 :param url: URL for the new :class:`Request` object.265 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.261 :param **kwargs: Optional arguments that ``request`` takes.266 :param \*\*kwargs: Optional arguments that ``request`` takes.267 """268269 return self.request('put', url, data=data, **kwargs)270
2 unmodified lines
273 """Sends a PATCH request. Returns :class:`Response` object.274275 :param url: URL for the new :class:`Request` object.276 :param data: (optional) Dictionary or bytes to send in the body of the :class:`Request`.272 :param **kwargs: Optional arguments that ``request`` takes.277 :param \*\*kwargs: Optional arguments that ``request`` takes.278 """279280 return self.request('patch', url, data=data, **kwargs)281
1 unmodified line
283 def delete(self, url, **kwargs):284 """Sends a DELETE request. Returns :class:`Response` object.285286 :param url: URL for the new :class:`Request` object.282 :param **kwargs: Optional arguments that ``request`` takes.287 :param \*\*kwargs: Optional arguments that ``request`` takes.288 """289290 return self.request('delete', url, **kwargs)291
14 unmodified lines
modified:requests/utils.py+9 added-1 removed
12 unmodified lines
13import codecs14import os15import random16import re17import traceback17import zlib18from netrc import netrc, NetrcParseError1920from .compat import parse_http_list as _parse_list_header
3 unmodified lines
2425NETRC_FILES = ('.netrc', '_netrc')262728def dict_to_sequence(d):29 """Returns an internal sequence dictionary update."""3031 if hasattr(d, 'items'):32 d = d.items()3334 return d353637def get_netrc_auth(url):38 """Returns the Requests tuple auth for a given url from netrc."""3940 locations = (os.path.expanduser('~/{0}'.format(f)) for f in NETRC_FILES)
431 unmodified lines
modified:tests/test_requests_async.py+6 added
6 unmodified lines
78import sys9import unittest1011import select12has_poll = hasattr(select, "poll")1314from requests import async15import envoy1617sys.path.append('.')
41 unmodified lines
5960 async.map61 async.send6263 def test_select_poll(self):64 """Test to make sure we don't overwrite the poll"""65 self.assertEqual(hasattr(select, "poll"), has_poll)6667if __name__ == '__main__':68 unittest.main()
modified:AUTHORS.rst+4 added
86 unmodified lines
87- Brendan Maguire <maguire.brendan@gmail.com>88- Chris Dary89- Danver Braganza <danverbraganza@gmail.com>90- Max Countryman91- Nick Chadwick92- Jonathan Drosdeck93- Jiri Machalek94- Steve Pulec
modified:HISTORY.rst+8 added
1History2-------340.11.0 (2012-03-14)5+++++++++++++++++++67* Private SSL Certificate support8* Remove select.poll from Gevent monkeypatching9* Remove redundant generator for chunked transfer encoding10* Fix: Response.ok raises Timeout Exception in safe_mode11120.10.8 (2012-03-09)13+++++++++++++++++++1415* Generate chunked ValueError fix
410 unmodified lines
modified:README.rst+1 added-1 removed
71 unmodified lines
72#. Write a test which shows that the bug was fixed or that the feature works as expected.73#. Send a pull request and bug the maintainer until it gets merged and published. :) Make sure to add yourself to AUTHORS_.7475.. _`the repository`: http://github.com/kennethreitz/requests76.. _AUTHORS: http://github.com/kennethreitz/requests/blob/master/AUTHORS76.. _AUTHORS: https://github.com/kennethreitz/requests/blob/develop/AUTHORS.rst