﻿id	summary	reporter	owner	description	type	status	priority	milestone	component	version	resolution	keywords	cc
113	Problems with dict item access/assignment using attribute syntax	darkness-keyword-genshi.e8bcba@…	cmlenz	"There are a few problems in `genshi.template.eval` related to the transformations that allow `d.k` to work like `d[""k""]`.  Here's a short-ish executable example:

{{{
#!python
from genshi.template import MarkupTemplate
def run(content):
	return MarkupTemplate(content).generate().render()


run(""""""
<html><head><title>Tests</title></head><body>

<?python

d = dict(k=1)

# The most serious problem, IMHO, is that this doesn't work
# because a Subscript node with the OP_ASSIGN flag isn't handled.
d[""k""] = 2

?>
<p> ${d.k} is still 1 (should be 2) </p>

<?python

# This assignment will produce an error because the AssAttr AST
# node isn't handled.
d.k = 3

?>
<p> ${d.k} should now be 3 </p>

</body></html>
"""""")
}}}

Executing this with Genshi 0.4 or SVN (as of r569) will cause an exception because of the `d.k = 3`; comment that out and you'll see the wrong values output in the template.  There are other things that fail with the current Genshi too, mostly related to AST nodes that weren't included in `genshi.template.eval`; see the tests included in the patch for more examples.

The attached patch tries to solve these problems by essentially converting `d.k` to `AccessWrapper(d).k` and `d[""k""]` to `AccessWrapper(d)[""k""]`.  `AccessWrapper` then tries both attribute and item access, in an order depending on which was used.

To me this patch looks a little ugly.  (In my defense I think the original use of `_lookup_attr`/`_lookup_item` wasn't very pretty either. :) )  I assumed that converting all those `_lookup_*` calls to an object instantiation followed by another function call for the operator overload would consume more time and memory.  However, in my testing with both Genshi from SVN versus my patched Genshi, I was unable to see a significant difference in either time taken or memory used.  My speculation is that other modules used from `genshi.template.eval` are so much more costly (i.e. the `compiler` package) that any performance degradation due to my patch becomes immaterial."	defect	closed	major	0.4.1	Expression evaluation	devel	fixed	genshi eval attr item dict assignment	
