__str__() methods are returning unicode instead of str
I was looking at this issue in django-rosetta, which uses polib: http://code.google.com/p/django-rosetta/issues/detail?id=75
I tracked it down to a bug in polib that caused various str() methods to return unicode instead of str. Calling str() on such an object causes an exception, when str() tries to encode the string using the default ascii code page.
This bug is caused by polib's assumption that codecs.open() returns a generator of str objects. In fact, it generates unicode when you give codecs.open() an encoding parameter (this is the case in Python 2.5). The unicode type then gets propagated in string formatting and joining till it's returned by a str() method.
The quick fix would be to encode the string as it comes out of codecs.open(). Something like this:
(Ignore the line numbers, the version I'm using is the one shipped with django-rosetta.)
--- polib.py.old 2010-06-15 10:31:03.000000000 +0100 +++ polib.py 2010-06-15 12:20:40.000000000 +0100 @@ -1110,6 +1110,7 @@ """ i, lastlen = 1, 0 for line in self.fhandle: + line = line.encode("utf8") line = line.strip() if line == '': i = i+1