From 48413de4187e1393dcfd01542dcbc486a3eb0ae2 Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Wed, 3 Aug 2011 19:27:36 +0200 Subject: [PATCH] Display warning message for each cookie parsing error. --- linkcheck/cache/cookie.py | 13 ++++++++----- linkcheck/checker/httpurl.py | 13 +++++++------ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/linkcheck/cache/cookie.py b/linkcheck/cache/cookie.py index 3133e531..9d6b971a 100644 --- a/linkcheck/cache/cookie.py +++ b/linkcheck/cache/cookie.py @@ -39,6 +39,7 @@ class CookieJar (object): @synchronized(_lock) def add (self, headers, scheme, host, path): """Parse cookie values, add to cache.""" + errors = [] jar = self.cache.setdefault(host, set()) for h in headers.getallmatchingheaders("Set-Cookie"): # RFC 2109 (Netscape) cookie type @@ -49,8 +50,9 @@ class CookieJar (object): if not cookie.is_expired(): jar.add(cookie) except cookies.CookieError, msg: - log.debug(LOG_CACHE, - "Invalid cookie %r for %s:%s%s: %s", h, scheme, host, path, msg) + errmsg = "Invalid cookie %r for %s:%s%s: %s" % ( + h, scheme, host, path, msg) + errors.append(errmsg) for h in headers.getallmatchingheaders("Set-Cookie2"): # RFC 2965 cookie type try: @@ -60,10 +62,11 @@ class CookieJar (object): if not cookie.is_expired(): jar.add(cookie) except cookies.CookieError, msg: - log.debug(LOG_CACHE, - "Invalid cookie2 %r for %s:%s%s: %s", h, scheme, host, path, msg) + errmsg = "Invalid cookie2 %r for %s:%s%s: %s" % ( + h, scheme, host, path, msg) + errors.append(errmsg) self.cache[host] = jar - return jar + return errors @synchronized(_lock) def get (self, scheme, host, port, path): diff --git a/linkcheck/checker/httpurl.py b/linkcheck/checker/httpurl.py index b79685e0..b8c2cdf5 100644 --- a/linkcheck/checker/httpurl.py +++ b/linkcheck/checker/httpurl.py @@ -466,12 +466,13 @@ class HttpUrl (internpaturl.InternPatternUrl, proxysupport.ProxySupport): for c in self.cookies: self.add_info(_("Sent cookie: %(cookie)s.") % {"cookie": c}) - jar = self.aggregate.cookies.add(self.headers, self.urlparts[0], - self.urlparts[1], self.urlparts[2]) - if not jar: - self.add_warning(_("Could not store cookies from headers: %(headers)s.") % - {'headers': str(self.headers)}, - tag=WARN_HTTP_COOKIE_STORE_ERROR) + errors = self.aggregate.cookies.add(self.headers, + self.urlparts[0], self.urlparts[1], self.urlparts[2]) + if errors: + self.add_warning( + _("Could not store cookies from headers: %(error)s.") % + {'error': "\n".join(errors)}, + tag=WARN_HTTP_COOKIE_STORE_ERROR) if response.status >= 200: self.set_result(u"%r %s" % (response.status, response.reason)) else: