Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 2 contributors
Commits on Apr 13, 2012
@reclosedev reclosedev fix #549 Add 'prefetch' to Session.__attrs__ and Requests.__init__ d569a2d
Commits on Apr 14, 2012
@kennethreitz Merge pull request #550 from reclosedev/develop
Fix issue #549. Add 'prefetch' to Session.__attrs__ and Requests.__init__
2f6b5fe
Showing with 23 additions and 2 deletions.
  1. +5 −1 requests/models.py
  2. +2 −1 requests/sessions.py
  3. +16 −0 tests/test_requests.py
View
6 requests/models.py
@@ -61,6 +61,7 @@ def __init__(self,
proxies=None,
hooks=None,
config=None,
+ prefetch=False,
_poolmanager=None,
verify=None,
session=None,
@@ -149,6 +150,9 @@ def __init__(self,
#: SSL Certificate
self.cert = cert
+ #: Prefetch response content
+ self.prefetch = prefetch
+
if headers:
headers = CaseInsensitiveDict(self.headers)
else:
@@ -624,7 +628,7 @@ def send(self, anyway=False, prefetch=False):
self.__dict__.update(r.__dict__)
# If prefetch is True, mark content as consumed.
- if prefetch:
+ if prefetch or self.prefetch:
# Save the response.
self.response.content
View
3 requests/sessions.py
@@ -52,7 +52,7 @@ class Session(object):
__attrs__ = [
'headers', 'cookies', 'auth', 'timeout', 'proxies', 'hooks',
- 'params', 'config', 'verify', 'cert']
+ 'params', 'config', 'verify', 'cert', 'prefetch']
def __init__(self,
@@ -179,6 +179,7 @@ def request(self, method, url,
allow_redirects=allow_redirects,
proxies=proxies,
config=config,
+ prefetch=prefetch,
verify=verify,
cert=cert,
_poolmanager=self.poolmanager
View
16 tests/test_requests.py
@@ -708,6 +708,22 @@ def test_session_pickling(self):
self.assertEqual(s.cookies, ds.cookies)
self.assertEqual(s.auth, ds.auth)
+ def test_unpickled_session_requests(self):
+ s = requests.session()
+ r = get(httpbin('cookies', 'set', 'k', 'v'), allow_redirects=True, session=s)
+ c = json.loads(r.text).get('cookies')
+ assert 'k' in c
+
+ ds = pickle.loads(pickle.dumps(s))
+ r = get(httpbin('cookies'), session=ds)
+ c = json.loads(r.text).get('cookies')
+ assert 'k' in c
+
+ ds1 = pickle.loads(pickle.dumps(requests.session()))
+ ds2 = pickle.loads(pickle.dumps(requests.session(prefetch=True)))
+ assert not ds1.prefetch
+ assert ds2.prefetch
+
def test_invalid_content(self):
# WARNING: if you're using a terrible DNS provider (comcast),
# this will fail.

No commit comments for this range

Something went wrong with that request. Please try again.