Interesting. The first version I posted actually used __getitem__ for child nodes, and
__getattr__ for attributes, leading to examples like::
>>> m = Meld2('<a meld:id="foo" href="blah">A link goes <b meld:id="name">here</b></a>')
>>> m.href = 'http://plope.com'
>>> m['name'] = 'somewhere'
The reason I did that was to avoid linguistic confusion: I wanted to represent XML attributes
as Python attributes. But this creates a need to handle the 'class' attribute specially since
it's a Python keyword. And as Richie Hindle pointed out to me, there's a strong appeal to
using the simpler syntax for the common case::
But I feel your pain, Casey. I plan to whip up a Meld2 Zope product and try using meld templates
with Zope to see how that goes, and I'm nervous about the __getattr__ because it's so often
painful to override that in Zope. And it's already caused one annoyance: __repr__ doesn't work
unless I explicitly define it, and I have insufficient getattr-fu to understand (or care) why.
I don't expect Meld2 to get much uptake in the Zope world since we have so much ZPT to maintain.
Hell, we still have DTML to maintain. One crazy idea I have is to write another API for adapting
metal macros to/from Meld2 instances. But that may not be possible for a mere mortal.
__getattr__ for attributes, leading to examples like::
>>> m = Meld2('<a meld:id="foo" href="blah">A link goes <b meld:id="name">here</b></a>')
>>> m.href = 'http://plope.com'
>>> m['name'] = 'somewhere'
The reason I did that was to avoid linguistic confusion: I wanted to represent XML attributes
as Python attributes. But this creates a need to handle the 'class' attribute specially since
it's a Python keyword. And as Richie Hindle pointed out to me, there's a strong appeal to
using the simpler syntax for the common case::
>>> meld.body.table_one.headers['class'] = 'highlight' # Python
>>> meld['body']['table_one']['headers']._class = 'highlight' # Perl 8-)
So I switched 'em around.
But I feel your pain, Casey. I plan to whip up a Meld2 Zope product and try using meld templates
with Zope to see how that goes, and I'm nervous about the __getattr__ because it's so often
painful to override that in Zope. And it's already caused one annoyance: __repr__ doesn't work
unless I explicitly define it, and I have insufficient getattr-fu to understand (or care) why.
I don't expect Meld2 to get much uptake in the Zope world since we have so much ZPT to maintain.
Hell, we still have DTML to maintain. One crazy idea I have is to write another API for adapting
metal macros to/from Meld2 instances. But that may not be possible for a mere mortal.