Hi,

I am using FormEncode/htmlfill to handle forms.

It seems that if you have a non-ascii error message to be displayed on
a form, such as         Invalid(u'\u041d\u0435\u043e\u0431\u0445\u043e
\u0434\u0438\u043c\u043e',) attempt to render a form results in:

File '/usr/lib/python2.5/site-packages/FormEncode-0.7.1-py2.5.egg/
formencode/htmlfill.py', line 104 in html_quote
  return cgi.escape(str(v), 1)
UnicodeEncodeError: 'ascii' codec can't encode characters in position
0-9: ordinal not in range(128)

The best solution I found so far is to monkeypatch html_quote function
from htmlfill library to be more unicode-friendly:

def monkeypatch_htmlfill_library():
    from formencode import htmlfill
    import cgi
    def my_html_quote(v):
        if v is None:
            return ''
        elif hasattr(v, '__html__'):
            return v.__html__()
        s = unicode(v) # @@ use unicode() instead of str()
        return cgi.escape(s, 1)
    htmlfill.html_quote = my_html_quote

Hopefully someone will find this useful.

Best,
Max.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to