Revision: 4547
Author: rotem
Date: 2007-11-15 10:18:54 +0000 (Thu, 15 Nov 2007)
Log Message:
-----------
Fixing a possible crash in wikipedia.replaceExcept on Windows: Don't use the replace method on a function object (see bug 1821360).
Modified Paths:
--------------
trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py 2007-11-15 05:14:45 UTC (rev 4546)
+++ trunk/pywikipedia/wikipedia.py 2007-11-15 10:18:54 UTC (rev 4547)
@@ -2807,22 +2807,21 @@
index = nextExceptionMatch.end()
else:
# We found a valid match. Replace it.
-
- # This is a hack for Windows users. As they're unable to enter real
- # linebreaks in the command prompt, this line allows them to enter
- # backslash-n instead.
- # This means that it is impossible replace a string with a real
- # backslash-n sequence (it will always become a linebreak), but
- # it is unprobable that someone will want to do that.
- if sys.platform=='win32':
- new = new.replace('\\n', '\n')
-
try:
# the parameter new can be a function which takes the match as a parameter.
replacement = new(match)
except TypeError:
# it is not a function, but a string.
+ # This is a hack for Windows users. As they're unable to enter real
+ # linebreaks in the command prompt, this line allows them to enter
+ # backslash-n instead.
+ # This means that it is impossible replace a string with a real
+ # backslash-n sequence (it will always become a linebreak), but
+ # it is unprobable that someone will want to do that.
+ if sys.platform=='win32':
+ new = new.replace('\\n', '\n')
+
# We cannot just insert the new string, as it may contain regex
# group references such as \2 or \g<name>.
# On the other hand, this approach does not work because it can't