Namespaced attributes stripped off in TurboGears

0 views
Skip to first unread message

George Sakkis

unread,
Apr 19, 2007, 11:02:28 AM4/19/07
to Genshi
Reposting the following from the Turbogears group; I probably should
have posted it here in the first place. By the way, the problem
persists on Genshi 0.4.

George

=======================================================

I'm running TG with Genshi (0.3.6) and for some reason the attributes
with namespaces are removed. For instance "foo:bar" is stripped off
from the generated html for the following template:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:foo="http://www.foo.net/">

<body foo:bar="frob"/>

</html>

On the other hand, if I load the template, generate the stream and
render it manually it shows up correctly. In other words:

# This works
@tg.expose()
def tmp(self):
from genshi.template import TemplateLoader
loader = TemplateLoader([templates_dir])
tmpl = loader.load('template_path')
return tmpl.generate().render()

# This doesn't
@tg.expose(template='genshi:path.to.template')
def tmp2(self):
return {}

Any ideas ?

George

Shannon -jj Behrens

unread,
Apr 19, 2007, 2:43:51 PM4/19/07
to gen...@googlegroups.com

Christopher Lenz

unread,
Apr 20, 2007, 4:13:56 AM4/20/07
to gen...@googlegroups.com

Are you by any chance using HTML serialization (the default)? It
intentionally strips all namespace information, since HTML doesn't
support namespaces.

You'll need to use XHTML serialization to make namespace info show up
in the generated output. See:

<http://genshi.edgewall.org/wiki/Documentation/plugin.html#usage>
<http://genshi.edgewall.org/wiki/Documentation/plugin.html#genshi-
default-format>

Cheers,
Chris
--
Christopher Lenz
cmlenz at gmx.de
http://www.cmlenz.net/

George Sakkis

unread,
Apr 20, 2007, 11:07:04 AM4/20/07
to Genshi

Ah, that was it! Genshi renders XML by default, tg.expose() does HTML.
Now I have to find out how to change the default rather than setting
format='xhtml' everywhere.

Thanks a lot,
George

Shannon -jj Behrens

unread,
Apr 20, 2007, 2:33:17 PM4/20/07
to gen...@googlegroups.com, Mike Orr

I'll take another stab at trying to be useful ;)

Changing the default format is something that the Buffet plugin is
supposed to take care of. However, the last time I checked, it wasn't
possible. You might want to check to see if this is still the case.
Mike Orr has been working on updating the Buffet spec to handle things
like this.

George Sakkis

unread,
Apr 23, 2007, 1:47:26 PM4/23/07
to Genshi
On Apr 20, 2:33 pm, "Shannon -jj Behrens" <jji...@gmail.com> wrote:

Thanks for trying :)

> Changing the default format is something that the Buffet plugin is
> supposed to take care of. However, the last time I checked, it wasn't
> possible. You might want to check to see if this is still the case.
> Mike Orr has been working on updating the Buffet spec to handle things
> like this.

I didn't check but I found how to do it in Turbogears; just add
genshi.outputformat = "xhtml"
in /your_app/config/app.cfg and that's it.

Best,
George

Reply all
Reply to author
Forward
0 new messages