Revision: 7619 Author: alexsh Date: 2009-11-09 18:35:28 +0000 (Mon, 09 Nov 2009)
Log Message: ----------- wikipedia.py: change Site()._cookies save cookie data to dict login.py: fix badtoken or anonymous edits after login if login data not exist.
Modified Paths: -------------- trunk/pywikipedia/login.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/login.py =================================================================== --- trunk/pywikipedia/login.py 2009-11-09 17:29:03 UTC (rev 7618) +++ trunk/pywikipedia/login.py 2009-11-09 18:35:28 UTC (rev 7619) @@ -79,6 +79,7 @@ class LoginManager: def __init__(self, password = None, sysop = False, site = None, username=None, verbose=False): self.site = site or wikipedia.getSite() + self.sysop = sysop if username: self.username=username # perform writeback. @@ -201,6 +202,12 @@ got_user = True
if got_token and got_user: + index = self.site._userIndex(self.sysop) + self.site._cookies[index] = L + try: + self.site._token[index] = data['login']['lgtoken'] + "+\" + except: + pass return L elif not captcha: solve = self.site.solveCaptcha(data)
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2009-11-09 17:29:03 UTC (rev 7618) +++ trunk/pywikipedia/wikipedia.py 2009-11-09 18:35:28 UTC (rev 7619) @@ -5197,7 +5197,10 @@ """Return a string containing the user's current cookies.""" self._loadCookies(sysop = sysop) index = self._userIndex(sysop) - return self._cookies[index] + if self._cookies[index]: + return "; ".join(["%s=%s" % (v,k) for v,k in self._cookies[index].iteritems()]) + else: + return None
def _loadCookies(self, sysop = False): """Retrieve session cookies for login""" @@ -5227,13 +5230,19 @@ self._isLoggedIn[index] = False else: f = open(fn) - self._cookies[index] = '; '.join([x.strip() for x in f.readlines()]) + tmp = {} + ck = re.compile("(.*?)=(.*?)\n") + for x in ck.findall(f.read()): + tmp[ x[0] ] = x[1] + self._cookies[index] = tmp f.close()
def _readCookies(self, filename): try: f = open( config.datafilepath('login-data', filename) ) - data = '; '.join([p.strip() for p in f.readlines()]) + ck = re.compile("(.*?)=(.*?)\n") + data = dict([(x[0],x[1]) for x in ck.findall(f.read())]) + #data = dict(ck.findall(f.read())) f.close() return data except IOError: