Skip to content

Instantly share code, notes, and snippets.

@dsedivec
Created September 10, 2010 18:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dsedivec/574160 to your computer and use it in GitHub Desktop.
Save dsedivec/574160 to your computer and use it in GitHub Desktop.
In one window:
$ python2.6 /tmp/wsgiexample.py
In another:
$ curl http://localhost:9977
POST some text to me.
$ curl -d 'This is xxx a test.' http://localhost:9977
I found 3 X(es).
from wsgiref.simple_server import make_server
def count_letter_x(environ, start_response):
start_response("200 OK", [("Content-Type", "text/plain")])
if environ["REQUEST_METHOD"] == "POST":
length = environ["CONTENT_LENGTH"]
request_body = environ["wsgi.input"].read(int(length))
num_x_letters = request_body.count("x")
return ["I found %d X(es).\n" % (num_x_letters,)]
else:
return ["POST some text to me.\n"]
server = make_server("", 9977, count_letter_x)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment