Discussion:
submit special character with genshi
Enrico Heller
2013-10-22 07:47:21 UTC
Permalink
Hello there,

just another question. If i try to submit special character like german
ö-ä-ü genshi dies with this error msg. How i make genshi able to show this?

Genshi UnicodeDecodeError error while rendering template
'/tmp/Trachelloworld-1.1-py2.6.egg-tmp/helloworld/templates/helloworld.html',
line 17, char -1

Thnx for help.
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genshi+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/genshi.
For more options, visit https://groups.google.com/groups/opt_out.
Simon Cross
2013-10-22 07:53:40 UTC
Permalink
Hi Enrico

Could you give a small example that fails for you and your Genshi
version and Python version (2 or 3)? The most likely reason is this if
failing is that you have gotten some minor detail of encodings wrong.

Genshi 0.6.x expects UTF-8 encoded strings by default. Genshi 0.7.x
expects unicode by default.

Schiavo
Simon
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genshi+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/genshi.
For more options, visit https://groups.google.com/groups/opt_out.
Enrico Heller
2013-10-22 12:38:28 UTC
Permalink
Hello Simon,

PlugIn

1 # Helloworld plugin
2
3 import re
4 import MySQLdb
5
6 from genshi.builder import tag
7 from trac.core import *
8 from trac.web import IRequestHandler
9 from trac.web.chrome import INavigationContributor, ITemplateProvider,
add_stylesheet
.
.
.
61 def _page_data(self, req):
62 title = "Test"
63 wert = "Testwert"
64 return {'title': title}
.
.
.
103 data['test'] = 'schön'
104 return 'helloworld.html', data, None



Template

1 <!DOCTYPE html
2 PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4 <html xmlns="http://www.w3.org/1999/xhtml"
5 xmlns:py="http://genshi.edgewall.org/"
6 xmlns:xi="http://www.w3.org/2001/XInclude">
7 <xi:include href="layout.html" />
8 <head>
.
.
.
46 <p>$i{test}</p>
.
.
.


Trac Error

Genshi UnicodeDecodeError error while rendering template
'/tmp/Trachelloworld-1.1-py2.6.egg-tmp/helloworld/templates/helloworld.html',
line 46, char -1

If i change the variable to:

103 data['test'] = 'schoen'
104 return 'helloworld.html', data, None

it works..

My System:
System Information Trac 0.12.3 Genshi 0.6.1 mod_python 3.3.1 pysqlite 2.4.1
Python 2.6.8 (unknown, May 29 2012, 22:30:44) [GCC 4.3.4 [gcc-4_3-branch
revision 152973]] setuptools 0.6c8 SQLite 3.7.6.3 jQuery:1.4.4


Thanks 4 your help
Post by Simon Cross
Hi Enrico
Could you give a small example that fails for you and your Genshi
version and Python version (2 or 3)? The most likely reason is this if
failing is that you have gotten some minor detail of encodings wrong.
Genshi 0.6.x expects UTF-8 encoded strings by default. Genshi 0.7.x
expects unicode by default.
Schiavo
Simon
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genshi+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/genshi.
For more options, visit https://groups.google.com/groups/opt_out.
Simon Cross
2013-10-22 12:40:57 UTC
Permalink
Post by Enrico Heller
103 data['test'] = 'schön'
Try making this u'schön' ?
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genshi+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/genshi.
For more options, visit https://groups.google.com/groups/opt_out.
Felix Schwarz
2013-10-22 13:04:27 UTC
Permalink
Post by Simon Cross
Post by Enrico Heller
103 data['test'] = 'schön'
Try making this u'schön' ?
But then you'll need to declare the encoding also in the Python file in the
first line:
#encoding: utf-8

Alternatively you should be able to write:
data['test'] = u'sch\xf6n'

@Enrico: Looks like you don't fully understand the differences between
unicode, utf-8, encoding in Python 2 - not that I blame you, because it is a
bit tricky especially when other languages uses unicode and utf-8 as synonms.
But basically when you want non-ascii characters in a string as rule of thumb
you should use u'...'.

fs
--
You received this message because you are subscribed to the Google Groups "Genshi" group.
To unsubscribe from this group and stop receiving emails from it, send an email to genshi+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/genshi.
For more options, visit https://groups.google.com/groups/opt_out.
Loading...