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

nicdumz at svn.wikimedia.org nicdumz at svn.wikimedia.org
Sat May 17 14:34:03 UTC 2008


Revision: 5392
Author:   nicdumz
Date:     2008-05-17 14:34:03 +0000 (Sat, 17 May 2008)

Log Message:
-----------
Changed my mind; allowing UnicodeDecodeError to be raised from Page.__init__ is *_BAD_*.
Raising instead wikipedia.Error, and catching it in templatesWithParams

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

Modified: trunk/pywikipedia/wikipedia.py
===================================================================
--- trunk/pywikipedia/wikipedia.py	2008-05-17 14:21:52 UTC (rev 5391)
+++ trunk/pywikipedia/wikipedia.py	2008-05-17 14:34:03 UTC (rev 5392)
@@ -324,7 +324,10 @@
             # Convert URL-encoded characters to unicode
             # Sometimes users copy the link to a site from one to another.
             # Try both the source site and the destination site to decode.
-            t = url2unicode(t, site = insite, site2 = site)
+            try:
+                t = url2unicode(t, site = insite, site2 = site)
+            except UnicodeDecodeError:
+                raise Error(u'Bad page title : %s' % t)
 
             # Normalize unicode string to a NFC (composed) format to allow
             # proper string comparisons. According to
@@ -1736,7 +1739,7 @@
                     continue
                 try:
                     name = Page(self.site(), name).title()
-                except:
+                except Error:
                     if name.strip():
                         output(
                             u"Page %s contains invalid template name {{%s}}."





More information about the Pywikipedia-l mailing list