Revision: 6422
Author: nicdumz
Date: 2009-02-23 08:15:42 +0000 (Mon, 23 Feb 2009)
Log Message:
-----------
In output(), trying to access __unicode__ builtin if object has one ( unicode(obj,
encoding) does not try to, while unicode(obj) does. )
Modified Paths:
--------------
branches/rewrite/pywikibot/bot.py
Modified: branches/rewrite/pywikibot/bot.py
===================================================================
--- branches/rewrite/pywikibot/bot.py 2009-02-23 07:19:48 UTC (rev 6421)
+++ branches/rewrite/pywikibot/bot.py 2009-02-23 08:15:42 UTC (rev 6422)
@@ -144,10 +144,16 @@
## % type(text),
## level=VERBOSE
## )
- try:
- text = unicode(text, 'utf-8')
- except UnicodeDecodeError:
- text = unicode(text, 'iso8859-1')
+ if type(text) is not str:
+ # looks like text is a non-text object.
+ # Maybe it has a __unicode__ builtin ?
+ # (allows to print Page, Site...)
+ text = unicode(text)
+ else:
+ try:
+ text = unicode(text, 'utf-8')
+ except UnicodeDecodeError:
+ text = unicode(text, 'iso8859-1')
if newline:
text += u'\n'
if toStdout:
Show replies by thread