[albatross-users] Confused over name spaces

Dave Cole djc at object-craft.com.au
Sat Sep 20 13:58:17 EST 2003


> On Sat, 2003-09-13 at 00:18, Sheila King wrote:
> > <al-macro name="mymacro">
> > <al-exec expr="""import time
> > now = time.localtime()
> > """ />
> > 
> > <al-value expr="str(now)" />
> > 
> > </al-macro>
> 
> Assuming it's not a typo, you only need one lot of " around the al-exec
> expr, i.e.
> 
> <al-exec expr="
> import time
> now = time.localtime()
> " />
> 
> I'm not sure what """ would do. I'm kind of surprised that doesn't raise
> an error.

The reason you don't see an exception is due to the parser being based
upon regular expressions.  Anything that does not match the tag
regular expressions is treated as plain text.  You can see how the
parser loads the above template by doing this:

>>> from albatross import Template, SimpleContext
>>> s = '''<al-macro name="mymacro">
... <al-exec expr="""import time
... now = time.localtime()
... """ />
...
... <al-value expr="str(now)" />
...
... </al-macro>
... '''
>>> ctx = SimpleContext('.')
>>> t = Template(ctx, '<inline>', s)
>>> t
Template(Content([<al-macro name="mymacro">Content([Text(<al-exec expr="""import time
now = time.localtime()
""" />
 
), <al-value expr="str(now)">])</al-macro>]))

This shows (very crudely) how the parser handled the template.  What
you can see though is that your <al-exec> tag was handled as text.
This can be confirmed like this:

>>> t.content.items[0].content.items[0].__class__.__name__
'Text'
>>> t.content.items[0].content.items[0].text
'<al-exec expr="""import time\nnow = time.localtime()\n""" />\n\n'

The above makes me think that the __repr__ methods in templates could
be improved to make the above clearer.

- Dave

-- 
http://www.object-craft.com.au




More information about the Albatross-users mailing list