http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10386
Revision: 10386 Author: xqt Date: 2012-06-20 13:58:25 +0000 (Wed, 20 Jun 2012) Log Message: ----------- xmlreader must be imported from pywikibot
Modified Paths: -------------- branches/rewrite/scripts/replace.py branches/rewrite/scripts/template.py
Modified: branches/rewrite/scripts/replace.py =================================================================== --- branches/rewrite/scripts/replace.py 2012-06-20 13:39:39 UTC (rev 10385) +++ branches/rewrite/scripts/replace.py 2012-06-20 13:58:25 UTC (rev 10386) @@ -169,7 +169,7 @@ self.excsInside += self.exceptions['inside-tags'] if "inside" in self.exceptions: self.excsInside += self.exceptions['inside'] - import xmlreader + from pywikibot import xmlreader self.site = pywikibot.getSite() dump = xmlreader.XmlDump(self.xmlFilename) self.parser = dump.parse()
Modified: branches/rewrite/scripts/template.py =================================================================== --- branches/rewrite/scripts/template.py 2012-06-20 13:39:39 UTC (rev 10385) +++ branches/rewrite/scripts/template.py 2012-06-20 13:58:25 UTC (rev 10386) @@ -158,10 +158,8 @@ self.xmlfilename = xmlfilename
def __iter__(self): - """ - Yield page objects until the entire XML dump has been read. - """ - import xmlreader + """Yield page objects until the entire XML dump has been read.""" + from pywikibot import xmlreader mysite = pywikibot.getSite() dump = xmlreader.XmlDump(self.xmlfilename) # regular expression to find the original template. @@ -172,11 +170,14 @@ for template in self.templates: templatePattern = template.titleWithoutNamespace() if not pywikibot.getSite().nocapitalize: - templatePattern = '[' + templatePattern[0].upper() + templatePattern[0].lower() + ']' + templatePattern[1:] + templatePattern = '[%s%s]%s' % (templatePattern[0].upper(), + templatePattern[0].lower(), + templatePattern[1:]) templatePattern = re.sub(' ', '[_ ]', templatePattern) templatePatterns.append(templatePattern) - templateRegex = re.compile(r'{{ *([mM][sS][gG]:)?(?:%s) *(?P<parameters>|[^}]+|) *}}' % '|'.join(templatePatterns)) - + templateRegex = re.compile( + r'{{ *([mM][sS][gG]:)?(?:%s) *(?P<parameters>|[^}]+|) *}}' + % '|'.join(templatePatterns)) for entry in dump.parse(): if templateRegex.search(entry.text): page = pywikibot.Page(mysite, entry.title)