changeset 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
files setup.py theslasher.ini theslasher/__init__.py theslasher/factory.py
diffstat 4 files changed, 85 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /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
+      """,
+      )
+      
--- /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
--- /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)
--- /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)
+