annotate theslasher/__init__.py @ 0:3812c1493dde default tip

add the slasher...be afraid, be very afraid
author k0s <k0scist@gmail.com>
date Mon, 11 Jan 2010 17:50:36 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
1 """
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
2 request dispatcher
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
3 """
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
4
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
5 from webob import Request, exc
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
6
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
7 class TheSlasher(object):
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
8
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
9 ### class level variables
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
10 def __init__(self, app):
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
11 self.app = app
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
12
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
13 ### methods dealing with HTTP
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
14 def __call__(self, environ, start_response):
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
15
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
16 request = Request(environ)
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
17
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
18 if request.path_info.endswith('/') and (request.path_info != '/'):
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
19 location = request.path_info.rstrip('/')
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
20 return exc.HTTPMovedPermanently(location=location)(environ, start_response)
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
21
3812c1493dde add the slasher...be afraid, be very afraid
k0s <k0scist@gmail.com>
parents:
diff changeset
22 return self.app(environ, start_response)