1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/Common/Form/__init__.py Thu Mar 11 16:21:31 2004 +0000
1.3 @@ -0,0 +1,62 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"A form submission test."
1.7 +
1.8 +import WebStack.Generic
1.9 +
1.10 +class FormResource:
1.11 +
1.12 + """
1.13 + A resource which handles incoming form submissions.
1.14 + """
1.15 +
1.16 + def respond(self, trans):
1.17 +
1.18 + """
1.19 + Examine the incoming request, decoding the form information.
1.20 + """
1.21 +
1.22 + # NOTE: Some frameworks do not pass in the content type.
1.23 +
1.24 + content_type = trans.get_content_type()
1.25 + input = trans.get_request_stream()
1.26 + received_data = input.read()
1.27 +
1.28 + # NOTE: Send the appropriate kind of response.
1.29 +
1.30 + trans.set_content_type(WebStack.Generic.ContentType("text/html"))
1.31 + out = trans.get_response_stream()
1.32 + out.write("""
1.33 +<html>
1.34 + <head>
1.35 + <title>Form Test</title>
1.36 + </head>
1.37 + <body>
1.38 + <h1>Form Test</h1>
1.39 + <h2>Normal</h2>
1.40 + <form method="post" action="">
1.41 + <input name="x" type="text" value="1"/><br/>
1.42 + <input name="x" type="text" value="2"/><br/>
1.43 + <input name="y" type="text" value="3"/><br/>
1.44 + <input name="f" type="file"/><br/>
1.45 + <input name="send" type="submit" value="Send!"/>
1.46 + </form>
1.47 + <h2>Multipart</h2>
1.48 + <form method="post" action="" enctype="multipart/form-data">
1.49 + <input name="x" type="text" value="1"/><br/>
1.50 + <input name="x" type="text" value="2"/><br/>
1.51 + <input name="y" type="text" value="3"/><br/>
1.52 + <input name="f" type="file"/><br/>
1.53 + <input name="send" type="submit" value="Send!"/>
1.54 + </form>
1.55 + <h2>Content Type</h2>
1.56 + <p>%s</p>
1.57 + <h2>Received Data</h2>
1.58 + <p>Start</p>
1.59 + <pre>%s</pre>
1.60 + <p>Stop</p>
1.61 + </body>
1.62 +</html>
1.63 +""" % (content_type.content_type, received_data.replace("<", "<").replace(">", ">").replace("&", "&")))
1.64 +
1.65 +# vim: tabstop=4 expandtab shiftwidth=4