[Pywikipedia-l] SVN: [4622] trunk/pywikipedia/wikipedia.py

rotem at svn.wikimedia.org rotem at svn.wikimedia.org
Sat Dec 1 10:03:42 UTC 2007


Revision: 4622
Author:   rotem
Date:     2007-12-01 10:03:41 +0000 (Sat, 01 Dec 2007)

Log Message:
-----------
Fix escaping order, so you do not escape and then put the backslashes in other brackets, in wikipedia.Page.replaceImage. This means namespaces with non-ASCII (?) chars work now.

Modified Paths:
--------------
    trunk/pywikipedia/wikipedia.py

Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py	2007-12-01 04:44:02 UTC (rev 4621)
+++ trunk/pywikipedia/wikipedia.py	2007-12-01 10:03:41 UTC (rev 4622)
@@ -2134,9 +2134,8 @@
             """
             Creates a pattern that matches the string case-insensitively.
             """
-            s = re.escape(s)
             return ur'(?:%s)' % u''.join([u'[%s%s]'
-                                            % (c.upper(), c.lower())
+                                            % (re.escape(c.upper()), re.escape(c.lower()))
                                           for c in s])
 
         def capitalizationPattern(s):
@@ -2145,11 +2144,10 @@
             the first letter case-insensitive if capitalization is switched
             on on the site you're working on.
             """
-            s = re.escape(s)
             if self.site().nocapitalize:
-                return s
+                return re.escape(s)
             else:
-                return ur'(?:[%s%s]%s)' % (s[0].upper(), s[0].lower(), s[1:])
+                return ur'(?:[%s%s]%s)' % (re.escape(s[0].upper()), re.escape(s[0].lower()), re.escape(s[1:]))
 
         namespaces = set(('Image', 'Media') + site.namespace(6, all = True) + site.namespace(-2, all = True))
         # note that the colon is already included here





More information about the Pywikipedia-l mailing list