Revision: 4475
Author: russblau
Date: 2007-10-23 12:34:02 +0000 (Tue, 23 Oct 2007)
Log Message:
-----------
Clean up replaceCategoryInPlace()
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2007-10-21 14:58:06 UTC (rev 4474)
+++ trunk/pywikipedia/wikipedia.py 2007-10-23 12:34:02 UTC (rev 4475)
@@ -3089,11 +3089,10 @@
return text.strip()
def replaceCategoryInPlace(oldtext, oldcat, newcat, site=None):
- """Replace the category oldcat with the category newcat and then return
- the modified Wiki source.
+ """Replace the category oldcat with the category newcat and return
+ the modified text.
+
"""
- #Note that this doesn't work yet and it has some very strange side-effects.
-
if site is None:
site = getSite()
@@ -3111,10 +3110,14 @@
categoryR = re.compile(r'\[\[\s*(%s)\s*:\s*%s\s*((?:\|[^]]+)?\]\])'
% (catNamespace, title))
if newcat is None:
- text = replaceExcept(oldtext, categoryR, '', ['nowiki', 'comment', 'math', 'pre'])
+ text = replaceExcept(oldtext, categoryR, '',
+ ['nowiki', 'comment', 'math', 'pre'])
else:
- text = replaceExcept(oldtext, categoryR, '[[Category:%s\\2' % newcat.titleWithoutNamespace(), ['nowiki', 'comment', 'math', 'pre'])
- return text.strip()
+ text = replaceExcept(oldtext, categoryR,
+ '[[Category:%s\\2'
+ % newcat.titleWithoutNamespace(),
+ ['nowiki', 'comment', 'math', 'pre'])
+ return text
def replaceCategoryLinks(oldtext, new, site=None):
"""Replace the category links given in the wikitext given