Edgewall Software

Opened 17 years ago

Closed 17 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)

ElementTreeStream.py (1.0 KB) - added by gavin@… 17 years ago.
Contains the ElementTreeStream? class

Download all attachments as: .zip

Change History (4)

Changed 17 years ago by gavin@…

Contains the ElementTreeStream? class

comment:1 follow-up: Changed 17 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 17 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 17 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”.

Note: See TracTickets for help on using tickets.