Revision: 6328 Author: kim Date: 2009-02-05 22:27:26 +0000 (Thu, 05 Feb 2009)
Log Message: ----------- Provide a marginally more useful Exception message. (Message was very misleading. This took me ages to figure out)
Modified Paths: -------------- trunk/pywikipedia/login.py trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/login.py =================================================================== --- trunk/pywikipedia/login.py 2009-02-05 22:22:41 UTC (rev 6327) +++ trunk/pywikipedia/login.py 2009-02-05 22:27:26 UTC (rev 6328) @@ -64,18 +64,25 @@
class LoginManager: - def __init__(self, password = None, sysop = False, site = None): + def __init__(self, password = None, sysop = False, site = None, username=None): self.site = site or wikipedia.getSite() - if sysop: - try: - self.username = config.sysopnames[self.site.family.name][self.site.lang] - except: - raise wikipedia.NoUsername(u'ERROR: Sysop username for %s:%s is undefined.\nIf you have a sysop account for that site, please add such a line to user-config.py:\n\nsysopnames['%s']['%s'] = 'myUsername'' % (self.site.family.name, self.site.lang, self.site.family.name, self.site.lang)) - else: - try: - self.username = config.usernames[self.site.family.name][self.site.lang] - except: - raise wikipedia.NoUsername(u'ERROR: Username for %s:%s is undefined.\nIf you have an account for that site, please add such a line to user-config.py:\n\nusernames['%s']['%s'] = 'myUsername'' % (self.site.family.name, self.site.lang, self.site.family.name, self.site.lang)) + if username: + self.username=username + # perform writeback. + if site.family.name not in config.usernames: + config.usernames[site.family.name]={} + config.usernames[site.family.name][self.site.lang]=username + else: + if sysop: + try: + self.username = config.sysopnames[self.site.family.name][self.site.lang] + except: + raise wikipedia.NoUsername(u'ERROR: Sysop username for %s:%s is undefined.\nIf you have a sysop account for that site, please add such a line to user-config.py:\n\nsysopnames['%s']['%s'] = 'myUsername'' % (self.site.family.name, self.site.lang, self.site.family.name, self.site.lang)) + else: + try: + self.username = config.usernames[self.site.family.name][self.site.lang] + except: + raise wikipedia.NoUsername(u'ERROR: Username for %s:%s is undefined.\nIf you have an account for that site, please add such a line to user-config.py:\n\nusernames['%s']['%s'] = 'myUsername'' % (self.site.family.name, self.site.lang, self.site.family.name, self.site.lang)) self.password = password if getattr(config, 'password_file', ''): self.readPassword()
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2009-02-05 22:22:41 UTC (rev 6327) +++ trunk/pywikipedia/wikipedia.py 2009-02-05 22:27:26 UTC (rev 6328) @@ -809,7 +809,7 @@ RversionTab = re.compile(r'<li id="ca-history"><a href=".*?title=.*?&action=history".*?>.*?</a></li>', re.DOTALL) matchVersionTab = RversionTab.search(text) if not matchVersionTab: - raise NoPage(self.site(), self.aslink(forceInterwiki = True)) + raise NoPage(self.site(), self.aslink(forceInterwiki = True),"Page does not exist. In rare cases, if you are certain the page does exist, look into overriding family.RversionTab" ) # Look if the page is on our watchlist matchWatching = Rwatchlist.search(text) if matchWatching: