Re: encoding problem

Juan Fiol <[email protected]> Wed, 25 Nov 2009 02:02:36 -0800 (PST)
Newsgroups gmane.comp.python.cheetah
Message-ID <[email protected]>
Hi, thanks for the prompt answer. I have almost no experience with Cheetah. I am currently using it through tahchee and only for a small set of webpages. So, I am not sure even if my diagnosis is correct.

The problem appears when I do not have the encoding line in both *compiled* templates that used accented words or words like "Español" and in *uncompiled* templates that included accented words (in spanish).

I've tried including the encoding line in both without success until I changed re.match to re.search
I could send my templates, or simplified versions of them, but they are really for use with tahchee. It probably would be better if I can generate a couple of examples in cheetah templates. However, I don't even know the difference or how to use cheetah directly yet. Also, I am rather busy these days, so it can take me three or four days.

After changed the file Compiler.py and including the encoding line in all relevant files everything worked well.

A python trace (error message) corresponds to cheetah not finding the encoding. It follows an example:
+++++++++++++++++++++++++++++++++++++++++++++++
  File "/usr/lib/python2.6/site-packages/Cheetah/Compiler.py", line 1588, in __init__
    source = unicode(source)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 84: ordinal not in range(128)
make: *** [local] Error 1
+++++++++++++++++++++++++++++++++++++++++++++++

Cheers, Juan
--- On Wed, 11/25/09, [email protected] <[email protected]> wrote:

> From: [email protected] <[email protected]>
> Subject: Re: [Cheetahtemplate-discuss] encoding problem
> To: "Juan Fiol" <[email protected]>
> Cc: [email protected]
> Date: Wednesday, November 25, 2009, 3:03 AM
> 
> On Tue, 24 Nov 2009, Juan Fiol wrote:
> 
> > Hi, using versions 2.2.2 and 2.4.0 in gentoo I found
> that previous working templates (with version 2.0.1) do not
> longer work. The error point out to encoding (ascii not
> being good for some chars). After posting to tahchee mail
> list, I included encoding directives like suggested in the
> manual:
> > 
> > #encoding: UTF-8
> 
> Are you referring to the *compiled* templates or the
> uncompiled templates? If
> it's the former than I might need to bump the latest
> compatible version tuple.
> If it's the latter, are you using encoded strings? If I
> remember correctly
> there should be safe-guards in place to try to perform a
> best effort decoding
> of strings (as per usual, a traceback would be helpful here
> with relevant
> data).
> 
> > but they were not recognized. It finally seems that I
> could identify the problem to the file Compiler.py. The line
> looking for the encoding is using re.match rather than
> re.search
> > I would think that re.match should work but in fact it
> does not. 
> > 
> > I corrected the problem in my system by applying the
> simple patch that is included at the end. Is it correct? Or
> the problem shows from some other issue that I am not
> seeing?
> 
> Looks simple enough, do you have a test case that I can add
> to our
> regression tests?
> 
> > Another question: The behavior of cheetah has changed
> from version 2.0.1 . Previously I did not have any encoding
> defined and it just worked. Now I have to include a line
> with the encoding in each file to make it work. Is there
> another way to do it (like defining a global encoding)?
> > 
> 
> I'll have to get back to you on the global encoding thing,
> the basis of this
> change was to resolve a number of outstanding unicode
> issues with previous
> versions of Cheetah, by making all internal strings to
> Cheetah unicode objects,
> instead of a mix of encoded strings and unicode objects,
> etc.
> 
> Cheers,
> -R. Tyler Ballance
> --------------------------------------
>  Jabber: [email protected]
>  GitHub: http://github.com/rtyler
> Twitter: http://twitter.com/agentdero
>    Blog: http://unethicalblogger.com
> 
> 


      

------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with
Crystal Reports now.  http://p.sf.net/sfu/bobj-july