changeset 3:c2bb8f873aee

make a useful(?) example factory
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 05 May 2010 22:05:16 -0700
parents 1182315b18ac
children 61dd789330f7
files taginthemiddle/example.py
diffstat 1 files changed, 5 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/taginthemiddle/example.py	Tue May 04 19:15:21 2010 -0700
+++ b/taginthemiddle/example.py	Wed May 05 22:05:16 2010 -0700
@@ -1,31 +1,16 @@
-import os
-
-from dispatcher import Dispatcher
+from dispatcher import Tagger
 from paste.httpexceptions import HTTPExceptionHandler
 from paste.urlparser import StaticURLParser
 from pkg_resources import resource_filename
 
-class PassthroughFileserver(object):
-    """serve files if they exist"""
-
-    def __init__(self, app, directory):
-        self.app = app
-        self.directory = directory
-        self.fileserver = StaticURLParser(self.directory)
-
-    def __call__(self, environ, start_response):
-        path = environ['PATH_INFO'].strip('/')
-        if path and os.path.exists(os.path.join(self.directory, path)):
-            return self.fileserver(environ, start_response)
-        return self.app(environ, start_response)
-
 def factory(global_conf, **app_conf):
-    """create a webob view and wrap it in middleware"""
+    """create an example view and wrap it in tagging middleware"""
 
     keystr = 'TagInTheMiddle.'
     args = dict([(key.split(keystr, 1)[-1], value)
                  for key, value in app_conf.items()
                  if key.startswith(keystr) ])
-    app = Dispatcher(**args)
-    return HTTPExceptionHandler(PassthroughFileserver(app, resource_filename(__name__, 'static')))
+    app = StaticURLParser(app_conf['directory'])
+    tagger = Tagger(app, **args)
+    return HTTPExceptionHandler(tagger)