From 8779158b2f4a8ea04616e71c908feaaaf520982c Mon Sep 17 00:00:00 2001 From: Bastian Kleineidam Date: Tue, 2 Aug 2011 21:56:26 +0200 Subject: [PATCH] Sent cookies with more specific paths first. --- linkcheck/cache/cookie.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/linkcheck/cache/cookie.py b/linkcheck/cache/cookie.py index f92217f1..3133e531 100644 --- a/linkcheck/cache/cookie.py +++ b/linkcheck/cache/cookie.py @@ -67,10 +67,14 @@ class CookieJar (object): @synchronized(_lock) def get (self, scheme, host, port, path): - """Cookie cache getter function.""" + """Cookie cache getter function. Return ordered list of cookies + which match the given host, port and path. + Cookies with more specific paths are listed first.""" jar = self.cache.setdefault(host, set()) cookies = [x for x in jar if x.check_expired() and \ x.is_valid_for(scheme, host, port, path)] + # order cookies with more specific (ie. longer) paths first + cookies.sort(key=lambda c: len(c.attributes['path']), reverse=True) log.debug(LOG_CACHE, "Found %d cookies for host %r path %r", len(cookies), host, path) return cookies