Re: Unicode characters and htmlfill issue
Marius Gedminas <[email protected]> Wed, 25 Mar 2009 15:37:57 +0200
| Newsgroups | gmane.comp.python.formencode |
|---|---|
| Message-ID | <[email protected]> |
Hi again!
On Mon, Mar 23, 2009 at 06:43:00PM +0100, Andrea Riciputi wrote:
> I have a problem with UnicodeString validator and htmlfill.
We discussed this on IRC
(http://pylonshq.com/irclogs/%23pylons/%23pylons.2009-03-24.log.html#t2009-03-24T09:04:00
is the horrible url) and decided that the right solution is to use
String validators of formencode.
The difference between String and UnicodeString is that String passes
through str and unicode objects unchanged, while UnicodeString always
ensures you get unicode from to_python() and always returns str from
from_python().
Pylons already takes care of str <-> unicode conversions for us, both on
the input side and on the output side, so having FormEncode do it again
causes problems.
Here's my recommendations for avoiding Unicode problems:
* make sure you get unicode objects from the database (i.e. use
SQLAlchemy's UnicodeString columns)
* always use unicode objects internally (pure-ASCII str objects don't
hurt, so pure ASCII string constants in the source code are fine --
but when you're taking user input, make sure to convert it to
unicode as soon as possible)
* do not use formencode.validators.UnicodeString
* pass unicode strings to htmlfill.render()
This way SQLAlchemy takes care of conversion at the database side, Pylons
takes care of conversion at the HTML side, and you always deal with
unicode strings.
Now, I've only been using Pylons for two months so I'm not a great
expert. If there are any holes in this logic, please poke at them!
Marius Gedminas
--
The irony is that Bill Gates claims to be making a stable operating
system and Linus Torvalds claims to be trying to take over the
world.
-- seen on the net
------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
FormEncode-discuss mailing list
FormEncode-discuss-5NWGOfrQmneRv+LV9MX5uipxlwaOVQ5f@public.gmane.org
https://lists.sourceforge.net/lists/listinfo/formencode-discuss
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iD8DBQFJyjO1kVdEXeem148RAlCnAKCERYmMvQ53rgxHw9vLf25JY31RYgCfWrkc wlFTlKolrozvQrocneDGQ2E= =xMG/ -----END PGP SIGNATURE-----