473,320 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Encoding problem with web application (Paste+Mako)

msj
Hi

I have a problem with encoding non-ascii characters in a web
application. The application uses Paste and Mako.

The code is here: http://www.webudkast.dk/demo.txt

The main points are:

After getting some user generated input using
paste.request.parse_formvars, how should this be correctly saved to
file?

How should this afterward be read from the file, and fed correctly
into a Mako template?

Thanks.
Martin

Jun 6 '07 #1
2 1772

ms*@infoserv.dk wrote:
Hi

I have a problem with encoding non-ascii characters in a web
application. The application uses Paste and Mako.

The code is here: http://www.webudkast.dk/demo.txt

The main points are:

After getting some user generated input using
paste.request.parse_formvars, how should this be correctly saved to
file?

How should this afterward be read from the file, and fed correctly
into a Mako template?
You have to know the encoding of user input and then you
can use ``input_encoding`` and ``output_encoding`` parameters
of ``Template``. Mako internally handles everything as Python unicode
objects.
For example:

t = Template(filename="templ.mako", input_encoding="iso-8859-2",
output_encoding="iso-8859-2")
content = t.render(**context)

--
HTH,
Rob

Jun 6 '07 #2
Rob Wolfe wrote:
>
You have to know the encoding of user input and then you
can use ``input_encoding`` and ``output_encoding`` parameters
of ``Template``. Mako internally handles everything as Python unicode
objects.
For example:

t = Template(filename="templ.mako", input_encoding="iso-8859-2",
output_encoding="iso-8859-2")
content = t.render(**context)

--
HTH,
Rob
Thanks Rob

Using:

t=Template(content,input_encoding="utf-8", output_encoding="utf-8")

did the trick. Thanks for the help.

/Martin
Jun 6 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

14
by: Sebastian Meyer | last post by:
Hi newsgroup, i am trying to replace german special characters in strings like str = re.sub('ö', 'oe', str) When i work with this, i always get the message UniCode Error: ASCII decoding error...
6
by: Duncan M | last post by:
Hi all, I have seen a similar post to this in the past but no resolution. I will explain fully my problem: I am writing a text editor that will be used in several regions around the world but...
3
by: xmlguy | last post by:
XmlTextReader myXmlReader = new XmlTextReader(args); string en = myXmlReader.Encoding.EncodingName; //Console.WriteLine(x); Error: Unhandled Exception: System.NullReferenceException: Object...
6
by: jmgonet | last post by:
Hello everybody, I'm having troubles loading a Xml string encoded in UTF-8. If I try this code: ------------------------------ XmlDocument doc=new XmlDocument(); String s="<?xml...
8
by: Xarky | last post by:
Hi, I am downloading a GIF file(as a mail attachement) with this file format, Content-Transfer-Encoding: base64; Now I am writing the downloaded data to a file with this technique: ...
4
by: shreshth.luthra | last post by:
Hi All, I am having a GUI which accepts a Unicode string and searches a given set of xml files for that string. Now, i have 2 XML files both of them saved in UTF-8 format, having characters...
8
by: Andy | last post by:
Hello All: I have a windows application that I need to encode a string using Unicode. The example I have been given to use is a Web-Version. Below is the webcode. ...
23
by: Allan Ebdrup | last post by:
I hava an ajax web application where i hvae problems with UTF-8 encoding oc chineese chars. My Ajax webapplication runs in a HTML page that is UTF-8 Encoded. I copy and paste some chineese chars...
2
by: =?Utf-8?B?bW9pdGFs?= | last post by:
I have a client application ( web service ) write in vs2005 consuming an external web service with WSE 2.0 (x509). The response is in hebrew ( windows-1255 ). In the Trace files I see the hebrew...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.