Revision: 5815 Author: nicdumz Date: 2008-08-19 12:05:23 +0000 (Tue, 19 Aug 2008)
Log Message: ----------- Let's keep Unicode(De|En)codeError - do not raise another Error instead - but append to the Error messages custom reasons for user-friendliness
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-08-19 11:46:52 UTC (rev 5814) +++ trunk/pywikipedia/wikipedia.py 2008-08-19 12:05:23 UTC (rev 5815) @@ -1300,13 +1300,15 @@ """Encode an ascii string/Unicode string to the site's encoding""" try: return arg.encode(self.site().encoding()) - except UnicodeDecodeError: + except UnicodeDecodeError, e: # happens when arg is a non-ascii bytestring : # when reencoding bytestrings, python decodes first to ascii - raise PageNotSaved("An ascii string or unicode %s is expected" % msgForError) - except UnicodeEncodeError: + e.reason += ' (cannot convert input %s string to unicode)' % msgForError + raise e + except UnicodeEncodeError, e: # happens when arg is unicode - raise PageNotSaved("The %s could not be converted to the site's encoding (%s)" % (msgForError, self.site().encoding())) + e.reason += ' (cannot convert %s to wiki encoding %s)' % (msgForError, self.site().encoding()) + raise e
def _putPage(self, text, comment=None, watchArticle=False, minorEdit=True, newPage=False, token=None, newToken=False, sysop=False,
pywikipedia-l@lists.wikimedia.org