[Cheetahtemplate-discuss] Unicode problem with Cheetah and PyYAML.
Brought to you by:
rtyler,
tavis_rudd
From: Israel S. <duk...@gm...> - 2007-08-07 17:15:04
|
Hello: I just started using Cheetah but I have a problem I couldn't solve. I'm working for the Alqua Proyect (http://alqua.org, spanish) and I'm using some templates to generate LaTeX files. I have four template files, and each one inherits from the previous: Resources.tmpl, ResourcesTEX.tmpl, mainLATEX.tmpl and latex_book_b_es.tmpl. That is, for example, in ResourcesTEX.tmpl I've put a '#extends Resources' directive, and so on. The template files (.tmpl) use ISO-8859-15, so I've put '#encoding iso-8859-15' directive into the files, too. The first thing I do is compile the template files, in order: cheetah compile Resources.tmpl, cheetah compile ResourcesTEX.tmpl, and so on. I use yaml files for store the data, so I launch Python console and type: import latex_book_b_es import yaml stream=file('data.yaml','r') # where data.yaml is utf-8 data = yaml.load(stream) At this point, data becomes a nested dictionary with some values in unicode. If I type 'data', I see several values with u'something' syntax. output = latex_book_b_es.latex_book_b_es(searchList=data) print output Traceback [...] UnicodeDecodeError: 'ascii' codec can't decode byte 0xf3 in position 36: ordinal not in range(128) I have read about this error, and the problem is Python tries to convert the latex_book_b_es template strings to unicode assuming ascii encoding, but these strings contain non-ascii characters (spanish) so it fails. I looked at this mailing list archives and read about problems like this, and tried a lot of options, like putting '#unicode iso-8859-15' in .tmpl files instead of '#encoding ...', but I have had no success. I think a solution could be coding the dictionary from PyYAML into iso-8859-15, but I don't know how to accomplish this easily. Do you have any idea about how to solve this? I'm really stuck. -- Cheers, Israel Saeta Pérez. http://dukebody.blogsome.com |