changeset 3:bb2d34fb5de4

allow to be used as middleware
author k0s <k0scist@gmail.com>
date Sun, 27 Dec 2009 16:27:34 -0500
parents 0b5fce452087
children e5efa999911a
files setup.py uploader/dispatcher.py
diffstat 2 files changed, 5 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/setup.py
+++ b/setup.py
@@ -1,12 +1,12 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = "0.2"
+version = "0.2.1"
 
 setup(name='uploader',
       version=version,
       description="a file uploader app",
       long_description="""
 """,
       classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
       author='Ethan Jucovy',
--- a/uploader/dispatcher.py
+++ b/uploader/dispatcher.py
@@ -7,17 +7,18 @@ from handlers import Get, Post, SubpathG
 from webob import Request, exc
 
 class Dispatcher(object):
 
     ### class level variables
     defaults = { 'directory': None,
                  'auth': 'False',
                  'query_string': None,
-                 'subpath': 'False' }
+                 'subpath': 'False',
+                 'app': None}
 
     def __init__(self, **kw):
         for key in self.defaults:
             setattr(self, key, kw.get(key, self.defaults[key]))
         assert os.path.exists(self.directory)
         self.auth = self.auth.lower() == 'true'
         self.subpath = self.subpath.lower() == 'true'
         if self.subpath:
@@ -33,11 +34,13 @@ class Dispatcher(object):
         request = Request(environ)
         if self.auth and not request.remote_user:
             return exc.HTTPUnauthorized()(environ, start_response)
         for h in self.handlers:
             if h.match(self, request):
                 handler = h(self, request)
                 break
         else:
+            if self.app:
+                return self.app(environ, start_response)
             handler = exc.HTTPNotFound
         res = handler()
         return res(environ, start_response)