<s> """<STR_LIT>""" <EOL> from os import path , listdir <EOL> from coolmagic . utils import Request , local_manager , redirect <EOL> from werkzeug . routing import Map , Rule , RequestRedirect <EOL> from werkzeug . exceptions import HTTPException , NotFound <EOL> class CoolMagicApplication ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , config ) : <EOL> self . config = config <EOL> for fn in listdir ( path . join ( path . dirname ( __file__ ) , '<STR_LIT>' ) ) : <EOL> if fn . endswith ( '<STR_LIT>' ) and fn != '<STR_LIT>' : <EOL> __import__ ( '<STR_LIT>' + fn [ : - <NUM_LIT:3> ] ) <EOL> from coolmagic . utils import exported_views <EOL> rules = [ <EOL> Rule ( '<STR_LIT>' , <EOL> endpoint = '<STR_LIT>' ) <EOL> ] <EOL> self . views = { } <EOL> for endpoint , ( func , rule , extra ) in exported_views . iteritems ( ) : <EOL> if rule is not None : <EOL> rules . append ( Rule ( rule , endpoint = endpoint , ** extra ) ) <EOL> self . views [ endpoint ] = func <EOL> self . url_map = Map ( rules ) <EOL> def __call__ ( self , environ , start_response ) : <EOL> urls = self . url_map . bind_to_environ ( environ ) <EOL> req = Request ( environ , urls ) <EOL> try : <EOL> endpoint , args = urls . match ( req . path ) <EOL> resp = self . views [ endpoint ] ( ** args ) <EOL> except NotFound , e : <EOL> resp = self . views [ '<STR_LIT>' ] ( ) <EOL> except ( HTTPException , RequestRedirect ) , e : <EOL> resp = e <EOL> return resp ( environ , start_response ) <EOL> def make_app ( config = None ) : <EOL> """<STR_LIT>""" <EOL> config = config or { } <EOL> app = CoolMagicApplication ( config ) <EOL> from werkzeug . utils import SharedDataMiddleware <EOL> app = SharedDataMiddleware ( app , { <EOL> '<STR_LIT>' : path . join ( path . dirname ( __file__ ) , '<STR_LIT>' ) <EOL> } ) <EOL> app = local_manager . make_middleware ( app ) <EOL> return app </s>
