Revision: 5886 Author: nicdumz Date: 2008-09-12 01:56:26 +0000 (Fri, 12 Sep 2008)
Log Message: ----------- When the default (or command-line) family + wiki is not Public, getSite() tries to log in before completely loading the wikipedia module, causing a NameError :
( python login.py ) Traceback (most recent call last): File "\login.py", line 49, in <module> import wikipedia, config File "\wikipedia.py", line 6041, in <module> getSite() File "\wikipedia.py", line 5930, in getSite ret.forceLogin() File "\wikipedia.py", line 4178, in forceLogin if not self.loggedInAs(sysop = sysop): File "\wikipedia.py", line 4170, in loggedInAs self._load(sysop = sysop) File "\wikipedia.py", line 4756, in _load text = self.getUrl(url, sysop = sysop) File "\wikipedia.py", line 4438, in getUrl uo = MyURLopener() NameError: global name 'MyURLopener' is not defined
fixing this introducing a noLogin parameter in getSite
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-09-10 21:27:40 UTC (rev 5885) +++ trunk/pywikipedia/wikipedia.py 2008-09-12 01:56:26 UTC (rev 5886) @@ -5916,7 +5916,7 @@ _sites = {} _namespaceCache = {}
-def getSite(code=None, fam=None, user=None, persistent_http=None): +def getSite(code=None, fam=None, user=None, persistent_http=None, noLogin=False): if code == None: code = default_code if fam == None: @@ -5926,7 +5926,7 @@ _sites[key] = Site(code=code, fam=fam, user=user, persistent_http=persistent_http) ret = _sites[key] - if not ret.family.isPublic(): + if not ret.family.isPublic() and not noLogin: ret.forceLogin() return ret
@@ -6038,7 +6038,10 @@ logfile = None # Check try: - getSite() + # if the default family+wiki is a non-public one, + # getSite will try login in. We don't want that, the module + # is not yet loaded. + getSite(noLogin=True) except KeyError: print( u"""Please create a file user-config.py, and put in there:\n
pywikipedia-l@lists.wikimedia.org