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
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