Opened 18 years ago
Closed 18 years ago
#79 closed enhancement (worksforme)
ElementTreeStream: wrap ElementTree in a Stream
Reported by: | gavin@… | Owned by: | cmlenz |
---|---|---|---|
Priority: | major | Milestone: | |
Component: | Template engine plugin | Version: | 0.3.3 |
Keywords: | Cc: |
Description
The attached class wraps an ElementTree element to create a genshi.core.Stream. It is probably a drop-in replacement for the current ET function.
This means you can select(...) the stream. Some paths possible with Genshi do not have equivalents in ElementTree, AFAIK, partly because text nodes are just attributes of elements in ET.
As a convenience. the class also unwraps lists passed in, specifically to handle the result of element.findall(...).
Attachments (1)
Change History (4)
Changed 18 years ago by gavin@…
comment:1 follow-up: ↓ 2 Changed 18 years ago by cmlenz
- Milestone 0.4 deleted
Can't you just do:
et_stream = Stream(ET(tree)) et_stream.select("foo")
??
comment:2 in reply to: ↑ 1 Changed 18 years ago by anonymous
Replying to cmlenz:
Can't you just do: <snip>
Ah, yes you can. I didn't see that before (time pressure, excuses, etc) :-)
The major differences are that the class based solution allows you to reuse the Stream (but that's only because ET returns a generator), and that it attempts to unwrap lists, which was useful to me.
I prefer the class solution still, but then I wrote it. The original problem can be solved without it, so it's just a convenience now. Close the ticket if it's of no interest.
comment:3 Changed 18 years ago by cmlenz
- Resolution set to worksforme
- Status changed from new to closed
For a reusable stream, you can still use:
Stream(list(ET(tree)))
So yeah, I think this can be closed as “worksforme”.
Contains the ElementTreeStream? class