Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #499 (closed defect: fixed)

Opened 13 years ago

Last modified 12 years ago

Widgets versus Unicode

Reported by: Jorge Godoy <jgodoy@…> Owned by: alberto
Priority: normal Milestone: 0.9
Component: TG Widgets Version:
Severity: major Keywords:
Cc:

Description

I am seeing a lot of failures with regards to widgets plus UTF-8 (unicode) encoded strings. My last failure was reported on ticket #498, but is not an isolated case.

From SVN r.611:

godoy@jupiter ~/desenvolvimento/python/TurboGears/trunk % grep -r str\( turbogears/widgets/* | grep -v \.svn | grep -v substr
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span>
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span>
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span>
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span>
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span>
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span>
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span>
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span></div>
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span>
turbogears/widgets/base.py:    <span class="field_error" py:if="widget_error">${str(widget_error)}</span>
turbogears/widgets/tests/test_forms.py:    assert "enter an integer" in str(errors["age"])
godoy@jupiter ~/desenvolvimento/python/TurboGears/trunk % 

And from an interactive session of python:

In [1]: a = u'áéíóúçãõÇÃÕ'

In [2]: str(a)
---------------------------------------------------------------------------
exceptions.UnicodeEncodeError                        Traceback (most recent call last)

/home/godoy/<console> 

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-21: ordinal not in range(128)

In [3]: 

This means that all above conditions in turbogears code would fail if an unicode encoded string was passed to it.

Since Python has two string types ('str' and 'unicode'), I believe turbogears should work with both of then transparently. This means that for the above 'grep'ed code all type conversion should be done on Python code and, IMHO, only Unicode data should reach the templates (making this destination encoding configurable and using the already existing Kid option would be really great and solve problems for people not using Unicode on their template...).

Change History

comment:1 Changed 13 years ago by anonymous

  • Cc jgodoy@… added

comment:2 Changed 13 years ago by alberto

  • Owner changed from anonymous to alberto

I've got something in mind to fix it...

Could you please post a failing unittest so I know when I've really fixed it?

Thanks! alberto

comment:3 Changed 13 years ago by Jorge Godoy <jgodoy@…>

Alberto, do you mind if I send you my forms.py for this project? I don't have a failing test -- and I don't want this file to be the test, even though you can adapt it to be it later... -- right now.

comment:4 Changed 13 years ago by anonymous

  • Cc jgodoy@… removed

comment:5 Changed 13 years ago by alberto

Yeah, no problem... post here or send to alberto@….

Alberto

comment:6 Changed 13 years ago by Jorge Godoy <jgodoy@…>

Sent to your email.

comment:7 Changed 13 years ago by godoy

  • Status changed from new to closed
  • Resolution set to fixed

It's been a while since this was solved but I can't say exactly when. It is working perfectly as of r961.

Sorry for the delay in closing this bug.

Note: See TracTickets for help on using tickets.