1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
############################################################
# Apps
############################################################
def simple_app(response, environ, start_response):
start_response('200 OK', [('Content-type', 'text/html')])
return ['This is ', response]
def basic_app(environ, start_response):
return simple_app('basic app', environ, start_response)
def make_basic_app(global_conf, **conf):
return basic_app
############################################################
# Filters
############################################################
def make_cap_filter(global_conf, method_to_call='upper'):
def cap_filter(app):
return CapFilter(app, global_conf, method_to_call)
return cap_filter
class CapFilter(object):
def __init__(self, app, global_conf, method_to_call='upper'):
self.app = app
self.method_to_call = method_to_call
self.global_conf = global_conf
def __call__(self, environ, start_response):
app_iter = self.app(environ, start_response)
for item in app_iter:
yield getattr(item, self.method_to_call)()
if hasattr(app_iter, 'close'):
app_iter.close()
############################################################
# Servers
############################################################
def make_fake_server(global_conf=None, **settings):
return Server(global_conf, settings)
class Server(object):
def __init__(self, global_conf, settings):
self.global_conf = global_conf
self.settings = settings
def __call__(self, app):
return app
|