> Something has changed in r.773 with regards to unicode handling...  My forms
> work perfectly as long as I don't have any unicode string in it but they abort
> with an UnicodeEncodeDecode exception otherwise.
>
> They were working with r.765.

The only change that seem to have anything to do with unicode between
the revisions 773 and 765 is
http://trac.turbogears.org/turbogears/changeset/765. But that change
shouldn't matter.

> Traceback (most recent call last):
[compressing traceback]
>   File 
> "/home/godoy/desenvolvimento/python/TurboGears/trunk/thirdparty/kid/kid/pull.py",
>  line 190, in to_unicode
>     return unicode(value, encoding)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 4: 
> ordinal not in range(128)

> The unicode string is "quilômetro" (kilometer).

That is, AFAICT, not a Unicode string. It is a normal Python string
encoded in your choosen encoding. On my computer using utf8 encoding
"quilômetro" looks like this:

    >>> "quilômetro"
    'quil\xc3\xb4metro'

But if I encode it using unicode it looks like this:

    >>> u"quilômetro"
    u'quil\xf4metro'

I think your problem is caused by Kid trying to decode your string
using the ascii codec:

    >>> unicode("quilômetro", "ascii")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in
position 4: ordinal not in range(128)

But you probably want it to use the "utf-8" codec:

    >>> unicode("quilômetro", "utf-8")
    u'quil\xf4metro'

I used to have the exact same problem, but creating a file
sitecustomize.py in /usr/lib/python2.4/site-packages like this solved
all my problems:

    import sys
    sys.setdefaultencoding("utf-8")

--
mvh Björn

Reply via email to