Revision: 5164 Author: russblau Date: 2008-03-24 22:01:45 +0000 (Mon, 24 Mar 2008)
Log Message: ----------- Improve caching of _isDisambig; since isDisambig() calls self.templates(), use the latter method to check for disambig templates.
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-03-24 18:32:29 UTC (rev 5163) +++ trunk/pywikipedia/wikipedia.py 2008-03-24 22:01:45 UTC (rev 5164) @@ -965,20 +965,9 @@
""" if not hasattr(self, '_isDisambig'): - locdis = self.site().family.disambig( self._site.lang ) + foo = self.templates() + return self._isDisambig
- for tn in self.templates(): - tn = tn[:1].upper() + tn[1:] - tn = tn.replace(u'_', u' ') - while u" " in tn: - tn = tn.replace(u" ", u" ") - if tn in locdis: - _isDisambig = True - break - else: - _isDisambig = False - return _isDisambig - def getReferences(self, follow_redirects=True, withTemplateInclusion=True, onlyTemplateInclusion=False, redirectsOnly=False): @@ -1581,6 +1570,7 @@
If thistxt is set, it is used instead of current page content. """ + check_disambig = (thistxt is None) if not thistxt: try: thistxt = self.get() @@ -1629,10 +1619,13 @@ try: name = Page(self.site(), name).title() except Error: - output(u"Page %s contains invalid template name {{%s}}." + if name.strip(): + output(u"Page %s contains invalid template name {{%s}}." % (self.title(), name.strip())) continue - + if check_disambig and \ + name in self.site().family.disambig(self.site().lang): + self._isDisambig = True # Parameters paramString = m.group('params') params = [] @@ -1643,20 +1636,25 @@ for m2 in Rlink.finditer(paramString): count2 += 1 text = m2.group() - paramString = paramString.replace(text, '%s%d%s' % (marker2, count2, marker2)) + paramString = paramString.replace(text, + '%s%d%s' % (marker2, count2, marker2)) links[count2] = text # Parse string markedParams = paramString.split('|') # Replace markers for param in markedParams: for m2 in Rmarker.finditer(param): - param = param.replace(m2.group(), inside[int(m2.group(1))]) + param = param.replace(m2.group(), + inside[int(m2.group(1))]) for m2 in Rmarker2.finditer(param): - param = param.replace(m2.group(), links[int(m2.group(1))]) + param = param.replace(m2.group(), + links[int(m2.group(1))]) params.append(param)
# Add it to the result result.append((name, params)) + if check_disambig and not hasattr(self, "_isDisambig"): + self._isDisambig = False return result
def getRedirectTarget(self):
pywikipedia-l@lists.wikimedia.org