[XML-SIG] Child nodes and lazy evaluation (Generators)

Ken kens@sightreader.com
Wed, 22 Nov 2000 15:46:58 -0600


This is a multi-part message in MIME format.

------=_NextPart_000_001C_01C0549B.72947590
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I've written a Generator class which puts lazy evaluation functionality =
into a sequence object.  Seems to me that this would be a good thing use =
as an iterator for streaming XML/DOM child nodes.  I don't have time =
right now to integrate it myself, but it would be a fairly easy task.

The result would be to hide the details of event driven streaming =
protocol within a pythonic interface that syntactically behaves like a =
fully loaded tree (thus solving the old "tree vs. events" dillemma).

An example of how I have used generators is a readlines method of a =
simulated file object that returns a generator rather than a list.  I =
was able to connect a stream 'f' to a serial port or socket (which might =
not have an EOF anytime soon) and then:

for line in f.readlines():
    do_something(line)

... which does -not- block on reading the end-of-file as you would =
normally expect.

If you decide to take up this project please let me know.

http://starship.python.net/crew/seehof/Generator.html

- Ken mailto://kens@sightreader.com



------=_NextPart_000_001C_01C0549B.72947590
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT color=3D#000000 size=3D2>I've written a Generator class which =
puts lazy=20
evaluation functionality into a sequence object.&nbsp; Seems to me that =
this=20
would be a good thing use as an iterator for streaming XML/DOM child=20
nodes.&nbsp; I don't have time right now to integrate it myself, but it =
would be=20
a fairly easy task.</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>The result would be to hide the =
details of event=20
driven streaming protocol within a pythonic interface that syntactically =
behaves=20
like a fully loaded tree (thus solving the old &quot;tree vs. =
events&quot;=20
dillemma).</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>An example of how I have used =
generators is a=20
readlines method of a simulated file object that returns a generator =
rather than=20
a list.&nbsp; I was able to connect a stream 'f' to a serial port or =
socket=20
(which might not have an EOF anytime soon) and then:</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>for line in =
f.readlines():</FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT><FONT =
size=3D2>&nbsp;&nbsp;&nbsp;=20
do_something(line)</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>... which does -not- block on reading the =
end-of-file as you=20
would normally expect.</FONT></DIV>
<DIV><FONT size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT size=3D2>If you decide to take up this project please let me=20
know.</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2><A=20
href=3D"http://starship.python.net/crew/seehof/Generator.html">http://sta=
rship.python.net/crew/seehof/Generator.html</A></FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2>- Ken <A=20
href=3D"mailto://kens@sightreader.com">mailto://kens@sightreader.com</A><=
/FONT></DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT color=3D#000000 size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_001C_01C0549B.72947590--