#NEWLINE# def dispatcher( handlers ) : #NEWLINE# #INDENT# 'Accepts handlers and returns a WSGI app that dispatches requests to\n    them.\n\n    Args:\n        handlers: a list of handlers as produced by\n            wsgi_utils.load_user_scripts_into_handlers: a list of tuples of\n            (url_re, app).\n\n    Returns:\n        A WSGI app that dispatches to the user apps specified in the input.\n    ' #NEWLINE# @ wrappers . Request . application #NEWLINE# def dispatch( request ) : #NEWLINE# #INDENT# 'Handle one request.' #NEWLINE# for ( url_re , app ) in handlers : #NEWLINE# #INDENT# matcher = re . match ( url_re , request . path ) #NEWLINE# if ( matcher and ( matcher . end ( ) == len ( request . path ) ) ) : #NEWLINE# #INDENT# if ( app is not None ) : #NEWLINE# #INDENT# return app #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return response_for_error ( httplib . INTERNAL_SERVER_ERROR ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# logging . error ( 'No handler found for %s' , request . path ) #NEWLINE# return response_for_error ( httplib . NOT_FOUND ) #NEWLINE# #UNINDENT# return handlers