On 10/26/05, Kevin Dangoor <[EMAIL PROTECTED]> wrote:

Actually, the code above is not equivalent to what you described with the Kid template. This code is equivalent:

Kevin,

I've recreated this for your convenience.

This is with a shiny new project. I called it 'test', how imaginative.

The default controllers.py has been modifed thusly. I've left the original code in it but commented out.

== snip ==
import turbogears
from turbogears import controllers

class Root(controllers.Root ):
    @turbogears.expose(html="test.templates.welcome")
    def index(self):
        return dict()
#        import time
#        return dict(now=time.ctime())
== snip ==

As you can see, instead of returning a dict that is populated with the 'time' attribute, I am now returning an empty dict.   This causes an exception to be raised.

== snip ==

500 Internal error

Server got itself in trouble

Traceback (most recent call last):
File "e:\python\lib\site-packages\CherryPy-2.1.0_rc2-py2.4.egg\cherrypy\_cphttptools.py", line 271, in run
main()
File "e:\python\lib\site-packages\CherryPy- 2.1.0_rc2-py2.4.egg\cherrypy\_cphttptools.py", line 502, in main
body = page_handler(*args, **cherrypy.request.paramMap)
File "e:\python\lib\site-packages\TurboGears-0.8a4-py2.4.egg\turbogears\controllers.py ", line 122, in newfunc
return controllers._process_output(tg_format, output, html)
File "e:\python\lib\site-packages\TurboGears-0.8a4-py2.4.egg\turbogears\controllers.py", line 38, in _process_output
output = view.render(output, tg_format, template=template)
File "e:\python\lib\site-packages\TurboGears-0.8a4-py2.4.egg\turbogears\view.py", line 99, in render
return t.serialize(encoding="utf-8", output=format, fragment=fragment)
File "e:\python\lib\site-packages\kid-0.7adev_r186-py2.4.egg\kid\__init__.py", line 231, in serialize
return serializer.serialize(self, encoding, fragment)
File "e:\python\lib\site-packages\kid- 0.7adev_r186-py2.4.egg\kid\serialization.py", line 47, in serialize
text = list(self.generate(stream, encoding, fragment))
File "e:\python\lib\site-packages\kid-0.7adev_r186-py2.4.egg\kid\serialization.py ", line 301, in generate
for ev, item in self.apply_filters(stream):
File "e:\python\lib\site-packages\kid-0.7adev_r186-py2.4.egg\kid\serialization.py", line 73, in balancing_filter
for ev, item in stream:
File "e:\python\lib\site-packages\kid-0.7adev_r186-py2.4.egg\kid\pull.py", line 179, in _coalesce
for ev, item in stream:
File "e:\python\lib\site-packages\kid-0.7adev_r186-py2.4.egg\kid\filter.py ", line 21, in transform_filter
for ev, item in apply_matches(stream, template, templates, apply_func):
File "e:\python\lib\site-packages\kid-0.7adev_r186-py2.4.egg\kid\filter.py", line 31, in apply_matches
item = stream.expand()
File "e:\python\lib\site-packages\kid-0.7adev_r186-py2.4.egg\kid\pull.py", line 87, in expand
for ev, item in self._iter:
File "e:\python\lib\site-packages\kid- 0.7adev_r186-py2.4.egg\kid\pull.py", line 152, in _track
for p in stream:
File "e:\python\lib\site-packages\kid-0.7adev_r186-py2.4.egg\kid\pull.py", line 179, in _coalesce
for ev, item in stream:
File "D:\GL\test\test\templates\welcome.py", line 57, in _pull

NameError: name 'now' is not defined
== snip ==

This is of course tracable to this line in the welcome.kid template:

== snip ==

    <p>Your TurboGears server is running as of <span py:replace="now">now</span>.</p>

== snip ==

This is what I was referring to about the 'one too many attributes' scenario, and what I was considering to be non-pythonic from "a certain point of view".

The reverse (missing the variable in the template) also raises an exception, but as I said I think that one is understandable and is completely consistent with Python.

Hopefully that clears any confusion I might have created.

On to other issues.
--
"Things fall apart. The Center cannot hold."
                  - Life as a QA geek, in a nutshell.

Best,

    Jeff


Reply via email to