Edgewall Software

Ticket #79 (closed enhancement: worksforme)

Opened 20 months ago

Last modified 18 months ago

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

ElementTreeStream.py (1.0 kB) - added by gavin@… 20 months ago.
Contains the ElementTreeStream? class

Change History

Changed 20 months ago by gavin@…

Contains the ElementTreeStream? class

follow-up: ↓ 2   Changed 18 months ago by cmlenz

  • milestone 0.4 deleted

Can't you just do:

et_stream = Stream(ET(tree))
et_stream.select("foo")

??

in reply to: ↑ 1   Changed 18 months 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.

  Changed 18 months ago by cmlenz

  • status changed from new to closed
  • resolution set to worksforme

For a reusable stream, you can still use:

Stream(list(ET(tree)))

So yeah, I think this can be closed as “worksforme”.

Add/Change #79 (ElementTreeStream: wrap ElementTree in a Stream)

Author



Change Properties
<Author field>
Action
as closed
Next status will be 'reopened'
 
Note: See TracTickets for help on using tickets.