mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Merge branch 'develop' of https://github.com/robmadole/requests into develop
This commit is contained in:
+2
-1
@@ -2,4 +2,5 @@
|
||||
MANIFEST
|
||||
coverage.xml
|
||||
nosetests.xml
|
||||
pylint.txt
|
||||
pylint.txt
|
||||
*.pyc
|
||||
|
||||
+9
-3
@@ -111,6 +111,9 @@ class Request(object):
|
||||
|
||||
_handlers = []
|
||||
|
||||
if self.cookiejar != None:
|
||||
_handlers.append(urllib2.HTTPCookieProcessor(self.cookiejar))
|
||||
|
||||
if self.auth:
|
||||
if not isinstance(self.auth.handler, (urllib2.AbstractBasicAuthHandler, urllib2.AbstractDigestAuthHandler)):
|
||||
auth_manager.add_password(self.auth.realm, self.url, self.auth.username, self.auth.password)
|
||||
@@ -119,6 +122,7 @@ class Request(object):
|
||||
|
||||
_handlers.append(self.auth.handler)
|
||||
|
||||
if _handlers:
|
||||
_handlers.extend(get_handlers())
|
||||
opener = urllib2.build_opener(*_handlers)
|
||||
return opener.open
|
||||
@@ -183,7 +187,10 @@ class Request(object):
|
||||
if not self.sent or anyway:
|
||||
try:
|
||||
opener = self._get_opener()
|
||||
resp = opener(req)
|
||||
resp = opener(req)
|
||||
|
||||
if self.cookiejar != None:
|
||||
self.cookiejar.extract_cookies(resp, req)
|
||||
except urllib2.HTTPError, why:
|
||||
self._build_response(why)
|
||||
self.response.error = why
|
||||
@@ -195,7 +202,6 @@ class Request(object):
|
||||
else:
|
||||
self.response.cached = True
|
||||
|
||||
|
||||
self.sent = self.response.ok
|
||||
|
||||
return self.sent
|
||||
@@ -406,7 +412,7 @@ def request(method, url, **kwargs):
|
||||
data = kwargs.pop('data', dict()) or kwargs.pop('params', dict())
|
||||
|
||||
r = Request(method=method, url=url, data=data, headers=kwargs.pop('headers', {}),
|
||||
cookiejar=kwargs.pop('cookies', None), files=kwargs.pop('files', None),
|
||||
cookiejar=kwargs.pop('cookiejar', None), files=kwargs.pop('files', None),
|
||||
auth=kwargs.pop('auth', auth_manager.get_auth(url)))
|
||||
r.send()
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
import unittest
|
||||
import cookielib
|
||||
|
||||
import requests
|
||||
|
||||
@@ -114,6 +115,15 @@ class RequestsTestSuite(unittest.TestCase):
|
||||
self.assertFalse(r.error)
|
||||
r.raise_for_status()
|
||||
|
||||
def test_cookie_jar(self):
|
||||
"""
|
||||
.. todo:: This really doesn't test to make sure the cookie is working
|
||||
"""
|
||||
jar = cookielib.CookieJar()
|
||||
self.assertFalse(jar)
|
||||
|
||||
requests.get('http://google.com', cookies=jar)
|
||||
self.assertTrue(jar)
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user