Revision: 5281 Author: russblau Date: 2008-04-27 20:39:35 +0000 (Sun, 27 Apr 2008)
Log Message: ----------- Banish UnicodeEncodeError
Modified Paths: -------------- branches/rewrite/pywikibot/exceptions.py
Modified: branches/rewrite/pywikibot/exceptions.py =================================================================== --- branches/rewrite/pywikibot/exceptions.py 2008-04-27 16:05:02 UTC (rev 5280) +++ branches/rewrite/pywikibot/exceptions.py 2008-04-27 20:39:35 UTC (rev 5281) @@ -18,7 +18,10 @@ class Error(Exception): """Wikipedia error""" def __init__(self, arg): - self.string = arg.encode(sys.stdout.encoding) + try: + self.string = arg.encode(sys.stderr.encoding, "xmlcharrefreplace") + except (AttributeError, TypeError): + self.string = arg.encode("ascii", "xmlcharrefreplace") def __str__(self): return self.string
pywikipedia-l@lists.wikimedia.org