Revision: 5807 Author: nicdumz Date: 2008-08-18 11:53:24 +0000 (Mon, 18 Aug 2008)
Log Message: ----------- Let's add some comments, and fix that Encode/Decode confusion.
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-08-18 01:54:03 UTC (rev 5806) +++ trunk/pywikipedia/wikipedia.py 2008-08-18 11:53:24 UTC (rev 5807) @@ -1286,13 +1286,13 @@ def _encodeArg(self, arg, msgForError): """Encode an ascii string/Unicode string to the site's encoding""" try: - if isinstance(arg, str): - return arg.decode() # fails with UnicodeDecodeError if non-ascii + return arg.encode(self.site().encoding()) except UnicodeDecodeError: + # 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) - try: - return arg.encode(self.site().encoding()) - except UnicodeDecodeError: + except UnicodeEncodeError: + # happens when arg is unicode raise PageNotSaved("The %s could not be converted to the site's encoding (%s)" % (msgForError, self.site().encoding()))
def _putPage(self, text, comment=None, watchArticle=False, minorEdit=True,
pywikipedia-l@lists.wikimedia.org