Hi Ceri,

This message was discarded (apparently because you're not a member of
the repoze-dev maillist).  I'm forwarding it on your behalf, but you'll
need to sign up at http://lists.repoze.org to reply.

- C

On Sat, 2010-11-06 at 14:10 +0900, Ceri Storey wrote:
> Hi there.
> 
> 
> I think there was a bug introduced between chameleon 1.2.1--1.2.2; in
> that content included from a py:def statement will be followed by a
> "None". Looking into the internals (although please forgive me if this
> is unhelpful), it looks like when the py:def is translated into a
> function definition; it naturally returns None; and somehow; that's
> not being caught by the translation code. It looks like it should be;
> looking at the output from GenshiTemplate.compile() in 1.2.13; but I
> couldn't quite figure out what was going wrong. 
> 
> 
> Please find a test case below. I've bolded the erroneous "None" and
> versions for clarity.
> 
> rhk:chameleon cez$ ipython
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) 
> Type "copyright", "credits" or "license" for more information.
> 
> 
> IPython 0.10 -- An enhanced Interactive Python.
> ?         -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help      -> Python's own help system.
> object?   -> Details about 'object'. ?object also works, ?? prints
> more.
> 
> 
> In [1]: from chameleon.genshi.template import *;
> GenshiTemplate("""<div xmlns="http://www.w3.org/1999/xhtml";
> xmlns:py="http://genshi.edgewall.org/";
> xmlns:xi="http://www.w3.org/2001/XInclude";> <py:def
> function='fish'>Halibut</py:def><span>The fish of the day is
> ${fish()}. </span></div>""").render()
> Out[1]: u'<div xmlns="http://www.w3.org/1999/xhtml";> <span>The fish of
> the day is Halibut. </span></div>'
> 
> 
> In [2]: import chameleon; chameleon.__file__
> Out[2]:
> '/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/Chameleon-1.2.1-py2.5.egg/chameleon/__init__.pyc'
> 
> 
> In [3]: 
> Do you really want to exit ([y]/n)? 
> rhk:chameleon cez$  
> 
> 
> And now our failing case:
> 
> 
> rhk:chameleon cez$ ipython
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53) 
> Type "copyright", "credits" or "license" for more information.
> 
> 
> IPython 0.10 -- An enhanced Interactive Python.
> ?         -> Introduction and overview of IPython's features.
> %quickref -> Quick reference.
> help      -> Python's own help system.
> object?   -> Details about 'object'. ?object also works, ?? prints
> more.
> 
> 
> In [1]: import chameleon; chameleon.__file__
> Out[1]:
> '/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/Chameleon-1.2.2-py2.5.egg/chameleon/__init__.pyc'
> 
> 
> In [2]: from chameleon.genshi.template import *;
> GenshiTemplate("""<div xmlns="http://www.w3.org/1999/xhtml";
> xmlns:py="http://genshi.edgewall.org/";
> xmlns:xi="http://www.w3.org/2001/XInclude";> <py:def
> function='fish'>Halibut</py:def><span>The fish of the day is
> ${fish()}. </span></div>""").render()
> Out[2]: u'<div xmlns="http://www.w3.org/1999/xhtml";> <span>The fish of
> the day is HalibutNone. </span></div>'
> 
> 
> In [3]: 
> Do you really want to exit ([y]/n)? 
> rhk:chameleon cez$ 
> 
> 
> I can hack around this for now by providing an alternative translation
> function; a-la:
> 
> 
> In [4]: from chameleon.genshi.template import *;
> GenshiTemplate("""<div xmlns="http://www.w3.org/1999/xhtml";
> xmlns:py="http://genshi.edgewall.org/";
> xmlns:xi="http://www.w3.org/2001/XInclude";> <py:def
> function='fish'>Halibut</py:def><span>The fish of the day is
> ${fish()}. </span></div>""", translate=lambda x, **kwargs: x is not
> None and x or '').render()
> Out[4]: u'<div xmlns="http://www.w3.org/1999/xhtml";> <span>The fish of
> the day is Halibut. </span></div>'
> 
> 
> In [5]: import chameleon; chameleon.__file__
> Out[5]:
> '/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/Chameleon-1.2.2-py2.5.egg/chameleon/__init__.pyc'
> 
> 
> In [6]: 
> 
> This also works on 1.2.13. Although; in that case; if I pass
> 'translate' to a GenshiTemplateLoader; I can't see that __init__ for
> chameleon.core.loader:TemplateLoader will do anything with it. It
> doesn't appear to pass it to the loaded GenshiTemplate instances
> (read; I still get "None" in my output).
> 
> 
> Thanks in advance,
> 
> 
> ps. I sent this over to the month last month, but I didn't get
> nay response, nor does it show up in the list archives. Perhaps I've
> missed something.
> -- 
> Ceri Storey


_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to