Skip to content

Commit

Permalink
Included a form POST example in examples.005_http
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik Allik committed Aug 28, 2013
1 parent c24fcec commit 455e7ae
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions spinoff/examples/005_http.py
@@ -1,3 +1,5 @@
import random

from gevent import sleep

from spinoff.actor import Actor
Expand All @@ -10,6 +12,7 @@ def run(self):
(r'^/$', IndexResponder),
(r'^/foo/(?P<name>.+)$', FooResponder),
(r'^/add/(?P<a>[0-9]+)/(?P<b>[0-9]+)$', AdderResponder),
(r'^/form$', FormSubmitResponder),
]))
http_srv.join()

Expand All @@ -36,3 +39,14 @@ class AdderResponder(Actor):
def run(self, request, a, b):
a, b = int(a), int(b)
request.write('%d + %d = %d\n' % (a, b, self.spawn(Adder).ask((a, b)),))


class FormSubmitResponder(Actor):
def run(self, request):
stuff = request.form.getlist('stuff')
for item in stuff:
if random.random() < 0.25:
request.set_status('400 Bad Request')
request.writeln("I feel like I don't like the value %r")
return
request.writeln("got:\n%s" % ("\n".join(str(x) for x in stuff),))

0 comments on commit 455e7ae

Please sign in to comment.