[Pywikipedia-svn] SVN: [7312] trunk/pywikipedia/query.py

alexsh at svn.wikimedia.org alexsh at svn.wikimedia.org
Fri Sep 25 12:27:45 UTC 2009


Revision: 7312
Author:   alexsh
Date:     2009-09-25 12:27:45 +0000 (Fri, 25 Sep 2009)

Log Message:
-----------
ToUtf8(): fix non-unicode TypeError

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

Modified: trunk/pywikipedia/query.py
===================================================================
--- trunk/pywikipedia/query.py	2009-09-25 07:46:26 UTC (rev 7311)
+++ trunk/pywikipedia/query.py	2009-09-25 12:27:45 UTC (rev 7312)
@@ -251,14 +251,17 @@
     encList = ''
     # items may not have one symbol - '|'
     for l in list:
-        if '|' in l: raise "item '%s' contains '|' symbol" % l
+        if type(l) == str and '|' in l:
+            raise wikipedia.Error("item '%s' contains '|' symbol" % l )
         encList += ToUtf8(l) + '|'
     return encList[:-1]
 
 def ToUtf8(s):
-    if type(s) != type(u''):
-        wikipedia.output("item %s is not unicode" % unicode(s))
-        raise
+    if type(s) != unicode:
+        try:
+            s = unicode(s)
+        except UnicodeDecodeError:
+            s = s.decode(wikipedia.config.console_encoding)
     return s.encode('utf-8')
 
 def IsString(s):





More information about the Pywikipedia-svn mailing list