[Pywikipedia-l] SVN: [6423] branches/rewrite/pywikibot/bot.py

nicdumz at svn.wikimedia.org nicdumz at svn.wikimedia.org
Mon Feb 23 08:42:19 UTC 2009


Revision: 6423
Author:   nicdumz
Date:     2009-02-23 08:42:19 +0000 (Mon, 23 Feb 2009)

Log Message:
-----------
Modifying emit() so it can also handle strings, and not only unicode. See attached bug [ 2629586 ] TerminalHandler.emit crashes when message is a string

Modified Paths:
--------------
    branches/rewrite/pywikibot/bot.py

Modified: branches/rewrite/pywikibot/bot.py
===================================================================
--- branches/rewrite/pywikibot/bot.py	2009-02-23 08:15:42 UTC (rev 6422)
+++ branches/rewrite/pywikibot/bot.py	2009-02-23 08:42:19 UTC (rev 6423)
@@ -87,12 +87,15 @@
         try:
             msg = self.format(record)
             fs = "%s"
-            try:
-                self.stream.write(fs % msg.encode(config.console_encoding,
-                                                  "xmlcharrefreplace"))
-            except UnicodeError:
-                self.stream.write(fs % msg.encode("ascii",
-                                                  "xmlcharrefreplace"))
+            if isinstance(msg, str):
+                self.stream.write(fs % msg)
+            else:
+                try:
+                    self.stream.write(fs % msg.encode(config.console_encoding,
+                                                      "xmlcharrefreplace"))
+                except UnicodeError:
+                    self.stream.write(fs % msg.encode("ascii",
+                                                      "xmlcharrefreplace"))
             self.flush()
         except (KeyboardInterrupt, SystemExit):
             raise





More information about the Pywikipedia-l mailing list