dbr / pyerweb
- Source
- Commits
- Network (1)
- Issues (0)
- Downloads (0)
- Wiki (1)
- Graphs
-
Branch:
master
pyerweb /
| name | age | message | |
|---|---|---|---|
| |
.gitignore | Mon Nov 10 05:07:15 -0800 2008 | |
| |
README.markdown | Sun Apr 26 10:06:46 -0700 2009 | |
| |
example.py | Sun Apr 26 10:23:05 -0700 2009 | |
| |
html.py | Sun Apr 26 10:42:26 -0700 2009 | |
| |
pyerweb.py | Sun Apr 26 10:42:47 -0700 2009 |
README.markdown
pyerweb: an absurdly small Python web-framework
Currently pyerweb is basically a simple routing system, which allows you to do the following:
from pyerweb import GET, runner
@GET("^/view/(.+?)")
def view(key):
return "Viewing %s" % (key)
This maps /view/anything to calling view() with an argument of "anything"
You simply decorate a function with @GET, @PUT @POST or @DELETE, the argument is a regular expression (in a string), for example:
@POST("^/0-9+$")
..will match a POST request to /1 or /44532
Groups in the regular expression will be passed to the decorated function as arguments, for example:
@POST("^/(0-9)+$")
def view(the_number):
pass
..will grab the supplied number as the_number argument
The runner function is the WSGI compatible runner. For example, using "spawning" you can simply run:
spawn myscript.runner
Or, to use pyerweb as a CGI script (also works for the Google App Engine):
import wsgiref.handlers
from pyerweb import GET, runner
@GET("^/view/(.+?)")
def view(key):
return "Viewing %s" % (key)
if __name__ == "__main__":
wsgiref.handlers.CGIHandler().run(runner)
