Unicode problems with K4.3

5 views
Skip to first unread message

Nicolas Pinault

unread,
Oct 11, 2011, 12:08:50 PM10/11/11
to karr...@googlegroups.com
Hi Pierre,

I am converting one of my web sites from K2.x to K4.3.
Thanks to HTMLTags, all pages written with this class are very quickly
translated.
One problem I am facing is that all unicode characters are wronly
represented in Firefox and IE.

I added the following line to the begining of my scripts :

ENCODING= "utf-8"

Scripts are all saved with UTF-8 encoding.

I wonder what's wrong. Any idea ?

Cordialement,
Nicolas

Nicolas Pinault

unread,
Oct 13, 2011, 5:06:23 PM10/13/11
to karr...@googlegroups.com
Hi,
I finaly got it !

In Karrigell.py, the scripts are executed by these lines :
fileobj = open(self.script_path)
src = '\n'.join([ x.rstrip() for x in fileobj.readlines()])
fileobj.close()
exec(src,self.namespace) # run script in namespace

Script is read, then executed.
What about the script encoding ?
If the executed script is encoded in the default encoding, all is fine.
But what if the script is encoded in another encoding (like UTF-8) ?
In my case, scripts are encoded in UTF-8 but read as if they where
encoded in Windows native encoding.

So, to solve this problem, script has to be read with the correct encoding.
One solution :
- Read the file in binary mode
- Check the presence of encoding tag at the beginning of the file
- Use encoding found or default encoding to decode lines
- Execute script

Salutations,
Nicolas

Pierre Quentel

unread,
Oct 14, 2011, 3:54:22 AM10/14/11
to karrigell
Salut Nicolas,

You found the bug, and how to fix it. I will do it in a few days

Thanks for the report
- Pierre
Reply all
Reply to author
Forward
0 new messages