Initial support for cookies
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by robmadole · committed by robmadole · parent ee43ad2 · Browse files · 2 files·+19 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+19 added−3 removed
- other:+19 added−3 removed
Provenance
- Commit
e4c690e- Tree
936def0- Author
robmadole <robmadole@gmail.com>- Committer
robmadole <robmadole@gmail.com>- Parent
ee43ad2
2 files changed+19 added−3 removed
modified:requests/core.py+9 added-3 removed
109 unmodified lines110 """Creates appropriate opener object for urllib2."""111 112 _handlers = []113 114+ if self.cookiejar != None:115+ _handlers.append(urllib2.HTTPCookieProcessor(self.cookiejar))116+117 if self.auth:118 if not isinstance(self.auth.handler, (urllib2.AbstractBasicAuthHandler, urllib2.AbstractDigestAuthHandler)):119 auth_manager.add_password(self.auth.realm, self.url, self.auth.username, self.auth.password)120 self.auth.handler = self.auth.handler(auth_manager)121 auth_manager.add_auth(self.url, self.auth)122 123 _handlers.append(self.auth.handler)124 125+ if _handlers:126 _handlers.extend(get_handlers())127 opener = urllib2.build_opener(*_handlers)128 return opener.open129 else:56 unmodified lines186 187 if not self.sent or anyway:188 try:189 opener = self._get_opener()186- resp = opener(req)190+ resp = opener(req)191+192+ if self.cookiejar != None:193+ self.cookiejar.extract_cookies(resp, req)194 except urllib2.HTTPError, why:195 self._build_response(why)196 self.response.error = why197 else:3 unmodified lines201 self.response.cached = False202 else:203 self.response.cached = True204 198-205 self.sent = self.response.ok206 207 return self.sent208 202 unmodified lines411 """412 data = kwargs.pop('data', dict()) or kwargs.pop('params', dict())413 414 r = Request(method=method, url=url, data=data, headers=kwargs.pop('headers', {}),409- cookiejar=kwargs.pop('cookies', None), files=kwargs.pop('files', None),415+ cookiejar=kwargs.pop('cookiejar', None), files=kwargs.pop('files', None),416 auth=kwargs.pop('auth', auth_manager.get_auth(url)))417 r.send()418 419 return r.response82 unmodified linesmodified:test_requests.py+10 added
1 #!/usr/bin/env python2 # -*- coding: utf-8 -*-3 4 import unittest5+import cookielib6 7 import requests8 9 93 unmodified lines103 r = requests.get('http://google.com/')104 self.assertFalse(r.error)105 r.raise_for_status()106 107+ def test_cookie_jar(self):108+ """109+ .. todo:: This really doesn't test to make sure the cookie is working110+ """111+ jar = cookielib.CookieJar()112+ self.assertFalse(jar)113 114+ requests.get('http://google.com', cookies=jar)115+ self.assertTrue(jar)116 117 118+119 if __name__ == '__main__':120 unittest.main()