Hello all

I recognized an issue, when executing the following code:

print userlib.User(pywikibot.getSite(), u'º_the_Bench_º')

results in

Traceback (most recent call last):
  File "tests/dtbext_tester.py", line 279, in <module>
    print userlib.User(pywikibot.getSite(), u'º_the_Bench_º')
UnicodeEncodeError: 'ascii' codec can't encode character u'\xba' in position 13: ordinal not in range(128)

The u'\xba' is assigned to u'º' which raises an UnicodeEncodeError.

By using the patch attached, which simply adds an
'.encode(self.site().encoding())' to the string produced the issues
is solved for me. And produces:

wikipedia:de:º_the_Bench_º

May be the 'self.site().encoding()' should or has to be replaced by
another var or const. But the encoding to something like 'utf8' is
essential as statet in [1].

Thanks a lot and greetings
DrTrigon


[1] http://wiki.python.org/moin/UnicodeEncodeError

Index: userlib.py
===================================================================
--- userlib.py  (Revision 8572)
+++ userlib.py  (Arbeitskopie)
@@ -85,7 +85,7 @@
         return ip_regexp.match(self.username) is not None
 
     def __str__(self):
-        return u'%s:%s' % (self.site() , self.name())
+        return (u'%s:%s' % (self.site() , 
self.name())).encode(self.site().encoding())
 
     def __repr__(self):
         return self.__str__()
_______________________________________________
Pywikipedia-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/pywikipedia-l

Reply via email to