<s> """<STR_LIT>""" <EOL> from webob . exc import HTTPNotFound <EOL> from reg import mapply <EOL> from . app import App <EOL> from . import generic <EOL> DEFAULT_NAME = u'<STR_LIT>' <EOL> def publish ( request ) : <EOL> """<STR_LIT>""" <EOL> obj = resolve_model ( request ) <EOL> return resolve_response ( obj , request ) <EOL> def resolve_model ( request ) : <EOL> """<STR_LIT>""" <EOL> app = request . app <EOL> app . set_implicit ( ) <EOL> while request . unconsumed : <EOL> next = consume ( app , request ) <EOL> if next is None : <EOL> break <EOL> if not isinstance ( next , App ) : <EOL> return next <EOL> next . set_implicit ( ) <EOL> next . parent = app <EOL> request . app = next <EOL> request . lookup = next . lookup <EOL> app = next <EOL> if not request . unconsumed : <EOL> return consume ( app , request ) <EOL> return None <EOL> def consume ( app , request ) : <EOL> """<STR_LIT>""" <EOL> value , stack , traject_variables = app . config . path_registry . consume ( <EOL> request . unconsumed ) <EOL> if value is None : <EOL> return None <EOL> get_obj , get_parameters = value <EOL> variables = get_parameters ( request . GET ) <EOL> variables [ '<STR_LIT>' ] = request <EOL> variables [ '<STR_LIT>' ] = app <EOL> variables . update ( traject_variables ) <EOL> next_obj = mapply ( get_obj , ** variables ) <EOL> if next_obj is None : <EOL> return None <EOL> request . unconsumed = stack <EOL> return next_obj <EOL> def resolve_response ( obj , request ) : <EOL> """<STR_LIT>""" <EOL> view_name = request . view_name = get_view_name ( request . unconsumed ) <EOL> if view_name is None : <EOL> raise HTTPNotFound ( ) <EOL> return generic . view ( obj , request , lookup = request . lookup ) <EOL> def get_view_name ( stack ) : <EOL> """<STR_LIT>""" <EOL> unconsumed_amount = len ( stack ) <EOL> if unconsumed_amount == <NUM_LIT:0> : <EOL> return DEFAULT_NAME <EOL> elif unconsumed_amount == <NUM_LIT:1> : <EOL> return stack [ <NUM_LIT:0> ] . lstrip ( '<STR_LIT:+>' ) <EOL> else : <EOL> return None </s>
