http://www.mediawiki.org/wiki/Special:Code/pywikipedia/11321
Revision: 11321 Author: xqt Date: 2013-04-01 16:42:32 +0000 (Mon, 01 Apr 2013) Log Message: ----------- use findmarker() for extract_templates_and_params()
Modified Paths: -------------- trunk/pywikipedia/pywikibot/textlib.py
Modified: trunk/pywikipedia/pywikibot/textlib.py =================================================================== --- trunk/pywikipedia/pywikibot/textlib.py 2013-04-01 15:05:38 UTC (rev 11320) +++ trunk/pywikipedia/pywikibot/textlib.py 2013-04-01 16:42:32 UTC (rev 11321) @@ -108,7 +108,7 @@
dontTouchRegexes = [] for exc in exceptions: - if isinstance(exc, str) or isinstance(exc, unicode): + if isinstance(exc, basestring): # assume it's a reference to the exceptionRegexes dictionary # defined above. if exc in exceptionRegexes: @@ -274,13 +274,13 @@
""" # Find a marker that is not already in the text. - marker = findmarker(text, '@@', '@') + marker = findmarker(text) text = text[:index] + marker + text[index:] text = removeDisabledParts(text, tags) return (marker not in text)
-def findmarker(text, startwith=u'@', append=None): +def findmarker(text, startwith=u'@@', append=None): # find a string which is not part of text if not append: append = u'@' @@ -446,7 +446,7 @@
""" # Find a marker that is not already in the text. - marker = findmarker(oldtext, u'@@') + marker = findmarker(oldtext) if site is None: site = pywikibot.getSite() separator = site.family.interwiki_text_separator @@ -706,7 +706,7 @@
""" # Find a marker that is not already in the text. - marker = findmarker(oldtext, u'@@') + marker = findmarker(oldtext) if site is None: site = pywikibot.getSite() if site.sitename() == 'wikipedia:de' and "{{Personendaten" in oldtext: @@ -844,24 +844,16 @@ thistxt = removeDisabledParts(text)
# marker for inside templates or parameters - marker = u'@@' - while marker in thistxt: - marker += u'@' + marker = findmarker(thistxt)
# marker for links - marker2 = u'##' - while marker2 in thistxt: - marker2 += u'#' + marker2 = findmarker(thistxt, u'##', u'#')
# marker for math - marker3 = u'%%' - while marker3 in thistxt: - marker3 += u'%' + marker3 = findmarker(thistxt, u'%%', u'%')
# marker for value parameter - marker4 = u'§§' - while marker4 in thistxt: - marker4 += u'§' + marker4 = findmarker(thistxt, u'§§', u'§')
result = [] Rtemplate = re.compile(
pywikipedia-svn@lists.wikimedia.org