kartikanand / wikilooper

Wikilooper web version
MIT License
13 stars 1 forks source link

Unicode support (Else error is produced) #3

Closed kartikanand closed 9 years ago

kartikanand commented 9 years ago

With starting string as Pikachu it is not able to handle unicode string (Pokemon) in the next iteration.

Pikachu Pok%C3%A9mon Error 2

mcpower commented 9 years ago

Surprisingly, this works on Python 3, but not 2 (which is what @kartikanand currently uses). Here's a pic of it running on Python 3: image

Doing this on Python 3 (and fixing the display error) is trivial: urllib.parse.unquote will do the job. Python 2 on the other hand is really, really bad at Unicode and I'm still trying to figure out how to make it work.

edit: oops, didn't realise it was the project owner opening the issue! I have a fix, but I can't make a pull request for around 17 hours from now. If you would like to implement it yourself:

use urllib.unquote (Python 2) or urllib.parse.unquote (Python 3) to convert the string into the normal, expected output.
In Python 2, there will be errors in the decoded string (resulting in such things like u"pokémon"). To fix this, a very hacky method needs to be used:

args = "".join(chr(ord(c)) for c in args).decode("utf-8")
kartikanand commented 9 years ago

Hi thanks for the fix! I was thinking of porting the project to Python 3 itself, will fix a lot of issues.

PS: Is there a limit to pull requests?

mcpower commented 9 years ago

There is no limit to pull requests! I've already sent a pull request in with various modifications, including support for Python 3 and caching :)

auscompgeek commented 9 years ago

args = "".join(chr(ord(c)) for c in args).decode("utf-8")

pls. args.encode('latin1').decode() or gtfo

this is Python, not Java