summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authoramk <amk@localhost>2005-04-22 18:34:13 +0000
committeramk <amk@localhost>2005-04-22 18:34:13 +0000
commitade7c3a3aae4fc74d3295da0dfc964d4123696ee (patch)
tree6bef019533d608f6d6c0113a7db04dc9e22dd49e /examples
parentee6237ea49bb923d5d7af3e07edc13e88ef5c705 (diff)
downloadpaste-git-ade7c3a3aae4fc74d3295da0dfc964d4123696ee.tar.gz
Change application to run an iterable
Diffstat (limited to 'examples')
-rw-r--r--examples/helloworld/index.py39
1 files changed, 21 insertions, 18 deletions
diff --git a/examples/helloworld/index.py b/examples/helloworld/index.py
index b79132f..4fe0742 100644
--- a/examples/helloworld/index.py
+++ b/examples/helloworld/index.py
@@ -7,22 +7,25 @@ Automated greeting application.
import cgi
def application(environ, start_response):
- form = cgi.FieldStorage(fp=environ['wsgi.input'],
- environ=environ,
- keep_blank_values=1)
- start_response('200 OK', [('Content-type', 'text/html')])
+ def body():
+ form = cgi.FieldStorage(fp=environ['wsgi.input'],
+ environ=environ,
+ keep_blank_values=1)
+
+ if form.getvalue('name'):
+ yield ('<html><head><title>Hello!</title></head>\n')
+ yield ('<body>\n')
+ yield ('<h1>Hello %s!</h1>\n' % form['name'].value)
+ else:
+ yield ('<html><head><title>Who is there?</title></head>\n')
+ yield ('<body>\n')
+ yield ('<h1>Who is there?</h1>\n')
+ yield ('<form action="%s" method="POST">\n' % environ['SCRIPT_NAME'])
+ yield ('What is your name?<br>\n')
+ yield ('<input type="text" name="name" value="%s"><br>\n'
+ % cgi.escape(form.getvalue('name', ''), 1))
+ yield ('<input type="submit" value="That is my name"></form>\n')
+ yield ('</body></html>\n')
- if form.getvalue('name'):
- yield ('<html><head><title>Hello!</title></head>\n')
- yield ('<body>\n')
- yield ('<h1>Hello %s!</h1>\n' % form['name'].value)
- else:
- yield ('<html><head><title>Who is there?</title></head>\n')
- yield ('<body>\n')
- yield ('<h1>Who is there?</h1>\n')
- yield ('<form action="%s" method="POST">\n' % environ['SCRIPT_NAME'])
- yield ('What is your name?<br>\n')
- yield ('<input type="text" name="name" value="%s"><br>\n'
- % cgi.escape(form.getvalue('name', ''), 1))
- yield ('<input type="submit" value="That is my name"></form>\n')
- yield ('</body></html>\n')
+ start_response('200 OK', [('Content-type', 'text/html')])
+ return body()