[Cheetahtemplate-discuss] Unicode problem with Cheetah and PyYAML.
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
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'
output = latex_book_b_es.latex_book_b_es(searchList=data)
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
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.
Israel Saeta Pérez.
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >> http://get.splunk.com/
Cheetahtemplate-discuss mailing list