[lxml-dev] CSS and lxml
Frederik Elwert
felwert at uni-bremen.de
Mon Sep 17 17:00:21 CEST 2007
Am Montag, den 17.09.2007, 16:37 +0200 schrieb Stefan Behnel:
> If you don't want to alter the tree, you can use a dict to map Elements to a
> style dict. However, note that Elements are not currently weak referenceable,
> so you'd have to make sure the trees are discarded after use.
Erm, I must confess, I'm not sure what this means, practically speaking.
Is it enough to "del" the dict after use?
Aside from that, this sounds quite good.
> >> You could maybe implement a "cssannotate(stylesheet, tree)" function, which
> >> would map a stylesheet on a tree by setting (or extending) the "style"
> >> attributes on each element accordingly. That would come pretty close to what
> >> you were looking for.
> >
> > This just had the negative side-effect of changing the tree itself. So
> > it would only be applicable for read-only-operations, since one wouldn't
> > want to put all style permanently into style attributes for most use
> > cases.
>
> Agreed. However, you can't store anything in Elements that is not reflected by
> the underlying tree, as Element objects (which are actually just proxies) can
> be garbage collected while the tree stays alive.
Yes, sure. So a style dict would have to be a totally separated object,
I guess? I think I can live with that.
> You can also store style information in the tree under a separate namespace.
Hm, true. I have to think about that, since it would introduce some
redundancy, but it might be the easiest way to go.
> I don't think cssselect.py uses any 2.0 specific features. Copying it over to
> 1.3 (or into your own code base) should work as a temporary solution.
Ah, that's good, I'll give it a try!
Thanks,
Frederik
More information about the lxml-dev
mailing list