Revision: 5802 Author: nicdumz Date: 2008-08-17 07:40:05 +0000 (Sun, 17 Aug 2008)
Log Message: ----------- _putPage was crashing when either the text or the comment argument was a non-ascii string :
p.put('?\195?\182?\195?\164?\195?\182$?\195?\188?\195?\182$?\195?\164?\195?\182?\195?\164?\195?\167%2234qwdadasd', 'Test')
Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/nico/projets/devpywiki/wikipedia.py", line 1284, in put newPage, self.site().getToken(sysop = sysop), sysop = sysop) File "/home/nico/projets/devpywiki/wikipedia.py", line 1300, in _putPage encodedText = text.encode(self.site().encoding()) UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)
Now raising ValueError when the text or comment is not Unicode
Modified Paths: -------------- trunk/pywikipedia/wikipedia.py
Modified: trunk/pywikipedia/wikipedia.py =================================================================== --- trunk/pywikipedia/wikipedia.py 2008-08-16 11:18:09 UTC (rev 5801) +++ trunk/pywikipedia/wikipedia.py 2008-08-17 07:40:05 UTC (rev 5802) @@ -1294,8 +1294,12 @@ host = self.site().hostname() # Get the address of the page on that host. address = self.site().put_address(self.urlname()) + if not isinstance(comment, unicode): + raise ValueError("An unicode edit comment is expected as an argument") # Use the proper encoding for the comment encodedComment = comment.encode(self.site().encoding()) + if not isinstance(text, unicode): + raise ValueError("An unicode wikitext is expected as an argument") # Encode the text into the right encoding for the wiki encodedText = text.encode(self.site().encoding()) predata = {