Discussion:
input encoding
Helio MC Pereira
2005-09-11 01:04:24 UTC
Permalink
Hi,

I'm confused :-P

I don't need to define input encoding in a Ypage when I'm writing html
but when I call the self.write('<th>Acções</th>') It gives me an
error. Do I need to do anything?

Thanks,
Helio Pereira


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Irmen de Jong
2005-09-11 15:43:11 UTC
Permalink
Post by Helio MC Pereira
Hi,
I'm confused :-P
I don't need to define input encoding in a Ypage when I'm writing html
Uhm, you probably should.
Post by Helio MC Pereira
but when I call the self.write('<th>Acções</th>') It gives me an
error. Do I need to do anything?
You need to define an input encoding to tell Python what encoding
it is that you wrote your page in. It cannot guess this by itself,
and it is required to be able to translate your non-ascii chars
correctly.

The same applies to regular python source code by the way...

--Irmen


-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf
Irmen de Jong
2005-09-15 22:37:37 UTC
Permalink
# -*- coding: iso-8859-1 -*-
but in Ypages i can't do that...
Yes you can.
Post by Helio MC Pereira
but when I call the self.write('<th>Acções</th>') It gives me an
error. Do I need to do anything?
You are not following Python's rules of using non-ascii symbols
in string literals in Python source.
When you want this, you should not use string literals, but
unicode literals.
Try this instead: self.write(u'<th>Acções</th>')
(mind the u)

Also, to be able to actually output the non-ascii symbols you
will have to tell Snakelets what the output encoding of the page
is. When you don't specify a page output encoding, Snakelets
takes Python's default encoding, and usually will raise encoding
errors when you try to output non-ascii symbols. So what you need:
1. page input encoding decl
2. page output encoding decl (or global defaultOutputEncoding)
3. use unicode string literals.


I'm updating the Snakelets docs for 1.42 to be more clear about this.

Hope this helps,

--Irmen


-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP. Click here to play: http://sourceforge.net/geronimo.php
Loading...