From c19a1bde2e9ccab9dc2295d3486efd6b9abd88d2 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 21 Jul 2012 19:37:03 -0400 Subject: [PATCH] Determine which cookies apply to which domains better. --- earwigbot/wiki/site.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/earwigbot/wiki/site.py b/earwigbot/wiki/site.py index b756649..1bc6dcf 100644 --- a/earwigbot/wiki/site.py +++ b/earwigbot/wiki/site.py @@ -25,7 +25,6 @@ from gzip import GzipFile from json import loads from logging import getLogger, NullHandler from os.path import expanduser -from re import escape as re_escape, match as re_match from StringIO import StringIO from threading import Lock from time import sleep, time @@ -394,15 +393,13 @@ class Site(object): if user_name: return unquote_plus(user_name.value) - name = "centralauth_Token" for cookie in self._cookiejar: - if not cookie.domain_initial_dot or cookie.is_expired(): + if cookie.name != "centralauth_Token" or cookie.is_expired(): continue - if cookie.name != name: - continue - # Build a regex that will match domains this cookie affects: - search = ''.join(("(.*?)", re_escape(cookie.domain))) - if re_match(search, self.domain): # Test it against our site + base = cookie.domain + if base.startswith(".") and not cookie.domain_initial_dot: + base = base[1:] + if self.domain.endswith(base): user_name = self._get_cookie("centralauth_User", cookie.domain) if user_name: return unquote_plus(user_name.value)