[wwwsearch-commits] r20054 - in wwwsearch/ClientForm/trunk: . examples

jjlee at codespeak.net jjlee at codespeak.net
Sat Nov 19 01:59:44 CET 2005


Author: jjlee
Date: Sat Nov 19 01:59:43 2005
New Revision: 20054

Added:
   wwwsearch/ClientForm/trunk/examples/simple.py
Modified:
   wwwsearch/ClientForm/trunk/README.html.in
Log:
Make first example actually run-able

Modified: wwwsearch/ClientForm/trunk/README.html.in
==============================================================================
--- wwwsearch/ClientForm/trunk/README.html.in	(original)
+++ wwwsearch/ClientForm/trunk/README.html.in	Sat Nov 19 01:59:43 2005
@@ -34,27 +34,14 @@
 href="http://www.linpro.no/lwp/">libwww-perl</a> library, but the
 interface is not the same.
 
-<p>Simple example:
+<p>Simple working example:
 
-@{colorize(r"""
-from urllib2 import urlopen
-from ClientForm import ParseResponse
-
-forms = ParseResponse(urlopen("http://www.example.com/form.html"),
-                      backwards_compat=False)
-form = forms[0]
-print form
-form["author"] = "Gisle Aas"
-
-# form.click() returns a urllib2.Request object
-# (see HTMLForm.click.__doc__ if you don't have urllib2)
-response = urlopen(form.click("Thanks"))
-""")}
+@{colorize("".join(open("examples/simple.py").readlines()[2:]))}
 
-<p>A more complicated example, which you can actually run
-(<em><strong>Note</strong>: this example makes use of the ClientForm 0.2 API;
-refer to the README.html file in the latest 0.1 release for the corresponding
-code for that version.</em>):
+<p>A more complicated working example (<em><strong>Note</strong>: this
+example makes use of the ClientForm 0.2 API; refer to the README.html
+file in the latest 0.1 release for the corresponding code for that
+version.</em>):
 
 <a name="example"></a>
 @{colorize("".join(open("examples/example.py").readlines()[2:]))}

Added: wwwsearch/ClientForm/trunk/examples/simple.py
==============================================================================
--- (empty file)
+++ wwwsearch/ClientForm/trunk/examples/simple.py	Sat Nov 19 01:59:43 2005
@@ -0,0 +1,14 @@
+#!/usr/bin/env python
+
+from urllib2 import urlopen
+from ClientForm import ParseResponse
+
+response = urlopen("http://wwwsearch.sourceforge.net/ClientForm/example.html")
+forms = ParseResponse(response, backwards_compat=False)
+form = forms[0]
+print form
+form["comments"] = "Thanks, Gisle"
+
+# form.click() returns a urllib2.Request object
+# (see HTMLForm.click.__doc__ if you don't have urllib2)
+print urlopen(form.click()).read()


More information about the wwwsearch-commits mailing list