Scrapy, a fast high-level web crawling & scraping framework for Python.
cookies: add TODO comments to experimental cookie mw
Daniel Grana512b75942ccf
diff --git a/scrapy/trunk/scrapy/contrib_exp/downloadermiddleware/cookies.py b/scrapy/trunk/scrapy/contrib_exp/downloadermiddleware/cookies.pyindex afacfae94..0cb7b9b3e 100644--- a/scrapy/trunk/scrapy/contrib_exp/downloadermiddleware/cookies.py+++ b/scrapy/trunk/scrapy/contrib_exp/downloadermiddleware/cookies.py@@ -11,37 +11,42 @@ class CookiesMiddleware(object):"""This middleware enables working with sites that need cookies"""def __init__(self):- self.cookies = defaultdict(self.defaultdict_factory)+ self.cookies = defaultdict(CookieJar)dispatcher.connect(self.domain_closed, signals.domain_closed)def process_request(self, request, spider):if request.meta.get('dont_merge_cookies', False):return+jar = self.cookies[spider.domain_name]wreq = _WrappedRequest(request)- for key, value in request.cookies.items():- jar.set_cookie-+ # TODO: Merge cookies in request with jar here+ # for key, value in request.cookies.items():+ # jar.set_cookie(..)+ # set Cookie header with cookies in jarjar.add_cookie_header(wreq)+print request.url.netloc, ' Cookie: ', request.headers.get('Cookie'), request.cookiesdef process_response(self, request, response, spider):print request.url.netloc, 'Set-Cookie:', response.headers.get('Set-Cookie'), request.cookies++ # extract cookies from Set-Cookie and drop invalid/expired cookieswreq = _WrappedRequest(request)wrsp = _WrappedResponse(response)jar = self.cookies[spider.domain_name]+jar.extract_cookies(wrsp, wreq)++ # TODO: set current cookies in jar to response.cookies?return responsedef domain_closed(self, domain):if domain in self.cookies:del self.cookies[domain]- def defaultdict_factory(self):- return CookieJar()-class _WrappedRequest(object):"""Wraps a scrapy Request class with methods defined by urllib2.Request class to interact with CookieJar class