http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11738
Revision: 11738 Author: legoktm Date: 2013-07-10 06:36:59 +0000 (Wed, 10 Jul 2013) Log Message: ----------- Ensure we recurse through templates properly
Note that mwpfh returns a different order than regex does.
Modified Paths: -------------- branches/rewrite/pywikibot/textlib.py branches/rewrite/tests/textlib_tests.py
Modified: branches/rewrite/pywikibot/textlib.py =================================================================== --- branches/rewrite/pywikibot/textlib.py 2013-07-10 06:24:43 UTC (rev 11737) +++ branches/rewrite/pywikibot/textlib.py 2013-07-10 06:36:59 UTC (rev 11738) @@ -903,7 +903,7 @@ return extract_templates_and_params_regex(text) code = mwparserfromhell.parse(text) result = [] - for template in code.filter_templates(): + for template in code.filter_templates(recursive=True): params = {} for param in template.params: params[unicode(param.name)] = unicode(param.value)
Modified: branches/rewrite/tests/textlib_tests.py =================================================================== --- branches/rewrite/tests/textlib_tests.py 2013-07-10 06:24:43 UTC (rev 11737) +++ branches/rewrite/tests/textlib_tests.py 2013-07-10 06:36:59 UTC (rev 11738) @@ -44,12 +44,14 @@ self.assertEqual(func('{{a}}'), [('a', {})]) self.assertEqual(func('{{a|b=c}}'), [('a', {'b': 'c'})]) self.assertEqual(func('{{a|b|c=d}}'), [('a', {u'1': 'b', 'c': 'd'})]) + self.assertEqual(func('{{a|b={{c}}}}'), [(u'a', {u'b': u'{{c}}'}), ('c', {})])
def testExtractTemplatesRegex(self): func = textlib.extract_templates_and_params_regex # It's really long. self.assertEqual(func('{{a}}'), [('a', {})]) self.assertEqual(func('{{a|b=c}}'), [('a', {'b': 'c'})]) self.assertEqual(func('{{a|b|c=d}}'), [('a', {u'1': 'b', 'c': 'd'})]) + self.assertEqual(func('{{a|b={{c}}}}'), [('c', {}), (u'a', {u'b': u'{{c}}'})])
@unittest.expectedFailure def testSpacesInSection(self):
pywikipedia-svn@lists.wikimedia.org