Skip to content

Commit

Permalink
Added CookieJar
Browse files Browse the repository at this point in the history
  • Loading branch information
Kenneth Reitz committed Feb 14, 2011
1 parent cde3b88 commit 2203c3b
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions requests/core.py
Expand Up @@ -73,7 +73,9 @@ def __init__(self):
self.params = {}
self.data = {}
self.response = Response()

self.auth = None
self.cookiejar = None
self.sent = False


Expand All @@ -98,20 +100,31 @@ def _checks(self):

def _get_opener(self):
"""Creates appropriate opener object for urllib2."""


_handlers = []

if self.auth:

# create a password manager
authr = urllib2.HTTPPasswordMgrWithDefaultRealm()

authr.add_password(None, self.url, self.auth.username, self.auth.password)
handler = urllib2.HTTPBasicAuthHandler(authr)
opener = urllib2.build_opener(handler)
auth_handler = urllib2.HTTPBasicAuthHandler(authr)

_handlers.append(auth_handler)

# use the opener to fetch a URL
return opener.open
else:
return urllib2.urlopen
# return opener.open
if self.cookiejar:

cookie_handler = urllib2.HTTPCookieProcessor(cookiejar)
_handlers.append(cookie_handler)

opener = urllib2.build_opener(*_handlers)

return opener.open
# else:
# return urllib2.urlopen


def _build_response(self, resp):
Expand Down

0 comments on commit 2203c3b

Please sign in to comment.