annotate discusssions/factory.py @ 3:f09ba04b2e29 default tip

adding notes about -> collaborative documents
author Jeff Hammel <k0scist@gmail.com>
date Fri, 26 Mar 2010 14:03:44 -0700
parents c904249afb04
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
1 import os
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
2
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
3 from dispatcher import Dispatcher
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
4 from paste.httpexceptions import HTTPExceptionHandler
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
5 from paste.urlparser import StaticURLParser
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
6 from pkg_resources import resource_filename
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
7
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
8 class PassthroughFileserver(object):
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
9 """serve files if they exist"""
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
10
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
11 def __init__(self, app, directory):
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
12 self.app = app
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
13 self.directory = directory
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
14 self.fileserver = StaticURLParser(self.directory)
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
15
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
16 def __call__(self, environ, start_response):
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
17 path = environ['PATH_INFO'].strip('/')
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
18 if path and os.path.exists(os.path.join(self.directory, path)):
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
19 return self.fileserver(environ, start_response)
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
20 return self.app(environ, start_response)
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
21
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
22 def factory(global_conf, **app_conf):
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
23 """create a webob view and wrap it in middleware"""
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
24
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
25 keystr = 'discusssions.'
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
26 args = dict([(key.split(keystr, 1)[-1], value)
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
27 for key, value in app_conf.items()
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
28 if key.startswith(keystr) ])
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
29 app = Dispatcher(**args)
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
30 return HTTPExceptionHandler(PassthroughFileserver(app, resource_filename(__name__, 'static')))
c904249afb04 initial commit of discussions
k0s <k0scist@gmail.com>
parents:
diff changeset
31