I've been a-googling for examples or information on recieving and parsing html streams in a cgi script. I need to send a request like:

''http://www.foo.com/cgi-bin/responder.cgi?foo=hi&bar=there&bat=buddy&identifier=myname"

to a remote server which will then stream a response to my script, similar to what I have grown to expect from cgi.FieldStorage when processing user input.

I was hoping for something magical like:

gulp = cgi.StreamIO("http://www.foo.com/cgi-bin/responder.cgi?foo=hi&bar=there&bat=buddy").read()

... but for some reason not one of the python creators foresaw that I might one day need them to do all the thinking, typing and other hard parts for me! </rimshot>


So I decided to play around for a while and see what I could happen on my own. I first went to the interpreter:

>>> dir(cgi)
['FieldStorage', 'FormContent', 'FormContentDict', 'InterpFormContentDict', 'MiniFieldStorage', 'StringIO', 'SvFormContentDict', 'UserDict', '__all__', '__builtins__', '__doc__', '__file__', '__name__', '__version__', 'dolog', 'escape', 'initlog', 'log', 'logfile', 'logfp', 'maxlen', 'mimetools', 'nolog', 'os', 'parse', 'parse_header', 'parse_multipart', 'parse_qs', 'parse_qsl', 'print_arguments', 'print_directory', 'print_environ', 'print_environ_usage', 'print_exception', 'print_form', 'rfc822', 'sys', 'test', 'urllib', 'valid_boundary']


Oho! StringIO seems like it is my baby:

 dir(cgi.StringIO)
['__doc__', '__init__', '__iter__', '__module__', 'close', 'flush', 'getvalue', 'isatty', 'next', 'read', 'readline', 'readlines', 'seek', 'tell', 'truncate', 'write', 'writelines']

Right on! GetValue! Read and Write! That looks like the ticket and it appears to work the same way as the usual StringIO module. Now my connundrum: I can't find any examples.

I'm guessing what needs to happen is this:

meScript --> sends request with an identifier to the remote server.

RemoteServer --> sends data back to my meOtherScript (or a routine in meScript) which either pickles the data or stores it in a handy database.

while
   my the first instance of meScript which has now passed the identifier to itself loops around reading from the database until either the identifier (and other data) to show up or the script times out, generating a heartfelt apology.

Am I on the right track here? I suspect there is some sort of super easy way to accomplish this, but I am probably missing it.

Thanks!






_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to