1) Get the input encoding from locale.getlocale(locale.LC_CTYPE)[1], don't hardcode UTF-8
Come to think of it perhaps that's the same way we should get the input string encoding (not locale.getpreferredencoding(), anyway, it's not something you need to fix in this patch.
2) Run pyflakes and pep8 on this code, it will show you a number of stylistic issues, I can fix that myself but I usually recommend submitters to do it if they can.
Two more comments:
1) Get the input encoding from locale. getlocale( locale. LC_CTYPE) [1], don't hardcode UTF-8
Come to think of it perhaps that's the same way we should get the input string encoding (not locale. getpreferredenc oding() , anyway, it's not something you need to fix in this patch.
2) Run pyflakes and pep8 on this code, it will show you a number of stylistic issues, I can fix that myself but I usually recommend submitters to do it if they can.