Skip to content
Myr

Merge branch 'develop' into key_val_lists

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

Conflicts: requests/models.py

authored by Ian Cordasco · committed by Ian Cordasco · parents 1722f28, a94fcb8 · Browse files · 8 files+74 added−18 removed
This commit

State

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

Trailers

  • Conflicts: requests/models.py

Diff stats

8 files+74 added−18 removed

  • tests:+30 added−4 removed
  • other:+44 added−14 removed

8 files+74 added−18 removed

modified:requests/__init__.py+2 added-2 removed
13 unmodified lines
1415"""1617__title__ = 'requests'18__version__ = '0.13.5'19__build__ = 0x00130518__version__ = '0.13.6'19__build__ = 0x00130620__author__ = 'Kenneth Reitz'21__license__ = 'ISC'22__copyright__ = 'Copyright 2012 Kenneth Reitz'23
10 unmodified lines
modified:requests/api.py+12 added-3 removed
36 unmodified lines
37 :param prefetch: (optional) if ``True``, the response content will be immediately downloaded.38 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.39 """4041 s = kwargs.pop('session') if 'session' in kwargs else sessions.session()42 return s.request(method=method, url=url, **kwargs)41 # if this session was passed in, leave it open (and retain pooled connections);42 # if we're making it just for this call, then close it when we're done.43 adhoc_session = False44 session = kwargs.pop('session', None)45 if session is None:46 session = sessions.session()47 adhoc_session = True4849 try:50 return session.request(method=method, url=url, **kwargs)51 finally:52 if adhoc_session:53 session.close()544555def get(url, **kwargs):56 """Sends a GET request. Returns :class:`Response` object.5758 :param url: URL for the new :class:`Request` object.
70 unmodified lines
modified:requests/compat.py+2 added
93 unmodified lines
94 builtin_str = str95 bytes = str96 str = unicode97 basestring = basestring98 numeric_types = (int, long, float)99100101102elif is_py3:
7 unmodified lines
110 builtin_str = str111 str = str112 bytes = bytes113 basestring = (str,bytes)114 numeric_types = (int, float)115
modified:requests/models.py+5 added-4 removed
30 unmodified lines
31 stream_decode_response_unicode, get_netrc_auth, get_environ_proxies,32 to_key_val_list, DEFAULT_CA_BUNDLE_PATH)33from .compat import (34 cookielib, urlparse, urlunparse, urljoin, urlsplit, urlencode, str, bytes,35 StringIO, is_py2, chardet, json, builtin_str)35 StringIO, is_py2, chardet, json, builtin_str, numeric_types)3637REDIRECT_STATI = (codes.moved, codes.found, codes.other, codes.temporary_moved)38CONTENT_CHUNK_SIZE = 10 * 102439
17 unmodified lines
57 allow_redirects=False,58 proxies=None,59 hooks=None,60 config=None,61 prefetch=False,61 prefetch=True,62 _poolmanager=None,63 verify=None,64 session=None,65 cert=None):
289 unmodified lines
355 new_fields.append((field, newvalue))356 else:357 new_fields.append((field, val))358 fields = new_fields359359 (body, content_type) = encode_multipart_formdata(fields)360361 return (body, content_type)362
88 unmodified lines
451 return True452 except ValueError:453 return False454456 def send(self, anyway=False, prefetch=False):455 def send(self, anyway=False, prefetch=True):456 """Sends the request. Returns True if successful, False if not.457 If there was an HTTPError during transmission,458 self.response.status_code will contain the HTTPError code.459
307 unmodified lines
767 except AttributeError:768 self._content = None769770 self._content_consumed = True771 # don't need to release the connection; that's been handled by urllib3772 # since we exhausted the data.773 return self._content774775 @property776 def text(self):
63 unmodified lines
modified:requests/sessions.py+13 added-5 removed
66 unmodified lines
67 proxies=None,68 hooks=None,69 params=None,70 config=None,71 prefetch=False,71 prefetch=True,72 verify=True,73 cert=None):7475 self.headers = to_key_val_list(headers or [])
30 unmodified lines
106 def __enter__(self):107 return self108109 def __exit__(self, *args):110 pass110 self.close()111112 def close(self):113 """Dispose of any internal state.114115 Currently, this just closes the PoolManager, which closes pooled116 connections.117 """118 self.poolmanager.clear()119120 def request(self, method, url,121 params=None,122 data=None,123 headers=None,
5 unmodified lines
129 proxies=None,130 hooks=None,131 return_response=True,132 config=None,125 prefetch=False,133 prefetch=None,134 verify=None,135 cert=None):136137 """Constructs and sends a :class:`Request <Request>`.
11 unmodified lines
149 :param allow_redirects: (optional) Boolean. Set to True by default.150 :param proxies: (optional) Dictionary mapping protocol to the URL of the proxy.151 :param return_response: (optional) If False, an un-sent Request object will returned.152 :param config: (optional) A configuration dictionary. See ``request.defaults`` for allowed keys and their default values.145 :param prefetch: (optional) if ``True``, the response content will be immediately downloaded.153 :param prefetch: (optional) whether to immediately download the response content. Defaults to ``True``.154 :param verify: (optional) if ``True``, the SSL cert will be verified. A CA_BUNDLE path can also be provided.155 :param cert: (optional) if String, path to ssl client cert file (.pem). If Tuple, ('cert', 'key') pair.156 """157
4 unmodified lines
162 files = [] if files is None else files163 headers = [] if headers is None else headers164 params = [] if params is None else params165 hooks = {} if hooks is None else hooks158 prefetch = self.prefetch or prefetch166 prefetch = prefetch if prefetch is not None else self.prefetch167168 # use session's hooks as defaults169 for key, cb in list(self.hooks.items()):170 hooks.setdefault(key, cb)
166 unmodified lines
added:tests/informal/test_leaked_connections.py+26 added
1"""2This is an informal test originally written by Bluehorn;3it verifies that Requests does not leak connections when4the body of the request is not read.5"""67import gc, os, subprocess, requests, sys89def main():10 gc.disable()1112 for x in range(20):13 requests.head("http://www.google.com/")1415 print("Open sockets after 20 head requests:")16 pid = os.getpid()17 subprocess.call("lsof -p%d -a -iTCP" % (pid,), shell=True)1819 gcresult = gc.collect()20 print("Garbage collection result: %s" % (gcresult,))2122 print("Open sockets after garbage collection:")23 subprocess.call("lsof -p%d -a -iTCP" % (pid,), shell=True)2425if __name__ == '__main__':26 sys.exit(main())
modified:tests/test_requests.py+4 added-4 removed
850 unmodified lines
851 c = json.loads(r.text).get('cookies')852 assert 'k' in c853854 ds1 = pickle.loads(pickle.dumps(requests.session()))855 ds2 = pickle.loads(pickle.dumps(requests.session(prefetch=True)))856 assert not ds1.prefetch857 assert ds2.prefetch855 ds2 = pickle.loads(pickle.dumps(requests.session(prefetch=False)))856 assert ds1.prefetch857 assert not ds2.prefetch858859 # def test_invalid_content(self):860 # # WARNING: if you're using a terrible DNS provider (comcast),861 # # this will fail.
40 unmodified lines
902 '''\tUntent his person and share the air with us?'''903 )904905 # Make a request and monkey-patch its contents906 r = get(httpbin('get'))906 r = get(httpbin('get'), prefetch=False)907 r.raw = StringIO(quote)908909 lines = list(r.iter_lines())910 len_lines = len(lines)
130 unmodified lines
modified:HISTORY.rst+10 added
1 unmodified line
23History4-------560.13.6 (2012-08-06)7+++++++++++++++++++89- Long awaited fix for hanging connections!10110.13.5 (2012-07-27)12+++++++++++++++++++1314- Packaging fix15160.13.4 (2012-07-27)17+++++++++++++++++++1819- GSSAPI/Kerberos authentication!
502 unmodified lines