<s> from foam . core . log import KeyAdapter <EOL> def route ( path , methods ) : <EOL> def decorator ( target ) : <EOL> target . route = ( ( path , methods ) ) <EOL> return target <EOL> return decorator <EOL> class Dispatcher ( object ) : <EOL> def __init__ ( self , key , logger , app ) : <EOL> self . _log = KeyAdapter ( key , logger ) <EOL> self . _app = app <EOL> for k in dir ( self ) : <EOL> try : <EOL> val = getattr ( self , k ) <EOL> ( path , methods ) = val . route <EOL> except TypeError : <EOL> continue <EOL> except AttributeError : <EOL> continue <EOL> try : <EOL> app . add_url_rule ( path , path . replace ( "<STR_LIT:/>" , "<STR_LIT:_>" ) , val , methods = methods ) <EOL> self . _log . debug ( "<STR_LIT>" % ( path , k ) ) <EOL> except Exception , e : <EOL> self . _log . exception ( "<STR_LIT>" ) <EOL> continue </s>
