1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/examples/BaseHTTPRequestHandler/FormApp.py Thu Mar 11 16:21:31 2004 +0000
1.3 @@ -0,0 +1,14 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +from WebStack.Adapters import BaseHTTPRequestHandler
1.7 +from Form import FormResource
1.8 +import BaseHTTPServer
1.9 +
1.10 +# Special magic incantation.
1.11 +
1.12 +handler = BaseHTTPRequestHandler.HandlerFactory(FormResource())
1.13 +address = ("", 8080)
1.14 +server = BaseHTTPServer.HTTPServer(address, handler)
1.15 +server.serve_forever()
1.16 +
1.17 +# vim: tabstop=4 expandtab shiftwidth=4
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/examples/Common/Form/__init__.py Thu Mar 11 16:21:31 2004 +0000
2.3 @@ -0,0 +1,62 @@
2.4 +#!/usr/bin/env python
2.5 +
2.6 +"A form submission test."
2.7 +
2.8 +import WebStack.Generic
2.9 +
2.10 +class FormResource:
2.11 +
2.12 + """
2.13 + A resource which handles incoming form submissions.
2.14 + """
2.15 +
2.16 + def respond(self, trans):
2.17 +
2.18 + """
2.19 + Examine the incoming request, decoding the form information.
2.20 + """
2.21 +
2.22 + # NOTE: Some frameworks do not pass in the content type.
2.23 +
2.24 + content_type = trans.get_content_type()
2.25 + input = trans.get_request_stream()
2.26 + received_data = input.read()
2.27 +
2.28 + # NOTE: Send the appropriate kind of response.
2.29 +
2.30 + trans.set_content_type(WebStack.Generic.ContentType("text/html"))
2.31 + out = trans.get_response_stream()
2.32 + out.write("""
2.33 +<html>
2.34 + <head>
2.35 + <title>Form Test</title>
2.36 + </head>
2.37 + <body>
2.38 + <h1>Form Test</h1>
2.39 + <h2>Normal</h2>
2.40 + <form method="post" action="">
2.41 + <input name="x" type="text" value="1"/><br/>
2.42 + <input name="x" type="text" value="2"/><br/>
2.43 + <input name="y" type="text" value="3"/><br/>
2.44 + <input name="f" type="file"/><br/>
2.45 + <input name="send" type="submit" value="Send!"/>
2.46 + </form>
2.47 + <h2>Multipart</h2>
2.48 + <form method="post" action="" enctype="multipart/form-data">
2.49 + <input name="x" type="text" value="1"/><br/>
2.50 + <input name="x" type="text" value="2"/><br/>
2.51 + <input name="y" type="text" value="3"/><br/>
2.52 + <input name="f" type="file"/><br/>
2.53 + <input name="send" type="submit" value="Send!"/>
2.54 + </form>
2.55 + <h2>Content Type</h2>
2.56 + <p>%s</p>
2.57 + <h2>Received Data</h2>
2.58 + <p>Start</p>
2.59 + <pre>%s</pre>
2.60 + <p>Stop</p>
2.61 + </body>
2.62 +</html>
2.63 +""" % (content_type.content_type, received_data.replace("<", "<").replace(">", ">").replace("&", "&")))
2.64 +
2.65 +# vim: tabstop=4 expandtab shiftwidth=4