# HG changeset patch # User k0s # Date 1263250236 18000 # Node ID 3812c1493dde2f941178036b465047ac1b518785 add the slasher...be afraid, be very afraid diff -r 000000000000 -r 3812c1493dde setup.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/setup.py Mon Jan 11 17:50:36 2010 -0500 @@ -0,0 +1,31 @@ +from setuptools import setup, find_packages +import sys, os + +version = "0.0" + +setup(name='theslasher', + version=version, + description="removes trailing slashes", + long_description=""" +""", + classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers + author='Jeff Hammel', + author_email='k0scist@gmail.com', + url='http://k0s.org', + license="", + packages=find_packages(exclude=['ez_setup', 'examples', 'tests']), + include_package_data=True, + zip_safe=False, + install_requires=[ + # -*- Extra requirements: -*- + 'WebOb', + 'Paste', + 'PasteScript', + ], + entry_points=""" + # -*- Entry points: -*- + [paste.app_factory] + main = theslasher.factory:factory + """, + ) + diff -r 000000000000 -r 3812c1493dde theslasher.ini --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/theslasher.ini Mon Jan 11 17:50:36 2010 -0500 @@ -0,0 +1,21 @@ +#!/usr/bin/env paster + +[DEFAULT] +debug = true +email_to = k0scist@gmail.com +smtp_server = localhost +error_email_from = paste@localhost + +[server:main] +use = egg:Paste#http +host = 0.0.0.0 +port = 7777 + +[composite:main] +use = egg:Paste#urlmap +/ = theslasher + +set debug = false + +[app:theslasher] +paste.app_factory = theslasher.factory:factory diff -r 000000000000 -r 3812c1493dde theslasher/__init__.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/theslasher/__init__.py Mon Jan 11 17:50:36 2010 -0500 @@ -0,0 +1,22 @@ +""" +request dispatcher +""" + +from webob import Request, exc + +class TheSlasher(object): + + ### class level variables + def __init__(self, app): + self.app = app + + ### methods dealing with HTTP + def __call__(self, environ, start_response): + + request = Request(environ) + + if request.path_info.endswith('/') and (request.path_info != '/'): + location = request.path_info.rstrip('/') + return exc.HTTPMovedPermanently(location=location)(environ, start_response) + + return self.app(environ, start_response) diff -r 000000000000 -r 3812c1493dde theslasher/factory.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/theslasher/factory.py Mon Jan 11 17:50:36 2010 -0500 @@ -0,0 +1,11 @@ +from paste.httpexceptions import HTTPExceptionHandler +from theslasher import TheSlasher +from webob import Response + +def example(environ, start_response): + return Response(content_type='text/plain', body=environ['PATH_INFO'])(environ, start_response) + +def factory(global_conf, **app_conf): + """create a webob view and wrap it in middleware""" + return TheSlasher(example) +